I am currently setting up a project that is based on Python Flask (with Flask Migrate) with a PostgreSQL DB. I am working in a small team and have some questions regarding database updates.
As far as I am aware, If I update the database schema in Flask, I will have to perform a flask db migrate
and flask db upgrade
to apply the changes. And others that receives my update executes a flask db upgrade
to receive the schema changes. All is well but if I have updated rows in the database, how do I propagate the schema changes and data changes to my peers?
If I migrate and upgrade
my flask database followed by exporting a dump with psql
, when my peers receive the updates, do they simply import the data dump? Or do they have to perform a flask db upgrade
as well? If so, which one comes first? flask db upgrade
followed by dump import, or dump import followed by a flask db upgrade
?
I am not sure if simply importing the data dump with updated schema will mess up the migration commits in Flask Migrate. Not sure if this is the right place to ask but I hope I am able to find some answers here. Thanks in advance!
Edit: So far I am updating data in the database by dropping the database and recreating it with the dump, but I have yet to try it with any schema changes (project is progressing, a little slowly..)
Edit 2: Forgot to mention that all instances of PostgreSQL are hosted locally on our own machines
I am not very familiar with
Flask
and its migration mechanism. However, I guess this is not far fromEntity Framework
migration feature. If so, the problem is divided into two parts:First, you need to keep data structure up-to-date among your team. It's the simple part. Once you have changes on your entities (data classes) in your code base, you crate the related migration and commit/push the code. Everybody, including yourself, just upgrade the database based on the available migration. In this part, your actual data is not shared or sent to your colleagues.
Second, you want your data be shared among the people. You have a straightforward solution here. You can take database snapshot/backup/dump and send it to all the team. Consider that they should run the upgrade prior that import the database. Another option is to share a common database on the internet. There is also another work-around. Some technologies like
Entity Framework
allow you to transfer the data via something similar to seeding. If this is not available on your platform, you can publish the SQL script to create/update the desired data.