PostgreSQL Database Change Management with Django Migration

Ridwan Fajar
NiceDay Development
2 min readJun 28, 2021
My weevil portrait which I took at Ciwangun Indah Camp, West Bandung Regency, West Java Province, Indonesia

How to track changes and in database structure and dataset after new version of backend service deployed? How to revert it back if the deployment has an issue on database side?

I want to share my perspective about trackable database structure change as former backend team and currently as infrastructure team.

Its almost 4 years for NiceDay Nederland (formerly known as SenseHealth B.V.) to use Django as backend framework. For first two years, I involved as backend developer and write some migration scripts which is very useful to have our changes on our Python scripts. We use PostgreSQL for main transactional database and track every changes on that database.

Then after two years, I am fully joining Infrastructure Team and sometime handle backend developer requests regarding deployment. From my perspective, I could apply database change without touching SQL syntax such as CREATE TABLE or ALTER TABLE. Just let the migration scripts running. I could revert the migration and database change based on our strong “Deployment Request Document” which contain scenario for applying changes or revert it.

Django migration log is also helpful. You might find some exceptions and trace it easily if you encountered problem during migrations. You might check which migration that has been applied before. And about your dataset, don’t worry. We have consistent dataset because backend team test the migration script before create a request to infrastructure team for deploying new version of backend service.

By using Django Migration Tools, our life is easier.

Whatever the tools, keep your database structure change on migration script. You might alter your database structure manually after the deployment or revert it back whenever its needed. But that might time consuming workflow for your process.

And please keep in your mind, backup your dataset regularly just in case you might encounter disaster during applying migration script. Its also a best practice which introduced by ISO 27001:2013 for Information System Security Standard.

Thanks for reading! Have a nice day.

--

--