網頁

2022/5/24

Liquibase tag資料庫狀態

Liquibase tag標記資料庫目前狀態。


Tag是指將目前的資料庫狀態標注一個tag名稱,即在DATABASECHANGELOG最後一筆紀錄的TAG欄位加上tag名稱,之後可用rollback命令把資料庫狀態回復到tag時的狀態。

範例環境:

  • macOS BigSur version 10.15.5
  • Liquibase 4.10.0


事前要求

參考「Liquibase sql-format H2新增資料」在EMPLOYEE資料表新增資料。


Tag

DATABASECHANGELOG紀錄的TAG欄位原本未標記任何tag。

sql> SELECT * FROM databasechangelog;
ID | AUTHOR   | FILENAME      | DATEEXECUTED               | ORDEREXECUTED | EXECTYPE | MD5SUM                             | DESCRIPTION | COMMENTS | TAG  | LIQUIBASE | CONTEXTS | LABELS | DEPLOYMENT_ID
1  | employee | changelog.sql | 2022-05-24 16:43:01.221643 | 1             | EXECUTED | 8:28bb5eee313e523c6f750d4473e7bb0b | sql         |          | null | 4.10.0    | null     | null   | 3381780263
2  | employee | changelog.sql | 2022-05-24 16:51:02.397504 | 2             | EXECUTED | 8:b1bb25282c1a42ee4b411b34e605247f | sql         |          | null | 4.10.0    | null     | null   | 3382261332
3  | employee | changelog.sql | 2022-05-24 16:51:02.403449 | 3             | EXECUTED | 8:a0a2e29df3bb3d319f3f3c7d8dd907bd | sql         |          | null   | 4.10.0    | null     | null   | 3382261332
(3 rows, 3 ms)

liquibase.properties所在目錄命令列輸入liquibase tag v1把目前狀態標記一個tag v1

再次查詢DATABASECHANGELOG可看到最後一筆紀錄的TAG欄位變成v1

sql> SELECT * FROM databasechangelog;
ID | AUTHOR   | FILENAME      | DATEEXECUTED               | ORDEREXECUTED | EXECTYPE | MD5SUM                             | DESCRIPTION | COMMENTS | TAG  | LIQUIBASE | CONTEXTS | LABELS | DEPLOYMENT_ID
1  | employee | changelog.sql | 2022-05-24 16:43:01.221643 | 1             | EXECUTED | 8:28bb5eee313e523c6f750d4473e7bb0b | sql         |          | null | 4.10.0    | null     | null   | 3381780263
2  | employee | changelog.sql | 2022-05-24 16:51:02.397504 | 2             | EXECUTED | 8:b1bb25282c1a42ee4b411b34e605247f | sql         |          | null | 4.10.0    | null     | null   | 3382261332
3  | employee | changelog.sql | 2022-05-24 16:51:02.403449 | 3             | EXECUTED | 8:a0a2e29df3bb3d319f3f3c7d8dd907bd | sql         |          | v1   | 4.10.0    | null     | null   | 3382261332
(3 rows, 3 ms)

沒有留言:

張貼留言