feat: auto-suggest KS-2/KS-3 document numbers
This commit is contained in:
@@ -9,6 +9,7 @@ WORK_ITEM_OPTIONAL_BOQ_MIGRATION = "20260925_work_item_optional_boq"
|
||||
DAILY_REPORT_OPTIONAL_SYSTEM_MIGRATION = "20260925_daily_report_optional_system"
|
||||
KS2_REPORTING_PERIOD_MIGRATION = "20260925_ks2_reporting_period"
|
||||
PAYMENT_STATUS_MIGRATION = "20260926_payment_status"
|
||||
KS3_NUMBER_UNIQUE_MIGRATION = "20260927_ks3_number_unique"
|
||||
|
||||
|
||||
def run_migrations(engine):
|
||||
@@ -186,6 +187,17 @@ def run_migrations(engine):
|
||||
connection.execute("CREATE INDEX IF NOT EXISTS ix_payments_status ON payments (status)")
|
||||
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
|
||||
(PAYMENT_STATUS_MIGRATION, datetime.now(timezone.utc).isoformat()))
|
||||
if KS3_NUMBER_UNIQUE_MIGRATION not in applied:
|
||||
duplicates = connection.execute(
|
||||
"SELECT project_id, number FROM ks3_documents GROUP BY project_id, number HAVING COUNT(*) > 1"
|
||||
).fetchall()
|
||||
if duplicates:
|
||||
raise RuntimeError(f"Cannot add unique KS3 numbers: duplicates found {duplicates[:10]}")
|
||||
connection.execute(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS uq_ks3_project_number ON ks3_documents (project_id, number)"
|
||||
)
|
||||
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
|
||||
(KS3_NUMBER_UNIQUE_MIGRATION, datetime.now(timezone.utc).isoformat()))
|
||||
violations = connection.execute("PRAGMA foreign_key_check").fetchall()
|
||||
if violations:
|
||||
raise RuntimeError(f"Foreign key violations after agreement migration: {violations[:10]}")
|
||||
|
||||
Reference in New Issue
Block a user