diff --git a/cratedb_toolkit/cfr/systable.py b/cratedb_toolkit/cfr/systable.py index 051549c3..42665eed 100644 --- a/cratedb_toolkit/cfr/systable.py +++ b/cratedb_toolkit/cfr/systable.py @@ -166,7 +166,7 @@ def save(self) -> Path: path_table_schema = path_schema / f"{ExportSettings.TABLE_FILENAME_PREFIX}{tablename}.sql" path_table_data = path_data / f"{ExportSettings.TABLE_FILENAME_PREFIX}{tablename}.{self.data_format}" - tablename_out = f"{ExportSettings.TABLE_FILENAME_PREFIX}{tablename}" + tablename_out = self.adapter.quote_relation_name(f"{ExportSettings.TABLE_FILENAME_PREFIX}{tablename}") # Write schema file. with open(path_table_schema, "w") as fh_schema: diff --git a/tests/cfr/test_cli.py b/tests/cfr/test_cli.py index 412b096f..cbdfe163 100644 --- a/tests/cfr/test_cli.py +++ b/tests/cfr/test_cli.py @@ -108,6 +108,22 @@ def test_cfr_cli_export_failure(cratedb, tmp_path, caplog): assert result.output == "" +def test_cfr_cli_export_ensure_table_name_is_quoted(cratedb, tmp_path, caplog): + runner = CliRunner(env={"CRATEDB_SQLALCHEMY_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}) + result = runner.invoke( + cli, + args="--debug sys-export", + catch_exceptions=False, + ) + assert result.exit_code == 0 + + path = Path(json.loads(result.output)["path"]) + sys_cluster_table_schema = path / "schema" / "sys-cluster.sql" + with open(sys_cluster_table_schema, "r") as f: + content = f.read() + assert '"sys-cluster"' in content, "Table name missing or not quoted" + + def test_cfr_cli_import_success(cratedb, tmp_path, caplog): """ Verify `ctk cfr sys-import` works.