Spaces:
Running
Running
| import os | |
| import urllib.parse | |
| import sys | |
| # Añadir el directorio actual al path para que encuentre 'app' | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| from sqlalchemy import create_engine | |
| from app.database import Base | |
| # Importar TODOS los modelos para que SQLAlchemy los registre en Base.metadata | |
| from app.models.user import User, Device, CreditTransaction | |
| from app.models.iglesia import ( | |
| Iglesia, IglesiaRol, IglesiaMember, Miembro, RelacionFamiliar, | |
| Calendario, Servicio, Asistencia, Finanza, Momento, Inventario | |
| ) | |
| from app.models.aprendizaje import ( | |
| BibliaLibro, BibliaVersiculo, PlanLectura, DiaLectura, | |
| PreguntaQuiz, ProgresoPlan, PuntuacionLiga, Torneo, ParticipanteTorneo | |
| ) | |
| from app.models.lyrics import Group, UserGroup, Lyric, Repertorio, RepertorioLyric, Invitation | |
| from app.models.midi import PartituraMidi | |
| from app.models.process import Task | |
| # Cargar variables de entorno del archivo .env | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| if not DATABASE_URL: | |
| print("[ERROR] Error: La variable de entorno DATABASE_URL no está configurada.") | |
| print("Por favor, asegúrate de definir DATABASE_URL en tu archivo .env.") | |
| sys.exit(1) | |
| print("Conectando a Supabase PostgreSQL...") | |
| engine = create_engine(DATABASE_URL, pool_pre_ping=True) | |
| if __name__ == "__main__": | |
| try: | |
| print(f"Modelos registrados: {list(Base.metadata.tables.keys())}") | |
| print("Creando todas las tablas...") | |
| Base.metadata.create_all(bind=engine) | |
| print("[OK] Base de datos inicializada correctamente en Supabase!") | |
| except Exception as e: | |
| print(f"[ERROR] Error: {e}") | |