Merge pull request #9 from Danieli4/codex/add-offline-event-management-feature-5jma9d
Fix legacy schema upgrade for offline mission columns
This commit is contained in:
commit
39ed6e8813
|
|
@ -55,6 +55,10 @@ def run_migrations() -> None:
|
||||||
if "mission_submissions" in tables:
|
if "mission_submissions" in tables:
|
||||||
submission_columns = {column["name"] for column in inspector.get_columns("mission_submissions")}
|
submission_columns = {column["name"] for column in inspector.get_columns("mission_submissions")}
|
||||||
|
|
||||||
|
mission_columns = set()
|
||||||
|
if "missions" in tables:
|
||||||
|
mission_columns = {column["name"] for column in inspector.get_columns("missions")}
|
||||||
|
|
||||||
with engine.begin() as conn:
|
with engine.begin() as conn:
|
||||||
if "preferred_branch" not in user_columns:
|
if "preferred_branch" not in user_columns:
|
||||||
conn.execute(text("ALTER TABLE users ADD COLUMN preferred_branch VARCHAR(160)"))
|
conn.execute(text("ALTER TABLE users ADD COLUMN preferred_branch VARCHAR(160)"))
|
||||||
|
|
@ -70,6 +74,39 @@ def run_migrations() -> None:
|
||||||
if "resume_link" not in submission_columns:
|
if "resume_link" not in submission_columns:
|
||||||
conn.execute(text("ALTER TABLE mission_submissions ADD COLUMN resume_link VARCHAR(512)"))
|
conn.execute(text("ALTER TABLE mission_submissions ADD COLUMN resume_link VARCHAR(512)"))
|
||||||
|
|
||||||
|
if "missions" in tables:
|
||||||
|
# Легаси-базы без alembic_version пропускали миграцию с офлайн-полями,
|
||||||
|
# поэтому докидываем недостающие колонки вручную, чтобы API /admin не падало.
|
||||||
|
if "format" not in mission_columns:
|
||||||
|
conn.execute(
|
||||||
|
text(
|
||||||
|
"ALTER TABLE missions ADD COLUMN format VARCHAR(20) NOT NULL DEFAULT 'online'"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
conn.execute(text("UPDATE missions SET format = 'online' WHERE format IS NULL"))
|
||||||
|
if "event_location" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN event_location VARCHAR(160)"))
|
||||||
|
if "event_address" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN event_address VARCHAR(255)"))
|
||||||
|
if "event_starts_at" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN event_starts_at TIMESTAMP"))
|
||||||
|
if "event_ends_at" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN event_ends_at TIMESTAMP"))
|
||||||
|
if "registration_deadline" not in mission_columns:
|
||||||
|
conn.execute(
|
||||||
|
text("ALTER TABLE missions ADD COLUMN registration_deadline TIMESTAMP")
|
||||||
|
)
|
||||||
|
if "registration_url" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN registration_url VARCHAR(512)"))
|
||||||
|
if "registration_notes" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN registration_notes TEXT"))
|
||||||
|
if "capacity" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN capacity INTEGER"))
|
||||||
|
if "contact_person" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN contact_person VARCHAR(120)"))
|
||||||
|
if "contact_phone" not in mission_columns:
|
||||||
|
conn.execute(text("ALTER TABLE missions ADD COLUMN contact_phone VARCHAR(64)"))
|
||||||
|
|
||||||
conn.execute(text("CREATE TABLE IF NOT EXISTS alembic_version (version_num VARCHAR(32) NOT NULL)"))
|
conn.execute(text("CREATE TABLE IF NOT EXISTS alembic_version (version_num VARCHAR(32) NOT NULL)"))
|
||||||
conn.execute(text("DELETE FROM alembic_version"))
|
conn.execute(text("DELETE FROM alembic_version"))
|
||||||
conn.execute(text("INSERT INTO alembic_version (version_num) VALUES (:rev)"), {"rev": head_revision})
|
conn.execute(text("INSERT INTO alembic_version (version_num) VALUES (:rev)"), {"rev": head_revision})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user