portfolio_workers / scripts /migrate.sh
arcsu1's picture
Refactor Dockerfile and application structure: switch to Python base image, remove supervisord, and implement Alembic for database migrations; add FastAPI app with forex forecast feature and update requirements
01b5260
Raw History Blame Contribute Delete
839 Bytes
#!/usr/bin/env sh
set -eu
cd "$(dirname "$0")/.."
current_output=$(alembic current)
latest_output=$(alembic heads)
extract_revisions() {
printf '%s\n' "$1" | awk '
$1 ~ /^[[:alnum:]_]+$/ && $1 != "Current" && $1 != "none" {
print $1
}
' | sort -u
}
current_revisions=$(extract_revisions "$current_output")
latest_revisions=$(extract_revisions "$latest_output")
if [ -z "$latest_revisions" ]; then
echo "Unable to determine the latest Alembic revision." >&2
exit 1
fi
if [ "$current_revisions" = "$latest_revisions" ]; then
echo "Database is already at the latest migration ($current_revisions)."
exit 0
fi
echo "Database is not at the latest migration."
echo "Current revision(s): ${current_revisions:-none}"
echo "Latest revision(s): $latest_revisions"
exec alembic upgrade head