ai-station/init_db.py

28 lines
936 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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())