fix(connectors): retain exact CSV source evidence
Module Package Release / publish-packages (push) Successful in 17s
Module Package Release / publish-packages (push) Successful in 17s
Release v0.1.27. Coordinated integrity review: GovOPlaN/govoplan-core#298.
This commit is contained in:
@@ -2,16 +2,45 @@ from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
from alembic import command
|
||||
from alembic.runtime.migration import MigrationContext
|
||||
from sqlalchemy import create_engine, inspect
|
||||
from sqlalchemy import MetaData, Table, create_engine, inspect, select
|
||||
|
||||
from govoplan_connectors.backend.manifest import get_manifest
|
||||
from govoplan_core.db.migrations import migrate_database
|
||||
from govoplan_core.db.migrations import alembic_config, migrate_database
|
||||
|
||||
|
||||
class ConnectorsMigrationTests(unittest.TestCase):
|
||||
def test_csv_evidence_upgrade_preserves_legacy_snapshot_without_inventing_source(self) -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="govoplan-connectors-csv-migration-") as directory:
|
||||
url = f"sqlite:///{Path(directory) / 'connectors.db'}"
|
||||
config = alembic_config(database_url=url, enabled_modules=("connectors",), manifest_factories=(get_manifest,))
|
||||
command.upgrade(config, "c0f1a2b3c4d5")
|
||||
engine = create_engine(url)
|
||||
try:
|
||||
table = Table("connector_tabular_sources", MetaData(), autoload_with=engine)
|
||||
now = datetime.now(UTC)
|
||||
with engine.begin() as connection:
|
||||
connection.execute(table.insert().values(
|
||||
id="legacy-csv", tenant_id="tenant-1", provider="snapshot",
|
||||
source_name="legacy", name="Legacy", status="active", schema_version=1,
|
||||
schema=[{"name": "id", "data_type": "integer", "nullable": False}],
|
||||
rows=[{"id": 1}], fingerprint="a" * 64, row_count=1, byte_count=10,
|
||||
metadata={"original_label": "CSV"}, created_at=now, updated_at=now,
|
||||
))
|
||||
before = dict(connection.execute(select(table)).mappings().one())
|
||||
command.upgrade(config, "d2a4c6e8f0b1")
|
||||
upgraded = Table("connector_tabular_sources", MetaData(), autoload_with=engine)
|
||||
with engine.connect() as connection:
|
||||
after = dict(connection.execute(select(upgraded)).mappings().one())
|
||||
self.assertIsNone(after.pop("csv_source"))
|
||||
self.assertEqual(before, after)
|
||||
finally:
|
||||
engine.dispose()
|
||||
|
||||
def test_baseline_creates_connector_tables_and_head(self) -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="govoplan-connectors-migration-") as directory:
|
||||
url = f"sqlite:///{Path(directory) / 'connectors.db'}"
|
||||
@@ -24,7 +53,7 @@ class ConnectorsMigrationTests(unittest.TestCase):
|
||||
try:
|
||||
with engine.connect() as connection:
|
||||
self.assertIn(
|
||||
"c0f1a2b3c4d5",
|
||||
"d2a4c6e8f0b1",
|
||||
set(MigrationContext.configure(connection).get_current_heads()),
|
||||
)
|
||||
self.assertTrue(
|
||||
|
||||
Reference in New Issue
Block a user