Skip to content

Commit c33c52c

Browse files
authored
fix list_tables, include version suffix in Table.name (#2994)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Keep `Table.name` with version suffix from ClickHouse, expose version parsing, update TS/Py generators to emit base table name when suffix matches, and pin backward-compat test to CLI 0.6.201. > > - **ClickHouse/Infrastructure**: > - **`list_tables`**: Preserve version suffix in `Table.name` (use original `table_name`), set `database`, and maintain `version`/`order_by`/settings extraction. > - **API**: Make `extract_version_from_table_name` public. > - **Codegen**: > - **Python/TypeScript**: Use `extract_version_from_table_name` to determine emitted table id; pass base table name to `OlapTable` when parsed `version` equals `table.version` (otherwise use full `table.name`). > - **Tests (E2E)**: > - Pin backward-compat test to `@514labs/moose-cli@0.6.201` and update log message. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit be600d1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7307766 commit c33c52c

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

apps/framework-cli-e2e/test/backward-compatibility.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe("Backward Compatibility Tests", function () {
305305
TEST_AWS_SECRET_ACCESS_KEY: "test-secret-access-key",
306306
};
307307

308-
devProcess = spawn("npx", ["-y", "@514labs/moose-cli@latest", "dev"], {
308+
devProcess = spawn("npx", ["-y", "@514labs/moose-cli@0.6.201", "dev"], {
309309
stdio: "pipe",
310310
cwd: TEST_PROJECT_DIR,
311311
env: devEnv,
@@ -317,7 +317,7 @@ describe("Backward Compatibility Tests", function () {
317317
SERVER_CONFIG.startupMessage,
318318
SERVER_CONFIG.url,
319319
);
320-
console.log("Server started with latest CLI, infrastructure is ready");
320+
console.log("Server started with 0.6.201 CLI, infrastructure is ready");
321321
// Brief wait to ensure everything is fully settled
322322
await setTimeoutAsync(5000);
323323

apps/framework-cli/src/framework/core/infrastructure/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ impl std::fmt::Display for OrderBy {
266266
/// concerns from the core table abstraction.
267267
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
268268
pub struct Table {
269+
// the name field contains the version suffix
269270
pub name: String,
270271
pub columns: Vec<Column>,
271272
pub order_by: OrderBy,

apps/framework-cli/src/framework/python/generate.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::collections::HashMap;
1212
use std::fmt::Write;
1313
use std::sync::LazyLock;
1414

15+
use crate::infrastructure::olap::clickhouse::extract_version_from_table_name;
1516
/// Language-agnostic sanitization: replace common separators with spaces to create word boundaries.
1617
pub use ident::sanitize_identifier;
1718

@@ -708,11 +709,18 @@ pub fn tables_to_python(tables: &[Table], life_cycle: Option<LifeCycle>) -> Stri
708709
OrderBy::SingleExpr(expr) => format!("order_by_expression={:?}", expr),
709710
};
710711

712+
let (base_name, version) = extract_version_from_table_name(&table.name);
713+
let table_name = if version == table.version {
714+
&base_name
715+
} else {
716+
&table.name
717+
};
718+
711719
let var_name = map_to_python_snake_identifier(&table.name);
712720
writeln!(
713721
output,
714722
"{}_table = OlapTable[{}](\"{}\", OlapConfig(",
715-
var_name, table.name, table.name
723+
var_name, table.name, table_name
716724
)
717725
.unwrap();
718726
writeln!(output, " {order_by_spec},").unwrap();

apps/framework-cli/src/framework/typescript/generate.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::collections::HashMap;
1111
use std::fmt::Write;
1212

1313
// Use shared, language-agnostic sanitization (underscores) from utilities
14+
use crate::infrastructure::olap::clickhouse::extract_version_from_table_name;
1415
pub use ident::sanitize_identifier;
1516

1617
/// Map a string to a valid TypeScript PascalCase identifier (for types/classes/consts).
@@ -629,10 +630,17 @@ pub fn tables_to_typescript(tables: &[Table], life_cycle: Option<LifeCycle>) ->
629630
OrderBy::SingleExpr(expr) => format!("orderByExpression: {:?}", expr),
630631
};
631632
let var_name = sanitize_typescript_identifier(&table.name);
633+
634+
let (base_name, version) = extract_version_from_table_name(&table.name);
635+
let table_name = if version == table.version {
636+
&base_name
637+
} else {
638+
&table.name
639+
};
632640
writeln!(
633641
output,
634642
"export const {}Table = new OlapTable<{}>(\"{}\", {{",
635-
var_name, table.name, table.name
643+
var_name, table.name, table_name
636644
)
637645
.unwrap();
638646
writeln!(output, " {order_by_spec},").unwrap();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ async fn execute_raw_sql(
10951095
/// assert_eq!(base_name, "my_table");
10961096
/// assert_eq!(version.to_string(), "1.0.0");
10971097
/// ```
1098-
fn extract_version_from_table_name(table_name: &str) -> (String, Option<Version>) {
1098+
pub fn extract_version_from_table_name(table_name: &str) -> (String, Option<Version>) {
10991099
debug!("Extracting version from table name: {}", table_name);
11001100

11011101
// Special case for empty table name
@@ -1745,7 +1745,8 @@ impl OlapOperations for ConfiguredDBClient {
17451745
debug!("Extracted indexes for table {}: {:?}", table_name, indexes);
17461746

17471747
let table = Table {
1748-
name: base_name, // the name field is without version suffix elsewhere
1748+
// keep the name with version suffix, following PartialInfrastructureMap.convert_tables
1749+
name: table_name,
17491750
columns,
17501751
order_by: OrderBy::Fields(order_by_cols), // Use the extracted ORDER BY columns
17511752
partition_by: {

0 commit comments

Comments
 (0)