feat: add photos to daily reports
This commit is contained in:
@@ -14,6 +14,7 @@ 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"
|
||||
DAILY_REPORT_PHOTOS_MIGRATION = "20261015_daily_report_photos"
|
||||
|
||||
|
||||
def run_migrations(engine):
|
||||
@@ -308,6 +309,32 @@ def run_migrations(engine):
|
||||
)
|
||||
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
|
||||
(PROJECT_REQUISITES_MIGRATION, datetime.now(timezone.utc).isoformat()))
|
||||
if DAILY_REPORT_PHOTOS_MIGRATION not in applied:
|
||||
connection.execute("""CREATE TABLE IF NOT EXISTS daily_report_photos (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
project_id INTEGER NOT NULL REFERENCES projects(id),
|
||||
daily_report_id INTEGER NOT NULL REFERENCES daily_reports(id),
|
||||
storage_key VARCHAR NOT NULL,
|
||||
original_name VARCHAR,
|
||||
content_type VARCHAR(100) NOT NULL,
|
||||
file_size INTEGER NOT NULL,
|
||||
content_hash VARCHAR(64) NOT NULL,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)""")
|
||||
connection.execute(
|
||||
"CREATE INDEX IF NOT EXISTS ix_daily_report_photos_id ON daily_report_photos (id)"
|
||||
)
|
||||
connection.execute(
|
||||
"CREATE INDEX IF NOT EXISTS ix_daily_report_photos_project_id "
|
||||
"ON daily_report_photos (project_id)"
|
||||
)
|
||||
connection.execute(
|
||||
"CREATE INDEX IF NOT EXISTS ix_daily_report_photos_report_id "
|
||||
"ON daily_report_photos (daily_report_id)"
|
||||
)
|
||||
connection.execute("INSERT INTO schema_migrations(version, applied_at) VALUES (?, ?)",
|
||||
(DAILY_REPORT_PHOTOS_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