Clone
2
資料庫遷移(Migration)介紹與使用方式
張明輝 edited this page 2022-11-14 14:40:19 +08:00
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

前言

本專案使用Flyway作為Database Migration的工具Migration可以幫助我們在多人協同開發時確保資料庫Schema的一致性。

每當我們要讓資料庫異動共用資料如User的角色role or 權限grant或結構增刪改DB Schema)時就要寫一個migration的sql file來讓其他開發人員能同步此次修改

Migration命名規範

版本號結構為: Va.b.c.d__{description}.sql (有兩個'_')

以目前/build.gradle中,allprojectversion 為基礎版本號(a.b.c)

後面一位數則往上遞增

假設專案為以下結構

demo

  • 若目前基礎版本號碼為 0.0.1

    • 可以知道目前該基礎版本的migration已經有一個migration, 若要新增新的migration則尾數向上+1即命名為 0.0.1.2__xxx.sql
  • 若目前基礎版本號碼為 0.0.2

    • 可以知道目前沒有該基礎版本的migration, 若要新增新的migration則命名為 0.0.2.1__xxx.sql