美文网首页
HAP_数据库结构初始化

HAP_数据库结构初始化

作者: 灯下驼贼 | 来源:发表于2018-08-02 19:05 被阅读0次

    数据库结构初始化

    • 新建脚本:


      image.png
    image.png
    • 重新打包项目:
      方法一:在idea或者项目文件夹下命令运行:maven clean install
      方法二:
      image.png
    • 初始化数据库:
      去到项目文件夹下运行:
    mvn process-resources -D skipLiquibaseRun=false -D db.driver=com.mysql.jdbc.Driver -D db.url=jdbc:[mysql://localhost:3306/wht_dev](mysql://localhost:3306/wht_dev) -D db.user=root -D db.password=root -D db.skipUpdateTables="sys_config,sys_user"
    
    

    如果运行上面的代码,然后也运行成功了,但是表没出来,可能项目打包没成功或者没更新成功,这是我遇到的一个问题,然后我去文件夹下运行打包命令mvn clean install,如果运行这个命令出现说找不到jdk的话,你要去看一下你的环境变量配置,把jdk那些环境变量移到最上面。

    image.png
    如去到你数据库就发现一张WHT_20796_DEMO

    多张表一起建:
    道理同上:脚本代码如下:

    package wht.core.db
    
    
    import com.hand.hap.liquibase.MigrationHelper
    
    def mhi = MigrationHelper.getInstance()
    
    databaseChangeLog(logicalFilePath:"wht/core/db/2018-08-01-02-init-migration.groovy"){
    
    
        changeSet(author: "20796", id: "20180801-ora-20796csz-2") {
    
            if(mhi.isDbType('oracle')){
                createSequence(sequenceName: 'WHT_20796_DEMO_S')
            }
    
            createTable(tableName: "WHT_20796_DEMO_B") {
                column(autoIncrement: "true", name: "id", type: "BIGINT") {
                    constraints(nullable: "false", primaryKey: "true")
                }
                column(name: "desc", type: "VARCHAR(100)") {
                }
                column(name: "name", type: "VARCHAR(100)") {
                }
    
                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")
    
            }
            createTable(tableName: "WHT_20796_DEMO_TL") {
                column(name: "id", type: "BIGINT") {
                    constraints(nullable: "false", primaryKey: "true")
                }
                column(name:"LANG",type:"VARCHAR(50)"){
                    constraints(nullable:"false",primaryKey: "true")
    
                }
                column(name: "desc", type: "VARCHAR(100)") {
                }
                column(name: "name", type: "VARCHAR(100)") {
                }
    
                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")
    
            }
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:HAP_数据库结构初始化

          本文链接:https://www.haomeiwen.com/subject/engrvftx.html