Migrations and model changes
Here is a scenario.
- You change a model in
laguna-backend-modelcrate. - You also change the corresponding migration in
migrationsdir. - Your migration is now out of sync with DB.
- Run
scripts/dbreset.sh laguna_dev_dbwhich drops currentlaguna_dev_db, recreates newlaguna_dev_dband runs all migrations.
Here is another way to do it (without dropping DB):
- You change a model in
laguna-backend-modelcrate. - You create a new migration in
migrationscrate usingsqlx migrate add <migration_name>which contains someALTERstatements which probably haveDEFAULTs. - You run
sqlx migrate runto 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.