ai-station/init_db.py

27 lines
878 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
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")