Week 8: Database and Migrations

I never thought about how to keep the database updated when working in a team.

Through this project, It’s my first time to learn the concept of migrations and database versions.

Flask-Migration

When I read through the flask web development book, the migration concept was presented. I did not know what it really do when I follow the instructions to include Flask-Migration into our project.

The only thing I know was when anything changes in the database, I need to migrate and upgrade the database.

Problem Envolve

Since my understanding of “migration” was too vague. I did not deliver clearly to my teammates about what were the situations that needed migrations, and what were the steps to migrate. There were some situations we need to upgrade and did not upgrade, so the migration heads are messed up.

This is the time I need to fix it and make sure we understand the basics of migrations.

Migrations Upgrades

What we use is a development database under a development environment, which means that the database should be local to ourselves. What we share with each other is just changes to the database structure.

For example, add one column in the “animals” table to record animal registered date and time, or add an association table to record users and animals tables many to many relationships. These are the times we need to run migration with

 flask db migrate -m "what changed comment"

This will create a new migration head based on your changes to the database. After the head is created, we can upgrade our database to the new head with

flask db upgrade

After that, I can push my code changes and new version to the project codebase. Thus, my teammates could use the new head to upgrade their side local database. We will be on the same page for the newest version of the database.

What I learnt

This process will be more toward industry real scenario. My thoughts on database migrations are still the most basics, but it will be a better foundation compared to my previous understanding.

I really learnt a lot through CS467 and encountered a lot of new problems that I need to solve. The process is full of fun!

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *