Handling database migrations
Handling changes in a relational database requires special consideration.
A relational database stores both data and the structure of the data. Upgrading a database schema offers other challenges then the ones present when upgrading program binaries. Usually, when we upgrade an application binary, we stop the application, upgrade it, and then start it again. We don't really bother about the application state. That is handled outside of the application.
When upgrading databases, we do need to consider state, because a database contains comparatively little logic and structure, but contains much state.
In order to describe a database structure change, we issue a command to change the structure.
The database structures before and after a change is applied should be seen as different versions of the database. How do we keep track of database versions?
Note
Liquibase is a database migration system that, at its core, uses a tried and tested method. There are many systems...