Skip to content

Commit

Permalink
cfr: Fix quoting of the exported table name
Browse files Browse the repository at this point in the history
  • Loading branch information
seut committed Jun 14, 2024
1 parent a778756 commit 38e6097
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cratedb_toolkit/cfr/systable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/cfr/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 38e6097

Please sign in to comment.