Nuevos cambios en el servidor
This commit is contained in:
23
backend/run_sync_migrations.py
Normal file
23
backend/run_sync_migrations.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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.")
|
||||
Reference in New Issue
Block a user