feat: add project requisites and agreement cancellation

This commit is contained in:
Александр Арсентьев
2026-09-30 16:42:02 +03:00
parent 3c8bbe8b4b
commit a2a01e24e6
21 changed files with 1828 additions and 12 deletions
+29
View File
@@ -13,6 +13,7 @@ KS3_NUMBER_UNIQUE_MIGRATION = "20260927_ks3_number_unique"
BOQ_DOCUMENT_REQUISITES_MIGRATION = "20260928_boq_document_requisites"
DOCUMENT_ARTIFACTS_MIGRATION = "20260928_document_artifacts"
AGREEMENT_STATUS_CANCELLED_MIGRATION = "20260930_agreement_status_cancelled"
PROJECT_REQUISITES_MIGRATION = "20260930_project_requisites"
def run_migrations(engine):
@@ -279,6 +280,34 @@ def run_migrations(engine):
connection.execute("CREATE INDEX IF NOT EXISTS ix_agreements_boq_document_id ON agreements (boq_document_id)")
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
(AGREEMENT_STATUS_CANCELLED_MIGRATION, datetime.now(timezone.utc).isoformat()))
if PROJECT_REQUISITES_MIGRATION not in applied:
proj_cols = {row[1] for row in connection.execute("PRAGMA table_info(projects)")}
if "investor_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN investor_name VARCHAR")
if "customer_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN customer_name VARCHAR")
if "contractor_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN contractor_name VARCHAR")
if "construction_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN construction_name VARCHAR")
if "object_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN object_name VARCHAR")
if "contract_amount" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN contract_amount NUMERIC(18,2)")
if "contractor_signer_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN contractor_signer_name VARCHAR")
if "contractor_signer_position" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN contractor_signer_position VARCHAR")
if "customer_signer_name" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN customer_signer_name VARCHAR")
if "customer_signer_position" not in proj_cols:
connection.execute("ALTER TABLE projects ADD COLUMN customer_signer_position VARCHAR")
# Normalize legacy customer → customer_name for new domain field
connection.execute(
"UPDATE projects SET customer_name = customer WHERE customer_name IS NULL AND customer IS NOT NULL"
)
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
(PROJECT_REQUISITES_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]}")