50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from alembic.runtime.migration import MigrationContext
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
from govoplan_addresses.backend.db.models import Base
|
|
from govoplan_addresses.backend.manifest import get_manifest
|
|
from govoplan_core.db.migrations import migrate_database
|
|
|
|
|
|
class AddressesMigrationTests(unittest.TestCase):
|
|
def test_schema_identifiers_fit_postgresql_limit(self) -> None:
|
|
overlong_indexes = sorted(
|
|
index.name
|
|
for table in Base.metadata.tables.values()
|
|
if table.name.startswith("addresses_")
|
|
for index in table.indexes
|
|
if index.name and len(index.name) > 63
|
|
)
|
|
self.assertEqual([], overlong_indexes)
|
|
|
|
def test_fresh_database_reaches_import_profile_head(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="govoplan-addresses-migration-") as directory:
|
|
url = f"sqlite:///{Path(directory) / 'addresses.db'}"
|
|
migrate_database(
|
|
database_url=url,
|
|
enabled_modules=("addresses",),
|
|
manifest_factories=(get_manifest,),
|
|
)
|
|
engine = create_engine(url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
self.assertIn(
|
|
"d6e8f9a0b1c2",
|
|
set(MigrationContext.configure(connection).get_current_heads()),
|
|
)
|
|
tables = set(inspect(connection).get_table_names())
|
|
self.assertIn("addresses_import_profiles", tables)
|
|
self.assertIn("addresses_import_runs", tables)
|
|
finally:
|
|
engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|