Spaces:
Running
Running
test: keep project migration contracts aligned
Browse files
tests/test_database_migration_contracts.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
import re
|
| 4 |
import unittest
|
| 5 |
from pathlib import Path
|
| 6 |
|
|
@@ -20,20 +19,34 @@ ALLOWED_TABLES = {
|
|
| 20 |
|
| 21 |
|
| 22 |
class MigrationContractTests(unittest.TestCase):
|
| 23 |
-
def
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
self.assertIn("alter
|
| 29 |
-
self.assertIn("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def test_migrations_do_not_recreate_shared_tables(self) -> None:
|
| 32 |
counts: dict[str, int] = {}
|
| 33 |
for path in MIGRATION_FILES:
|
| 34 |
body = path.read_text()
|
| 35 |
for table in ALLOWED_TABLES:
|
| 36 |
-
counts[table] = counts.get(table, 0) + body.count(
|
|
|
|
|
|
|
| 37 |
|
| 38 |
for table, count in counts.items():
|
| 39 |
self.assertEqual(
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
import unittest
|
| 4 |
from pathlib import Path
|
| 5 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
class MigrationContractTests(unittest.TestCase):
|
| 22 |
+
def test_approval_workspace_integrity_migration_remains_present(self) -> None:
|
| 23 |
+
migration = Path(
|
| 24 |
+
"app/projects/migrations/0014_approval_workspace_integrity.sql"
|
| 25 |
+
).read_text()
|
| 26 |
+
|
| 27 |
+
self.assertIn("alter table approval_requests", migration)
|
| 28 |
+
self.assertIn("add column if not exists workspace_id text", migration)
|
| 29 |
+
self.assertIn("alter column workspace_id set not null", migration)
|
| 30 |
+
self.assertIn("create index if not exists ix_approval_requests_workspace", migration)
|
| 31 |
+
|
| 32 |
+
def test_latest_migration_repairs_project_brand_kit_reference(self) -> None:
|
| 33 |
+
latest = MIGRATION_FILES[-1]
|
| 34 |
+
self.assertEqual(latest.name, "0015_repair_project_brand_kit_column.sql")
|
| 35 |
+
body = latest.read_text()
|
| 36 |
+
|
| 37 |
+
self.assertIn("alter table projects", body)
|
| 38 |
+
self.assertIn("add column if not exists brand_kit_id text", body)
|
| 39 |
+
self.assertIn("fk_projects_brand_kit", body)
|
| 40 |
+
self.assertIn("ix_projects_workspace_brand_kit", body)
|
| 41 |
|
| 42 |
def test_migrations_do_not_recreate_shared_tables(self) -> None:
|
| 43 |
counts: dict[str, int] = {}
|
| 44 |
for path in MIGRATION_FILES:
|
| 45 |
body = path.read_text()
|
| 46 |
for table in ALLOWED_TABLES:
|
| 47 |
+
counts[table] = counts.get(table, 0) + body.count(
|
| 48 |
+
f"create table if not exists {table}"
|
| 49 |
+
)
|
| 50 |
|
| 51 |
for table, count in counts.items():
|
| 52 |
self.assertEqual(
|