""" Migration script for Phase 2 MVP fields: - subjects.is_short_course (BOOLEAN DEFAULT 0) - student_enrollments.allow_same_day_exception (BOOLEAN DEFAULT 0) - student_enrollments.exception_reason (VARCHAR(255)) """ import sqlite3 import os def migrate(): db_paths = [ os.path.join(os.path.dirname(__file__), 'instance', 'app.db'), os.path.join(os.path.dirname(__file__), 'app.db') ] for db_path in db_paths: if not os.path.exists(db_path): continue print(f"Migrating SQLite DB: {db_path}") conn = sqlite3.connect(db_path) cursor = conn.cursor() # Check subjects.is_short_course cursor.execute("PRAGMA table_info(subjects)") columns = [row[1] for row in cursor.fetchall()] if 'is_short_course' not in columns: print("Adding column 'is_short_course' to subjects table...") cursor.execute("ALTER TABLE subjects ADD COLUMN is_short_course BOOLEAN DEFAULT 0") # Check student_enrollments.allow_same_day_exception cursor.execute("PRAGMA table_info(student_enrollments)") enr_columns = [row[1] for row in cursor.fetchall()] if 'allow_same_day_exception' not in enr_columns: print("Adding column 'allow_same_day_exception' to student_enrollments table...") cursor.execute("ALTER TABLE student_enrollments ADD COLUMN allow_same_day_exception BOOLEAN DEFAULT 0") if 'exception_reason' not in enr_columns: print("Adding column 'exception_reason' to student_enrollments table...") cursor.execute("ALTER TABLE student_enrollments ADD COLUMN exception_reason VARCHAR(255)") conn.commit() conn.close() print(f"Migration completed for {db_path}") if __name__ == '__main__': migrate()