30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""
|
|
Migration script to create moodle_sync_tasks table if it doesn't exist.
|
|
Supports both SQLite and PostgreSQL.
|
|
"""
|
|
from app import create_app, db
|
|
from app.models.sync_task import MoodleSyncTask
|
|
from sqlalchemy import inspect
|
|
|
|
def run_migration():
|
|
app = create_app()
|
|
with app.app_context():
|
|
engine = db.engine
|
|
print(f"Connecting to database using engine: {engine.name}")
|
|
|
|
# db.create_all() creates any missing tables including moodle_sync_tasks
|
|
db.create_all()
|
|
print("db.create_all() executed successfully. Checking table existence...")
|
|
|
|
inspector = inspect(engine)
|
|
tables = inspector.get_table_names()
|
|
if 'moodle_sync_tasks' in tables:
|
|
print("SUCCESS: 'moodle_sync_tasks' table exists and is ready.")
|
|
cols = [c['name'] for c in inspector.get_columns('moodle_sync_tasks')]
|
|
print(f"Columns in moodle_sync_tasks: {cols}")
|
|
else:
|
|
print("ERROR: 'moodle_sync_tasks' table was not created.")
|
|
|
|
if __name__ == '__main__':
|
|
run_migration()
|