28 lines
855 B
Python
Executable File
28 lines
855 B
Python
Executable File
import asyncio
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from chainlit.data.sql_alchemy import SQLAlchemyDataLayer
|
|
|
|
async def init_db():
|
|
DATABASE_URL = "postgresql+asyncpg://ai_user:secure_password_here@localhost:5432/ai_station"
|
|
|
|
print("🔧 Connessione al database...")
|
|
|
|
# Crea engine direttamente
|
|
engine = create_async_engine(DATABASE_URL, echo=True)
|
|
|
|
# Importa i modelli
|
|
from chainlit.data.sql_alchemy import Base
|
|
|
|
print("📊 Creazione tabelle...")
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
|
|
print("✅ Tabelle create con successo!")
|
|
print("\nVerifica con:")
|
|
print(" docker compose exec postgres psql -U ai_user -d ai_station -c '\\dt'")
|
|
|
|
await engine.dispose()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(init_db())
|