cosmo/backend/scripts/run_migration.py

52 lines
1.3 KiB
Python

"""
Run database migration for scheduled_jobs table
"""
import asyncio
import asyncpg
from pathlib import Path
async def run_migration():
"""Run the migration SQL script"""
# Read the migration file
migration_file = Path(__file__).parent.parent / "migrations" / "add_predefined_jobs_support.sql"
with open(migration_file, 'r') as f:
sql = f.read()
# Connect to database
conn = await asyncpg.connect(
user='postgres',
password='cosmo2024',
database='cosmo_db',
host='localhost',
port=5432
)
try:
print("🔄 Running migration: add_predefined_jobs_support.sql")
# Execute the migration
await conn.execute(sql)
print("✅ Migration completed successfully!")
# Verify the changes
result = await conn.fetch("""
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'scheduled_jobs'
ORDER BY ordinal_position
""")
print("\n📋 Current scheduled_jobs table structure:")
for row in result:
print(f" - {row['column_name']}: {row['data_type']} (nullable: {row['is_nullable']})")
finally:
await conn.close()
if __name__ == "__main__":
asyncio.run(run_migration())