dribdat/force-migrate.sh

36 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2017-01-24 09:08:22 +00:00
#!/bin/bash
2021-03-15 21:02:10 +00:00
# Run without arguments or scroll down for instructions
if [ "$1" = "psql" ]; then
echo "Force migrating database"
rm -rf migrations/
psql -c "DROP TABLE alembic_version;" $DATABASE_URL
2023-04-25 17:49:32 +00:00
python "${APPDIR:-.}/manage.py" db init 2>&1 >/dev/null
python "${APPDIR:-.}/manage.py" db migrate
python "${APPDIR:-.}/manage.py" db upgrade
2021-03-15 23:01:58 +00:00
echo "Upgrade complete, 10 second cooldown"
sleep 10
2021-03-15 21:02:10 +00:00
elif [ "$1" = "heroku" ]; then
2019-03-14 16:09:24 +00:00
if [ -z "$2" ]; then
echo "Specify the app you wish to upgrade as a second parameter."
exit
fi
echo "Migrating Heroku DB on $2 in 5 seconds - Ctrl-C to abort."
2017-01-24 09:08:22 +00:00
sleep 5s
2019-03-14 16:09:24 +00:00
heroku pg:psql -a $2 -c "drop table alembic_version"
2023-04-25 17:49:32 +00:00
heroku run -a $2 "python ${APPDIR:-.}/manage.py db init && python ${APPDIR:-.}/manage.py db migrate && python ${APPDIR:-.}/manage.py db upgrade"
2021-03-15 21:02:10 +00:00
elif [ "$1" = "local" ]; then
echo "Resetting local SQLite DB (dev.db)"
2023-04-25 17:49:32 +00:00
rm -rf "${APPDIR:-.}/dev.db"
python "${APPDIR:-.}/manage.py" db migrate
python "${APPDIR:-.}/manage.py" db upgrade
2021-03-15 21:02:10 +00:00
else
2021-05-12 06:16:00 +00:00
echo "Use this script with the following arguments to refresh the DB schema:"
echo " psql - in production (such as your server ssh console)"
echo " heroku - to modify a locally configured remote app"
echo " local - wipe and reset your development SQLite file (dev.db)"
2017-01-24 09:08:22 +00:00
fi