5. 配置文件的編寫

配置文件編寫的示例如下:

 <?xml version="1.0" encoding="UTF-8"?>   
<databaseChangeLog   
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"   
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">   
  <changeSet  author="authorName"  id="changelog-1.0">  
    <createTable  tableName="TablesAndTables">  
      <column  name="COLUMN1"  type="TEXT">  
        <constraints  nullable="true"  primaryKey="false"  unique="false"/>  
      </column>  
    </createTable>  
  </changeSet>  
</databaseChangeLog> 

配置文件以一個個changeSet組成。changeSet的操作分為以下幾類

add

標簽 說明
addAutoIncrement 將已存在的列改為自增列
addColumn 增加列
addDefaultValue 增加列的默認值
addForeignKeyConstraint 增加外鍵
addLookupTable 創(chuàng)建外鍵的關(guān)聯(lián)表
addNotNullConstraint 增加非空值約束
addPrimaryKey 增加主鍵
addUniqueConstraint 增加唯一值約束

create

標簽 說明
createIndex 創(chuàng)建索引
createProcedure 創(chuàng)建存儲過程
createSequence 創(chuàng)建序列
createTable 創(chuàng)建表
createView 創(chuàng)建視圖

drop

標簽 說明
dropAllForeignKeyConstraints 刪除全部外鍵約束
dropColumn 刪除列
dropDefaultValue 刪除默認值
dropForeignKeyConstraint 刪除某一外鍵約束
dropNotNullConstraint 刪除空值約束
dropPrimaryKey 刪除主鍵
dropProcedure 刪除存儲過程
dropSequence 刪除序列
dropTable 刪除表
dropUniqueConstraint 刪除唯一約束
dropView 刪除視圖

rename

標簽 說明
renameColumn 重命名列
renameSequence 重命名序列
renameTable 重命名表
renameView 重命名視圖

sql

標簽 說明
sql sql語句
sqlFile sql文件

其他

標簽 說明
insert 插入數(shù)據(jù)
update 更新數(shù)據(jù)
delete 刪除數(shù)
empty 空操作
executeCommand 執(zhí)行命名
alterSequence 修改序列
customChange 自定義操作,需自己實現(xiàn)
loadData 導入csv數(shù)據(jù)至已存在的表中
loadUpdateData 導入csv數(shù)據(jù)至表中,表不存在則新建
mergeColumns 合并列
modifyDataType 修改數(shù)據(jù)類型
output 輸出日志
setColumnRemarks 增加列說明
setTableRemarks 增加表說明
stop 停止liquibase
tagDatabase 打標簽用于將來回滾

詳細的操作說明見https://docsstage.liquibase.com/change-types/community/home.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容