fix trigger creation bug

This commit is contained in:
2025-05-30 10:55:42 +02:00
parent df8209e86d
commit 3e9ad2dcb1
2 changed files with 30 additions and 5 deletions

View File

@@ -28,11 +28,36 @@ def init_database():
print(f"📍 Database URL: {database_url}")
try:
# Create all tables
# Create all tables first
print("📊 Creating tables...")
Base.metadata.create_all(bind=engine)
print("✅ Tables created successfully")
# Verify critical tables exist before creating triggers
print("🔍 Verifying tables exist...")
with engine.connect() as connection:
# Check if products and products_history tables exist
products_exists = connection.execute(text("""
SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_name = 'products'
);
""")).scalar()
history_exists = connection.execute(text("""
SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_name = 'products_history'
);
""")).scalar()
if not products_exists:
raise Exception("Products table was not created")
if not history_exists:
raise Exception("Products history table was not created")
print("✅ Required tables verified")
# Create triggers (if not already created by event listener)
print("⚙️ Ensuring triggers are created...")
with engine.connect() as connection: