ai-station/init_db.py

28 lines
936 B
Python
Raw Normal View History

2025-12-26 16:48:51 +00:00
import asyncio
from sqlalchemy import create_engine, text
from chainlit.data.sql_alchemy import SQLAlchemyDataLayer
DATABASE_URL = "postgresql+asyncpg://ai_user:secure_password_here@postgres:5432/ai_station"
async def init_database():
"""Inizializza le tabelle per Chainlit"""
print("🔧 Inizializzazione database...")
try:
# Crea data layer
data_layer = SQLAlchemyDataLayer(conninfo=DATABASE_URL)
# Forza creazione tabelle
if hasattr(data_layer, '_create_database'):
await data_layer._create_database()
print("✅ Database inizializzato con successo")
else:
print("⚠️ Metodo _create_database non disponibile")
print(" Le tabelle verranno create automaticamente al primo utilizzo")
except Exception as e:
print(f"❌ Errore: {e}")
if __name__ == "__main__":
asyncio.run(init_database())