23 lines
764 B
Python
23 lines
764 B
Python
from sqlalchemy import create_engine
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
|
|
# Cargar la URL de la base de datos desde el entorno
|
|
from os import getenv
|
|
DATABASE_URL = getenv("DATABASE_URL", "postgresql://servicemanager:servicemanager123@postgres:5432/servicemanager")
|
|
|
|
# Cambiar el dialecto a uno síncrono
|
|
DATABASE_URL = DATABASE_URL.replace("+asyncpg", "")
|
|
|
|
# Crear un motor síncrono
|
|
engine = create_engine(DATABASE_URL)
|
|
|
|
# Configurar Alembic
|
|
alembic_cfg = Config("backend/migrations/alembic.ini")
|
|
alembic_cfg.attributes['connection'] = engine.connect()
|
|
|
|
# Ejecutar las migraciones
|
|
if __name__ == "__main__":
|
|
print("Ejecutando migraciones...")
|
|
command.upgrade(alembic_cfg, "head")
|
|
print("Migraciones aplicadas correctamente.") |