fix(datasources): preserve governed CSV originals and fresh detail state
Module Package Release / publish-packages (push) Successful in 12s
Module Package Release / publish-packages (push) Successful in 12s
Release v0.1.26. Coordinated integrity review: GovOPlaN/govoplan-core#298.
This commit is contained in:
@@ -14,6 +14,47 @@ from govoplan_datasources.backend.manifest import get_manifest
|
||||
|
||||
|
||||
class DatasourceMigrationTests(unittest.TestCase):
|
||||
def test_csv_evidence_upgrade_preserves_legacy_rows_and_fingerprints(self) -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="govoplan-datasources-csv-migration-") as directory:
|
||||
url = f"sqlite:///{Path(directory) / 'datasources.db'}"
|
||||
config = self._config(url)
|
||||
command.upgrade(config, "d1a7c3e9f5b2")
|
||||
engine = create_engine(url)
|
||||
try:
|
||||
metadata = MetaData()
|
||||
tables = {name: Table(name, metadata, autoload_with=engine) for name in (
|
||||
"datasource_catalogue", "datasource_stages", "datasource_materializations",
|
||||
)}
|
||||
now = datetime.now(UTC)
|
||||
common = dict(tenant_id="tenant-1", schema=[], fingerprint="a" * 64,
|
||||
metadata={"retained": True}, provenance={}, created_at=now, updated_at=now)
|
||||
with engine.begin() as connection:
|
||||
connection.execute(tables["datasource_catalogue"].insert().values(
|
||||
**common, id="legacy-source", source_name="legacy", name="Legacy", kind="upload",
|
||||
mode="static", shape="tabular", status="active", schema_version=1,
|
||||
))
|
||||
connection.execute(tables["datasource_stages"].insert().values(
|
||||
**common, id="legacy-stage", source_name="staged", name="Staged", kind="upload",
|
||||
mode="static", shape="tabular", state="ready", rows=[{"id": 1}],
|
||||
row_count=1, byte_count=10, validation={}, governance={}, approval={},
|
||||
))
|
||||
connection.execute(tables["datasource_materializations"].insert().values(
|
||||
**common, id="legacy-materialization", datasource_id="legacy-source", revision=1,
|
||||
state="published", schema_version=1, rows=[{"id": 1}], row_count=1,
|
||||
byte_count=10, governance_snapshot={},
|
||||
))
|
||||
before = {name: dict(connection.execute(select(table)).mappings().one()) for name, table in tables.items()}
|
||||
command.upgrade(config, "e2b8d4a0f6c3")
|
||||
with engine.connect() as connection:
|
||||
for name in tables:
|
||||
upgraded = Table(name, MetaData(), autoload_with=connection)
|
||||
after = dict(connection.execute(select(upgraded)).mappings().one())
|
||||
if name != "datasource_catalogue":
|
||||
self.assertIsNone(after.pop("csv_source"))
|
||||
self.assertEqual(before[name], after)
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
@staticmethod
|
||||
def _config(url: str):
|
||||
return alembic_config(
|
||||
@@ -34,7 +75,7 @@ class DatasourceMigrationTests(unittest.TestCase):
|
||||
try:
|
||||
with engine.connect() as connection:
|
||||
self.assertIn(
|
||||
"d1a7c3e9f5b2",
|
||||
"e2b8d4a0f6c3",
|
||||
set(MigrationContext.configure(connection).get_current_heads()),
|
||||
)
|
||||
catalogue_columns = {
|
||||
|
||||
Reference in New Issue
Block a user