tuan-tu-tran / ades

Plate-forme web de gestion de dossiers d'élèves pour éducateurs scolaires
www.educ-action.be
GNU General Public License v3.0
0 stars 0 forks source link

Setup a db versioning and upgrading system #27

Closed tuan-tu-tran closed 10 years ago

tuan-tu-tran commented 10 years ago

The idea is that the db has a version that is persisted in it and a version expected by the code that is hard-coded.

Whenever there is a mismatch between the persisted version and the expected version, an upgrade is necessary and the db is modified to level up with the expected version.

For example, for some feature, we need to use a new table. The current version is 1.0 both in code and in db. In the code, we change the expected version to 2.0 and we write that new feature as if the new table was created.

When we deploy this in prod, the prod db will be at 1.0 but the expected version in the code is 2.0 so an upgrade is necessary.

The upgrade system executes the required scripts to bring the db to version 2.0

For each db version we should write an sql ddl script in the upgrade folder named like toX.X.sql

That way the upgrade system can compare the current version to the expected or target version and determine all the intermediary versions and scripts that must be executed to bring the db version to the required target version