38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Migration: Add end_date column to tryouts table.
|
|
|
|
Run this script to add the end_date column to the tryouts table.
|
|
Usage: python migrations/add_tryout_end_date.py
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from app.app import create_app
|
|
from app.extensions import db
|
|
from sqlalchemy import text
|
|
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
# Check if column already exists
|
|
result = db.session.execute(text(
|
|
"SELECT COUNT(*) FROM information_schema.columns "
|
|
"WHERE table_name = 'tryouts' AND column_name = 'end_date'"
|
|
))
|
|
exists = result.scalar() > 0
|
|
|
|
if exists:
|
|
print("Column 'end_date' already exists in 'tryouts' table. Skipping.")
|
|
else:
|
|
db.session.execute(text(
|
|
"ALTER TABLE tryouts ADD COLUMN end_date DATE NULL"
|
|
))
|
|
# Backfill: set end_date = date for existing tryouts
|
|
db.session.execute(text(
|
|
"UPDATE tryouts SET end_date = date WHERE end_date IS NULL"
|
|
))
|
|
db.session.commit()
|
|
print("Successfully added 'end_date' column to 'tryouts' table and backfilled existing rows.")
|
|
|
|
print("Migration complete.") |