Migrations and model changes
Here is a scenario.
- You change a model in
laguna-backend-model
crate. - You also change the corresponding migration in
migrations
dir. - Your migration is now out of sync with DB.
- Run
scripts/dbreset.sh laguna_dev_db
which drops currentlaguna_dev_db
, recreates newlaguna_dev_db
and runs all migrations.
Here is another way to do it (without dropping DB):
- You change a model in
laguna-backend-model
crate. - You create a new migration in
migrations
crate usingsqlx migrate add <migration_name>
which contains someALTER
statements which probably haveDEFAULT
s. - You run
sqlx migrate run
to run all migrations.
It is also possible to create "reversible" migrations with sqlx migrate add -r <migration_name>
which will create an up
and down
migration files and can be reverted with sqlx migrate revert
.