51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Database initialization script for ItDontFitGS API
|
|
Run this script to create the database tables
|
|
"""
|
|
|
|
from database import create_tables, engine
|
|
from sqlalchemy import text
|
|
import sys
|
|
|
|
def init_database():
|
|
"""Initialize the database and create tables"""
|
|
try:
|
|
# Test database connection
|
|
with engine.connect() as connection:
|
|
result = connection.execute(text("SELECT 1"))
|
|
print("✓ Database connection successful")
|
|
|
|
# Create tables
|
|
create_tables()
|
|
print("✓ Database tables created successfully")
|
|
|
|
# Verify tables exist
|
|
with engine.connect() as connection:
|
|
result = connection.execute(text("""
|
|
SELECT table_name
|
|
FROM information_schema.tables
|
|
WHERE table_schema = 'public'
|
|
AND table_name IN ('messages', 'transactions')
|
|
ORDER BY table_name
|
|
"""))
|
|
tables = [row[0] for row in result]
|
|
|
|
if 'messages' in tables and 'transactions' in tables:
|
|
print("✓ Tables verified: messages, transactions")
|
|
else:
|
|
print("✗ Table verification failed")
|
|
return False
|
|
|
|
print("\n🎉 Database initialization completed successfully!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ Database initialization failed: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("Initializing ItDontFitGS API database...")
|
|
success = init_database()
|
|
sys.exit(0 if success else 1)
|