fix trigger creation bug
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user