數據庫版本管理工具Flyway(4.0.3)---工做機制(譯文)

How Flyway worksjava

The easiest scenario is when you point Flyway to an empty database.數據庫

最容易的方案是Flyway指向一個空的數據庫。app

 

It will try to locate its metadata table. As the database is empty. Flyway won't find it and will create it instead.spa

FlyWay將試圖查找它的元數據表。由於數據庫是空的。Flyway找不到它的元數據表,而後就會去建立它的元數據表。3d

You now have a database with a single empty table called SCHEME_VERSION by default:blog

如今呢,咱們就有一個數據庫,這個數據庫包含一個缺省的空表SCHEME_VERSION :排序

This table will be used to track the state of the databse.rem

這張表將被用於監測數據庫的狀態。get

Immediately afterwards Flyway will begin scanning the filesystem or the classpath of the application for migrations.They can be written in either Sql or Java.it

緊接着Flyway將開始掃描文件系統或者應用的類路徑進行遷移。這些遷移文件能夠是SQL腳本或者是java程序。

The migrations are then sorted besed on their version number and applied in order.

這些遷移文件按照版本號進行排序而且按照這個排序去執行。

As each migration gets applied,the metadata table is updated accordingly:

當每個遷移文件被執行後,元數據的表就會按照格式進行更新。

schema_version

With the metabata and the initial state in palce,we can now talk about migrating to newer versions.

這樣咱們就能夠根據元數據和數據庫初始化的狀態,進行數據庫升級了。

Flyway will once agein scan the filesystem or the classpath of the application of the migrations. The migrations are checked against the metadata table. If their version number is lower or equal to the one of the version maked as current, they are ignored.

當Flyway 再次掃描遷移的時候,它就會檢查元數據表中遷移版本,若是要執行的遷移腳本的版本小於或者等於當前版本,Flyway將會忽略,再也不重複執行。

The remaining migrations are the pending migrations : available , but not applied.

剩下的遷移腳本將會被執行遷移:可獲取的而且沒有被執行過的腳本。

They are then sorted by version number and executed in order:

這些遷移文件根據版本號進行排序而且有序執行。

The metadata table is updated accordingly:

元數據的表也會作相應的更新:

And that's it! Every time the need to evolve the database arises, whether structure (DDL) or reference data (DML), simply create a new migration with a version number higher than the current one. The next time Flyway starts, it will find it and upgrade the database accordingly.

這樣的話,每次要作數據庫升級,不管是執行DDL語句仍是執行DML語句,全部的解決的問題的就是建立一個高於如今版本的遷移文件。當下一次Flyway開始運行的時候,它將會自動發現升級腳本,執行而且更新元數據表。

相關文章
相關標籤/搜索