Files
lasuite-drive/migrate.sh
notplants 0b64135f98 run migrations automatically on backend startup (AUTO_MIGRATIONS)
Add a migrate.sh config (ported from lasuite-docs) that the backend
entrypoint runs when AUTO_MIGRATIONS=true (default). It loads secrets,
waits for the DB, and idempotently applies pending migrations via
'migrate --check' then 'migrate --noinput'. The manual 'abra app cmd
backend migrate' now delegates to the same script.
2026-06-23 19:13:39 +00:00

27 lines
598 B
Bash

#!/bin/sh
set -e
# Load secrets into environment
source /abra-entrypoint.sh -e
# Wait for database to be ready (up to 30 seconds)
i=0
while ! python manage.py check --database default 2>/dev/null; do
i=$((i+1))
if [ "$i" -ge 30 ]; then
echo "migrate: timed out waiting for database" >&2
exit 1
fi
sleep 1
done
# Idempotent: skip if no pending migrations
if python manage.py migrate --check > /dev/null 2>&1; then
echo "migrate: no pending migrations, skipping"
exit 0
fi
echo "migrate: applying pending migrations..."
python manage.py migrate --noinput
echo "migrate: done"