官术网_书友最值得收藏!

  • Practical DevOps
  • Joakim Verona
  • 388字
  • 2021-07-16 09:48:07

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 like this, usually at least one for every programming language. Liquibase is well-known in the Java world, and even in the Java world, there are several alternatives that work in a similar manner. Flyway is another example for the Java platform.

Generally, database migration systems employ some variant of the following method:

  • Add a table to the database where a database version is stored.
  • Keep track of database change commands and bunch them together in versioned changesets. In the case of Liquibase, these changes are stored in XML files. Flyway employs a slightly different method where the changesets are handled as separate SQL files or occasionally as separate Java classes for more complex transitions.
  • When Liquibase is being asked to upgrade a database, it looks at the metadata table and determines which changesets to run in order to make the database up-to-date with the latest version.

As previously stated, many database version management systems work like this. They differ mostly in the way the changesets are stored and how they determine which changesets to run. They might be stored in an XML file, like in the case of Liquibase, or as a set of separate SQL files, as with Flyway. This later method is more common with homegrown systems and has some advantages. The Clojure ecosystem also has at least one similar database migration system of its own, called Migratus.

主站蜘蛛池模板: 莫力| 明光市| 乡宁县| 汝南县| 张家川| 莎车县| 昌邑市| 富裕县| 澄迈县| 镶黄旗| 盐池县| 荣昌县| 多伦县| 新干县| 台南县| 东台市| 灵宝市| 曲沃县| 涡阳县| 湖南省| 赤峰市| 高唐县| 红安县| 峨边| 三门县| 舟曲县| 三门县| 延寿县| 望谟县| 忻州市| 昌平区| 枣阳市| 蓝山县| 玉龙| 伊宁市| 茶陵县| 公主岭市| 凤台县| 钦州市| 炉霍县| 阿克苏市|