27 lines
878 B
Python
27 lines
878 B
Python
import asyncio
|
||
import asyncpg
|
||
import os
|
||
import sys
|
||
|
||
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+asyncpg://ai_user:secure_password_here@postgres:5432/ai_station")
|
||
|
||
# Converti da SQLAlchemy URL a asyncpg
|
||
db_url = DATABASE_URL.replace("postgresql+asyncpg://", "postgresql://")
|
||
|
||
async def init_database():
|
||
print("🔧 Inizializzazione database...")
|
||
try:
|
||
conn = await asyncpg.connect(db_url)
|
||
|
||
# Crea schema se non esiste (Chainlit lo farà automaticamente)
|
||
print("✅ Connessione al database riuscita")
|
||
print("ℹ️ Le tabelle verranno create automaticamente da Chainlit")
|
||
|
||
await conn.close()
|
||
except Exception as e:
|
||
print(f"❌ Errore connessione database: {e}")
|
||
sys.exit(1)
|
||
|
||
if __name__ == "__main__":
|
||
asyncio.run(init_database())
|
||
print("✅ Inizializzazione database completata") |