feat(tht): schema columns reader (name/description/type/pk) from catalog

This commit is contained in:
2026-07-06 23:25:00 +02:00
committed by Marco Pancotti
parent bfb54922f7
commit 9339a8272b
2 changed files with 80 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
import json
from datetime import datetime
from typer.testing import CliRunner
from tht.cli import app # the root Typer app that mounts schema_app as "schema"
from tht.mschema.models import ColumnPhysical, PhysicalSchema, TablePhysical
def _write_catalog(tmp_path):
phys = PhysicalSchema(
database="d", schema="s", introspected_at=datetime(2026, 1, 1),
tables={
"dim_patient": TablePhysical(
comment="Anagrafica",
columns={
"cod_paz": ColumnPhysical(type="bigint", pk=True, comment="Codice paziente"),
"nome": ColumnPhysical(type="text", comment="Nome"),
},
)
},
)
out = tmp_path / "artifacts" / "mschema" / "physical.yaml"
phys.to_yaml(out)
return out
def test_schema_columns_json(tmp_path, monkeypatch):
_write_catalog(tmp_path)
cfg = tmp_path / "workspace.yaml"
cfg.write_text(
"database: {database: d, schema: s, user: u, password: p, transport: direct}\n"
f"paths: {{artifacts: {tmp_path/'artifacts'}, indexes: {tmp_path/'i'}, sessions: {tmp_path/'s'}}}\n"
)
res = CliRunner().invoke(app, ["schema", "columns", "dim_patient", "--json", "-c", str(cfg)])
assert res.exit_code == 0, res.output
data = json.loads(res.output)
assert data["table"] == "dim_patient"
assert data["description"] == "Anagrafica"
assert {"name": "cod_paz", "description": "Codice paziente", "type": "bigint", "pk": True} in data["columns"]