put migration generation into a script

This commit is contained in:
Son NK 2020-05-07 17:59:21 +02:00
parent ef2a385563
commit 0a497c9f67
2 changed files with 17 additions and 12 deletions

View file

@ -1160,18 +1160,7 @@ Whenever the model changes, a new migration has to be created.
If you have Docker installed, you can create the migration by the following script:
```bash
# create a postgres database for SimpleLogin
docker rm -f sl-db
docker run -p 5432:5432 --name sl-db -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sl -d postgres
# run run `flask db upgrade` to upgrade the DB to the latest stage and
env DB_URI=postgresql://postgres:postgres@127.0.0.1:5432/sl flask db upgrade
# finally `flask db migrate` to generate the migration script.
env DB_URI=postgresql://postgres:postgres@127.0.0.1:5432/sl flask db migrate
# remove the db
docker rm -f sl-db
sh new_migration.sh
```
Make sure to review the migration script before committing it.

16
new_migration.sh Normal file
View file

@ -0,0 +1,16 @@
# Generate a new migration script using Docker
# To run it:
# sh new_migration.sh
# create a postgres database for SimpleLogin
docker rm -f sl-db
docker run -p 5432:5432 --name sl-db -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sl -d postgres
# run run `flask db upgrade` to upgrade the DB to the latest stage and
env DB_URI=postgresql://postgres:postgres@127.0.0.1:5432/sl flask db upgrade
# finally `flask db migrate` to generate the migration script.
env DB_URI=postgresql://postgres:postgres@127.0.0.1:5432/sl flask db migrate
# remove the db
docker rm -f sl-db