27 lines
594 B
Bash
27 lines
594 B
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
echo "📦 Running Alembic migrations..."
|
|
|
|
export SKIP_SCHEMA_BOOTSTRAP=1
|
|
|
|
MISSING=$(python3 <<EOF
|
|
from sqlalchemy import create_engine, inspect
|
|
from backend.core.settings import SQLALCHEMY_DATABASE_URI
|
|
|
|
engine = create_engine(SQLALCHEMY_DATABASE_URI)
|
|
inspector = inspect(engine)
|
|
tables = inspector.get_table_names()
|
|
print("1" if "users" not in tables else "0")
|
|
EOF
|
|
)
|
|
|
|
if [ "$MISSING" -eq "1" ]; then
|
|
echo "'users' table missing. Running Alembic migrations..."
|
|
alembic -c alembic.ini upgrade head
|
|
else
|
|
echo "DB already initialized. Skipping migrations."
|
|
fi
|
|
|
|
exec "$@"
|