This topic is for developers of WingCash. Let’s add posts to this topic about how to get things done and where to find things. All useful info posted here is a candidate for inclusion in the WingCash developer documentation. Questions are also welcome here.
How to create a database migration script in wcbuild
Make all changes you need to the SQLAlchemy declarations in
wingcash.agents. Add/remove/modify tables and columns as needed.
When you’re ready to test your new code, type
bin/resetif you made any schema changes. The
resetscript deletes, re-creates, and repopulates the private Postgres database. You may want to enhance the
populatescript so you don’t have to manually repopulate after every
With Supervisor running, type:
That command dumps the table definitions to 3 files in a directory called
Commit or stash your changes using git, then use
git checkoutto revert to a version without your schema changes. Dump the old schema to a new subdirectory called
Optionally, make a backup now so you don’t have to revert to this version again in case you have to fix the migration script later:
git checkoutto resume normal development on your branch.
List all the changes like this:
diff -Naur schema-before schema-after
Write the migration script(s) based on the diff. The schema file often contains most of the SQL you need to put in the migration script(s).
Update the schema version(s) in
Commit your migration script using git.
bin/supervisordto test your migration. Look at
var/log/appand ensure the migration happened.
diff -Naur schema-after schema-migratedto ensure the migrated schema is functionally equivalent to the expected schema.
If you made any mistakes, fix the migration script and commit it; to test it, first restore the database backup you created earlier:
This may sound like a lot of steps, but it becomes simple once you’ve done it a few times.