cosmo/backend/scripts/check_scheduled_jobs_table.py

65 lines
1.8 KiB
Python

"""
Check the current state of scheduled_jobs table
"""
import asyncio
import sys
from pathlib import Path
# Add backend to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from sqlalchemy import text
from app.database import engine
async def check_table():
"""Check current table structure"""
async with engine.begin() as conn:
# Check if table exists
result = await conn.execute(text("""
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_name = 'scheduled_jobs'
)
"""))
exists = result.scalar()
if not exists:
print("❌ Table 'scheduled_jobs' does not exist yet")
print("💡 You need to run: alembic upgrade head")
return
# Get table structure
result = await conn.execute(text("""
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'scheduled_jobs'
ORDER BY ordinal_position
"""))
rows = result.fetchall()
print("✅ Table 'scheduled_jobs' exists")
print("\n📋 Current table structure:")
for row in rows:
default = row[3] if row[3] else 'NULL'
print(f" - {row[0]}: {row[1]} (nullable: {row[2]}, default: {default})")
# Check for enum type
result = await conn.execute(text("""
SELECT EXISTS (
SELECT FROM pg_type
WHERE typname = 'jobtype'
)
"""))
enum_exists = result.scalar()
if enum_exists:
print("\n✅ ENUM type 'jobtype' exists")
else:
print("\n❌ ENUM type 'jobtype' does NOT exist")
if __name__ == "__main__":
asyncio.run(check_table())