• 初始化数据库

    CREATE USER 'hapdemo'@'%' IDENTIFIED BY "handhand";
    CREATE DATABASE hap_demo_service_todo DEFAULT CHARACTER SET utf8;
    GRANT ALL PRIVILEGES ON hap_demo_service_todo.* TO hapdemo@'%';
    FLUSH PRIVILEGES;
    
    #!/usr/bin/env bash
    
    # 获取初始化数据库的jar包
    mkdir -p target
    
    if [ ! -f target/hap-liquibase-tools.jar ]
    then
        curl http://nexus.saas.hand-china.com/content/repositories/rdc/com/hand/hap/cloud/hap-liquibase-tools/1.0/hap-liquibase-tools-1.0.jar -o target/hap-liquibase-tools.jar
    fi
    
    # 初始化项目数据库
    java -Dspring.datasource.url="jdbc:mysql://localhost:3306/hap_demo_service_todo?useUnicode=true&characterEncoding=utf-8&useSSL=false" \
        -Dspring.datasource.username=hapdemo \
        -Dspring.datasource.password=handhand \
        -Ddata.init=true -Ddata.drop=true \
        -Ddata.dir=hap-todo-service/src/main/resources \
        -jar target/hap-liquibase-tools.jar
    
    # 追加项目数据信息到hap-user-service数据库中
    java -Dspring.datasource.url="jdbc:mysql://localhost:3306/hap_user_service?useUnicode=true&characterEncoding=utf-8&useSSL=false" \
        -Dspring.datasource.username=hapcloud \
        -Dspring.datasource.password=handhand \
        -Ddata.init=true \
        -Ddata.dir=hap-user-service-db \
        -jar target/hap-liquibase-tools.jar
    
    package db
    
    databaseChangeLog(logicalFilePath: '2017-05-11-demo.groovy') {
        changeSet(id: '2017-05-29-todo', author: 'zhuang.chang@hand-china.com') {
            createTable(tableName: "todo_user") {
                column(name: 'id', type: 'BIGINT UNSIGNED', remarks: 'ID', autoIncrement: true) {
                    constraints(primaryKey: true)
                }
                column(name: 'employee_name', type: 'VARCHAR(32)', remarks: '员工名')
                column(name: 'employee_number', type: 'VARCHAR(32)', remarks: '员工号') {
                    constraints(unique: true)
                }
                column(name: 'email', type: 'VARCHAR(32)', remarks: '邮箱')
    
                column(name: "OBJECT_VERSION_NUMBER", 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")
            }
            createTable(tableName: "todo_task") {
                column(name: 'id', type: 'BIGINT UNSIGNED', remarks: 'ID', autoIncrement: true) {
                    constraints(primaryKey: true)
                }
                column(name: 'employee_id', type: 'BIGINT', remarks: '员工ID')
                column(name: 'state', type: 'VARCHAR(36)', remarks: '状态')
                column(name: 'task_number', type: 'VARCHAR(64)', remarks: '任务编号') {
                    constraints(unique: true)
                }
                column(name: 'task_description', type: 'VARCHAR(256)', remarks: '任务编号')
    
                column(name: "OBJECT_VERSION_NUMBER", 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")
            }
            createTable(tableName: "todo_swimlane") {
                column(name: 'id', type: 'BIGINT UNSIGNED', remarks: 'ID', autoIncrement: true) {
                    constraints(primaryKey: true)
                }
                column(name: 'state', type: 'VARCHAR(36)', remarks: '状态') {
                    constraints(unique: true)
                }
                column(name: 'next_state', type: 'VARCHAR(36)', remarks: '下一状态')
            }
        }
    }