JhHardwareWRS_BackPoint/scripts/migrate_temporary_workers.py
2026-06-24 15:19:14 +08:00

32 lines
964 B
Python

from sqlalchemy import text
from app.database import SessionLocal
def column_exists(db, table_name: str, column_name: str) -> bool:
return bool(db.execute(text(f"SHOW COLUMNS FROM {table_name} LIKE :column"), {"column": column_name}).first())
def main() -> None:
with SessionLocal() as db:
if not column_exists(db, "personnel", "is_temporary"):
db.execute(
text(
"ALTER TABLE personnel "
"ADD COLUMN is_temporary TINYINT(1) NOT NULL DEFAULT 0 AFTER name"
)
)
if not column_exists(db, "personnel", "temporary_expires_at"):
db.execute(
text(
"ALTER TABLE personnel "
"ADD COLUMN temporary_expires_at DATETIME NULL AFTER is_temporary"
)
)
db.commit()
print("temporary worker columns migrated")
if __name__ == "__main__":
main()