42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from pathlib import Path
|
|
import sys
|
|
|
|
from sqlalchemy import text
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.database import engine # noqa: E402
|
|
|
|
|
|
def column_exists(conn, column_name: str) -> bool:
|
|
return bool(conn.execute(
|
|
text("""
|
|
SELECT COUNT(*)
|
|
FROM information_schema.columns
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'work_schedules'
|
|
AND column_name = :column_name
|
|
"""),
|
|
{"column_name": column_name},
|
|
).scalar_one())
|
|
|
|
|
|
def main() -> None:
|
|
with engine.begin() as conn:
|
|
if not column_exists(conn, "auto_submit_hours"):
|
|
conn.execute(text("""
|
|
ALTER TABLE work_schedules
|
|
ADD COLUMN auto_submit_hours DECIMAL(10, 2) NOT NULL DEFAULT 15 AFTER attendance_radius_meters
|
|
"""))
|
|
conn.execute(text("""
|
|
UPDATE work_schedules
|
|
SET auto_submit_hours = 15
|
|
WHERE auto_submit_hours IS NULL OR auto_submit_hours <= 0
|
|
"""))
|
|
print("work_schedules auto_submit_hours migrated")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|