- Updated the Alembic upgrade command to use a Python script for execution, addressing issues with configuration handling in Docker. - Enhanced comments to clarify the purpose of the changes and their implications for E2E testing.
39 lines
956 B
Python
39 lines
956 B
Python
"""
|
|
E2E/Jenkins: aplica migraciones sin la CLI de Alembic.
|
|
|
|
docker compose run … alembic --config=… a veces deja un Config vacío (No 'script_location');
|
|
aquí se carga explícitamente /app/alembic.ini y se llama a command.upgrade().
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> int:
|
|
root = Path("/app")
|
|
if not root.is_dir():
|
|
print("ERROR: /app no es un directorio (volumen backend).", file=sys.stderr)
|
|
return 1
|
|
os.chdir(root)
|
|
sys.path.insert(0, str(root))
|
|
|
|
ini = root / "alembic.ini"
|
|
if not ini.is_file():
|
|
print(
|
|
f"ERROR: {ini} no existe. Comprueba el bind ./backend:./app en el agente.",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
from alembic.config import Config
|
|
from alembic import command
|
|
|
|
command.upgrade(Config(str(ini)), "head")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|