Commit 1e5183a0 authored by custom's avatar custom

Merge origin/master into master

parents 9fe4837e 07f8b87e
......@@ -55,11 +55,100 @@ Liquibase 使用手册
> TL 表均为联合主键,没有自增长、sequence 等
参考示例:
在groovy中创建一张表
```groovy
import com.hand.hap.liquibase.MigrationHelper
def mhi = MigrationHelper.getInstance()
databaseChangeLog(logicalFilePath: "2016-09-26-init-migration.groovy") {
changeSet(author: "作者名", id: "日期-作者-表名") {
createTable(tableName: "HR_EMPLOYEE") {
column(autoIncrement: "true", startWith: "10001", name: "EMPLOYEE_ID", type: "BIGINT", remarks: "员工ID") {
constraints(nullable: "false", primaryKey: "true", primaryKeyName: "HR_EMPLOYEE_PK")
}
column(name: "EMPLOYEE_CODE", remarks: "员工编码", type: "VARCHAR(30)") {
constraints(nullable: "false", unique: "true", uniqueConstraintName: "HR_EMPLOYEE_U1")
}
column(name: "NAME", remarks: "员工姓名", type: "VARCHAR(50)") { constraints(nullable: "false") }
column(name: "BORN_DATE", remarks: "出生日期", type: "DATE")
column(name: "EMAIL", remarks: "电子邮件", type: "VARCHAR(50)")
column(name: "MOBIL", remarks: "移动电话", type: "VARCHAR(50)")
column(name: "JOIN_DATE", remarks: "入职日期", type: "DATE")
column(name: "GENDER", remarks: "性别", type: "VARCHAR(1)")
column(name: "CERTIFICATE_ID", remarks: "ID", type: "VARCHAR(100)") {
constraints(nullable: "false", unique: "true", uniqueConstraintName: "HR_EMPLOYEE_U2")
}
column(name: "STATUS", remarks: "状态", type: "VARCHAR(50)") { constraints(nullable: "false") }
column(name: "ENABLED_FLAG", remarks: "启用状态", type: "VARCHAR(1)", defaultValue: "Y") {
constraints(nullable: "false")
}
column(name: "OBJECT_VERSION_NUMBER", type: "BIGINT", defaultValue: "1")
column(name: "REQUEST_ID", type: "BIGINT", defaultValue: "-1")
column(name: "PROGRAM_ID", type: "BIGINT", defaultValue: "-1")
column(name: "CREATED_BY", type: "BIGINT", defaultValue: "-1")
column(name: "CREATION_DATE", type: "DATETIME", defaultValueComputed: "CURRENT_TIMESTAMP")
column(name: "LAST_UPDATED_BY", type: "BIGINT", defaultValue: "-1")
column(name: "LAST_UPDATE_DATE", type: "DATETIME", defaultValueComputed: "CURRENT_TIMESTAMP")
column(name: "LAST_UPDATE_LOGIN", type: "BIGINT", defaultValue: "-1")
}
}
}
```
**请注意保持脚本格式工整**
## 修改表结构
也是通过添加 changeSet, 顺序添加
修改表结构参考示例:
```groovy
package com.hand.hap.db
import com.hand.hap.liquibase.MigrationHelper
def mhi = MigrationHelper.getInstance()
dbType = MigrationHelper.getInstance().dbType()
databaseChangeLog(logicalFilePath: "patch.groovy") {
changeSet(author: "作者", id: "日期-作者-编号") {
/**
* 新增一列
*/
addColumn(tableName: "SYS_USER") {
column(name: "LAST_LOGIN_DATE", type: "datetime", remarks: "最后一次登录时间")
}
/**
* 修改列名
*/
renameColumn(tableName: "SYS_IF_CONFIG_LINE_TL", columnDataType: "VARCHAR(255)", oldColumnName: "HEADER_ID", newColumnName: "LINE_ID")
/**
* 添加唯一约束
*/
addUniqueConstraint(tableName: "SYS_IF_CONFIG_HEADER_B", columnNames: "INTERFACE_CODE", constraintName: "SYS_IF_CONFIG_HEADER_U1")
/**
* 添加默认值
*/
addDefaultValue(tableName: "SYS_USER", columnName: "FIRST_LOGIN", columnDataType: "varchar", defaultValue: "Y")
/**
* 添加索引
*/
createIndex(tableName: "SYS_RESOURCE_B", indexName: "SYS_RESOURCE_B_N1") {
column(name: "TYPE", type: "varchar(15)")
}
/**
* 可以使用groovy语句进行条件判断
* 修改数据类型
*/
if (true) {
modifyDataType(tableName: "FND_COMPANY_B", columnName: "COMPANY_FULL_NAME", newDataType: "varchar(250)")
}
}
}
```
## 初始数据
......@@ -135,6 +224,6 @@ patch.groovy 中即可以写 liquibase 命令, 也可以执行 sql 语句.
编写完毕以后,将补丁配置到 patch.groovy 中。
> 补丁将会是用的比较多的方式,主要是增加新的数据,由于主键是手动指定的,请注意不要与他人的重复,必须在本地测试过之后再commit。
*补丁数据的脚本编写可参考修改数据库的脚本*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment