Skip to content

Commit ac3c6a4

Browse files
docs
1 parent 60f84dd commit ac3c6a4

File tree

7 files changed

+88
-45
lines changed

7 files changed

+88
-45
lines changed

apps/framework-cli/src/framework/core/infrastructure_map.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,8 +1749,10 @@ impl InfrastructureMap {
17491749
// Detect engine change (e.g., MergeTree -> ReplacingMergeTree)
17501750
let engine_changed = table.engine != target_table.engine;
17511751

1752-
// Detect cluster name change
1753-
let cluster_changed = table.cluster_name != target_table.cluster_name;
1752+
// Note: We intentionally do NOT check for cluster_name changes here.
1753+
// cluster_name is a deployment directive (how to run DDL), not a schema property.
1754+
// The inframap will be updated with the new cluster_name value, and future DDL
1755+
// operations will use it, but changing cluster_name doesn't trigger operations.
17541756

17551757
let order_by_change = if order_by_changed {
17561758
OrderByChange {
@@ -1792,11 +1794,11 @@ impl InfrastructureMap {
17921794
// since ClickHouse requires the full column definition when modifying TTL
17931795

17941796
// Only process changes if there are actual differences to report
1797+
// Note: cluster_name changes are intentionally excluded - they don't trigger operations
17951798
if !column_changes.is_empty()
17961799
|| order_by_changed
17971800
|| engine_changed
17981801
|| indexes_changed
1799-
|| cluster_changed
18001802
{
18011803
// Use the strategy to determine the appropriate changes
18021804
let strategy_changes = strategy.diff_table_update(

apps/framework-cli/src/infrastructure/olap/clickhouse.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,10 @@ impl OlapOperations for ConfiguredDBClient {
18991899
indexes,
19001900
database: Some(database),
19011901
table_ttl_setting,
1902-
cluster_name: None, // Cluster info not extracted from introspection
1902+
// cluster_name is always None from introspection because ClickHouse doesn't store
1903+
// the ON CLUSTER clause - it's only used during DDL execution and isn't persisted
1904+
// in system tables. Users must manually specify cluster in their table configs.
1905+
cluster_name: None,
19031906
};
19041907
debug!("Created table object: {:?}", table);
19051908

apps/framework-cli/src/infrastructure/olap/clickhouse/diff_strategy.rs

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,11 @@ impl TableDiffStrategy for ClickHouseTableDiffStrategy {
304304
})];
305305
}
306306

307-
// Check if cluster has changed
308-
if before.cluster_name != after.cluster_name {
309-
log::warn!(
310-
"ClickHouse: cluster changed for table '{}' (from {:?} to {:?}), requiring drop+create",
311-
before.name, before.cluster_name, after.cluster_name
312-
);
313-
return vec![
314-
OlapChange::Table(TableChange::Removed(before.clone())),
315-
OlapChange::Table(TableChange::Added(after.clone())),
316-
];
317-
}
307+
// Note: cluster_name changes are intentionally NOT treated as requiring drop+create.
308+
// cluster_name is a deployment directive (how to run DDL) rather than a schema property
309+
// (what the table looks like). When cluster_name changes, future DDL operations will
310+
// automatically use the new cluster_name via the ON CLUSTER clause, but the table
311+
// itself doesn't need to be recreated.
318312

319313
// Check if PARTITION BY has changed
320314
if before.partition_by != after.partition_by {
@@ -1284,16 +1278,9 @@ mod tests {
12841278

12851279
let changes = strategy.diff_table_update(&before, &after, vec![], order_by_change, "local");
12861280

1287-
// Should return DROP + CREATE (like ORDER BY changes)
1288-
assert_eq!(changes.len(), 2);
1289-
assert!(matches!(
1290-
changes[0],
1291-
OlapChange::Table(TableChange::Removed(_))
1292-
));
1293-
assert!(matches!(
1294-
changes[1],
1295-
OlapChange::Table(TableChange::Added(_))
1296-
));
1281+
// cluster_name is a deployment directive, not a schema property
1282+
// Changing it should not trigger any operations
1283+
assert_eq!(changes.len(), 0);
12971284
}
12981285

12991286
#[test]
@@ -1314,16 +1301,9 @@ mod tests {
13141301

13151302
let changes = strategy.diff_table_update(&before, &after, vec![], order_by_change, "local");
13161303

1317-
// Should return DROP + CREATE (like ORDER BY changes)
1318-
assert_eq!(changes.len(), 2);
1319-
assert!(matches!(
1320-
changes[0],
1321-
OlapChange::Table(TableChange::Removed(_))
1322-
));
1323-
assert!(matches!(
1324-
changes[1],
1325-
OlapChange::Table(TableChange::Added(_))
1326-
));
1304+
// cluster_name is a deployment directive, not a schema property
1305+
// Changing it should not trigger any operations
1306+
assert_eq!(changes.len(), 0);
13271307
}
13281308

13291309
#[test]
@@ -1344,16 +1324,9 @@ mod tests {
13441324

13451325
let changes = strategy.diff_table_update(&before, &after, vec![], order_by_change, "local");
13461326

1347-
// Should return DROP + CREATE (like ORDER BY changes)
1348-
assert_eq!(changes.len(), 2);
1349-
assert!(matches!(
1350-
changes[0],
1351-
OlapChange::Table(TableChange::Removed(_))
1352-
));
1353-
assert!(matches!(
1354-
changes[1],
1355-
OlapChange::Table(TableChange::Added(_))
1356-
));
1327+
// cluster_name is a deployment directive, not a schema property
1328+
// Changing it should not trigger any operations
1329+
assert_eq!(changes.len(), 0);
13571330
}
13581331

13591332
#[test]

apps/framework-docs/llm-docs/python/table-setup.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,39 @@ name = "default"
449449

450450
**Production:** Cluster names must match your ClickHouse `remote_servers` configuration.
451451

452+
#### Understanding `cluster` as a Deployment Directive
453+
454+
The `cluster` field is a **deployment directive** that controls HOW Moose runs DDL operations, not WHAT the table looks like:
455+
456+
- **Changing `cluster` won't recreate your table** - it only affects future DDL operations (CREATE, ALTER, etc.)
457+
- **ClickHouse doesn't store cluster information** - the `ON CLUSTER` clause is only used during DDL execution
458+
- **`moose init --from-remote` & `moose db pull` cannot detect cluster names** - ClickHouse system tables don't preserve this information
459+
460+
**If you're importing existing tables that were created with `ON CLUSTER`:**
461+
1. Run `moose init --from-remote` to generate your table definitions
462+
2. Manually add `cluster="your_cluster_name"` to the generated table configs
463+
3. Future migrations and DDL operations will correctly use `ON CLUSTER`
464+
465+
**Example workflow:**
466+
```python
467+
# After moose init --from-remote generates this:
468+
my_table = OlapTable[MySchema](
469+
"MyTable",
470+
OlapConfig(
471+
order_by_fields=["id"]
472+
)
473+
)
474+
475+
# Manually add cluster if you know it was created with ON CLUSTER:
476+
my_table = OlapTable[MySchema](
477+
"MyTable",
478+
OlapConfig(
479+
order_by_fields=["id"],
480+
cluster="my_cluster" # Add this line
481+
)
482+
)
483+
```
484+
452485
### S3Queue Engine Tables
453486

454487
The S3Queue engine enables automatic processing of files from S3 buckets as they arrive.

apps/framework-docs/llm-docs/typescript/table-setup.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,33 @@ name = "default"
278278

279279
**Production:** Cluster names must match your ClickHouse `remote_servers` configuration.
280280

281+
#### Understanding `cluster` as a Deployment Directive
282+
283+
The `cluster` field is a **deployment directive** that controls HOW Moose runs DDL operations, not WHAT the table looks like:
284+
285+
- **Changing `cluster` won't recreate your table** - it only affects future DDL operations (CREATE, ALTER, etc.)
286+
- **ClickHouse doesn't store cluster information** - the `ON CLUSTER` clause is only used during DDL execution
287+
- **`moose init --from-remote` & `moose db pull` cannot detect cluster names** - ClickHouse system tables don't preserve this information
288+
289+
**If you're importing existing tables that were created with `ON CLUSTER`:**
290+
1. Run `moose init --from-remote` to generate your table definitions
291+
2. Manually add `cluster: "your_cluster_name"` to the generated table configs
292+
3. Future migrations and DDL operations will correctly use `ON CLUSTER`
293+
294+
**Example workflow:**
295+
```typescript
296+
// After moose init --from-remote generates this:
297+
export const MyTable = new OlapTable<MySchema>("MyTable", {
298+
orderByFields: ["id"]
299+
});
300+
301+
// Manually add cluster if you know it was created with ON CLUSTER:
302+
export const MyTable = new OlapTable<MySchema>("MyTable", {
303+
orderByFields: ["id"],
304+
cluster: "my_cluster" // Add this line
305+
});
306+
```
307+
281308
### S3Queue Engine Tables
282309

283310
The S3Queue engine allows you to automatically process files from S3 buckets as they arrive.

apps/framework-docs/src/pages/moose/configuration.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ native_port = 9000
246246
# ClickHouse cluster configuration for replicated tables (optional)
247247
# Define clusters for use with ON CLUSTER DDL operations and distributed tables
248248
# In local dev, Moose creates single-node clusters. In production, names must match your ClickHouse remote_servers config.
249+
#
250+
# Note: Cluster names are deployment directives that control HOW Moose runs DDL (via ON CLUSTER),
251+
# not schema properties. Changing cluster names in your table configs won't trigger table recreation.
249252
# [[clickhouse_config.clusters]]
250253
# name = "default"
251254
# [[clickhouse_config.clusters]]

apps/framework-docs/src/pages/moose/olap/planned-migrations.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ You will commit the entire `migrations/` directory to version control, and Moose
8484

8585
<Callout type="info" title="Why edit the plan?" compact>
8686
Moose makes some assumptions about your schema changes, such as renaming a column instead of dropping and adding. You can modify the plan to override these assumptions.
87+
88+
Note: The `cluster` field controls which ClickHouse cluster Moose uses for `ON CLUSTER` DDL operations. It's a deployment directive, not a schema property, so changing it won't trigger table recreation.
8789
</Callout>
8890

8991
Open `plan.yaml` in your PR. Operations are ordered (teardown first, then setup) to avoid dependency issues. Review like regular code. You can also edit the plan to override the default assumptions Moose makes.

0 commit comments

Comments
 (0)