首页 > 其他分享 >groovy语法

groovy语法

时间:2024-03-13 22:15:13浏览次数:29  
标签:groovy changeSet tlberglund author tableName 语法 schemaName id

/*
 * Copyright 2011-2014 Tim Berglund and Steven C. Saliman
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

databaseChangeLog(logicalFilePath: '') {
  
  preConditions(onFail: 'WARN') {
    and {
      dbms(type: 'mysql')
      runningAs(username: 'root')
      or {
        changeSetExecuted(id: '', author: '', changeLogFile: '')
        columnExists(schemaName: '', tableName: '', columnName: '')
        tableExists(schemaName: '', tableName: '')
        viewExists(schemaName: '', viewName: '')
        foreignKeyConstraintExists(schemaName: '', foreignKeyName: '')
        indexExists(schemaName: '', indexName: '')
        sequenceExists(schemaName: '', sequenceName: '')
        primaryKeyExists(schemaName: '', primaryKeyName: '', tableName: '')
        sqlCheck(expectedResult: '') {
          "SELECT COUNT(1) FROM monkey WHERE status='angry'"
        }
        customPrecondition(className: '') {
          tableName('our_table')
          count(42)
        }
      }
    }
  }

  include(file: '', relative: true)
  
  //TODO figure out what properties are all about
  clobType = 0

  changeSet(id: '', author: '', dbms: '', runAlways: true, runOnChange: false, context: '', runInTransaction: true, failOnError: false) {
    // Comments supported through Groovy
    comment "Liquibase can be aware of this comment"

    preConditions {
      // just like changelog preconditions
    }
    
    validCheckSum 'd0763edaa9d9bd2a9516280e9044d885'
    
    // If rollback takes a string, it's just the SQL to execute
    rollback "DROP TABLE monkey_table"
    rollback """
      UPDATE monkey_table SET emotion='angry' WHERE status='PENDING';
      ALTER TABLE monkey_table DROP COLUMN angry;
    """
    
    // If rollback takes a closure, it's more Liquibase builder (a changeSet?)
    rollback {
      dropTable(tableName: 'monkey_table')
    }
    
    // If rollback takes a map, it identifies the changeset to re-run to do the rollback (this file assumed)
    rollback(changeSetId: '', changeSetAuthor: '')
    
  }
  
  
  changeSet(id: 'add-column', author: 'tlberglund') {
    addColumn(tableName: '', schemaName: '') {
      column(name: '', type: '', value: '', defaultValue: '', autoIncrement: false, remarks: '') {
        
        // Seems like you should have two ways of representing constraints
        
        // Pass a closure
        constraints {
          nullable(false)//
          primaryKey(true)//
          unique(true)
          uniqueConstraintName('make_it_unique_yo')
          foreignKeyName('key_to_monkey')//
          references('monkey_table')//
          deleteCascade(true)//
          deferrable(true)
          initiallyDeferred(false)
        }
        
        // Or pass a map
        // Can put all constraints in one call, or split them up as shown
        constraints(nullable: false, primaryKey: true)
        constraints(unique: true, uniqueConstraintName: 'make_it_unique_yo')
        constraints(foreignKeyName: 'key_to_monkey', references: 'monkey_table')
        constraints(deleteCascase: true)
        constraints(deferrable: true, initiallyDeferred: false)
      }
      

      // Examples of other value types (only one would apply inside addColumn)
      column(name: '', type: '', valueNumeric: '', defaultValueNumeric: '')
      column(name: '', type: '', valueBoolean: '', defaultValueBoolean: '')
      column(name: '', type: '', valueDate: '', defaultValueDate: '')
    }
  }
  
  
  changeSet(id: 'rename-column', author: 'tlberglund') {
    renameColumn(schemaName: '', tableName: '', oldColumnName: '', newColumnName: '', columnDataType: '')
  }
  
  
  changeSet(id: 'modify-column', author: 'tlberglund') {
    modifyColumn(schemaName: '', tableName: '') {
      column() { }
    }
  }
  
  
  changeSet(id: 'drop-column', author: 'tlberglund') {
    dropColumn(schemaName: '', tableName: '', columnName: '')
  }
  
  
  changeSet(id: 'alter-sequence', author: 'tlberglund') {
    alterSequence(sequenceName: '', incrementBy: '')
  }
  
  
  changeSet(id: 'create-table', author: 'tlberglund') {
    createTable(schemaName: '', tablespace: '', tableName: '', remarks: '') {
      column() {}
      column() {}
      column() {}
      column() {}
    }
  }
  
  
  changeSet(id: 'rename-table', author: 'tlberglund') {
    renameTable(schemaName: '', oldTableName: '', newTableName: '')
  }
  
  
  changeSet(id: 'drop-table', author: 'tlberglund') {
    dropTable(schemaName: '', tableName: '')
  }
  
  
  changeSet(id: 'create-view', author: 'tlberglund') {
    createView(schemaName: '', viewName: '', replaceIfExists: true) {
      "SELECT id, emotion FROM monkey"
    }
  }
  
  
  changeSet(id: 'rename-view', author: 'tlberglund') {
    renameView(schemaName: '', oldViewName: '', newViewName: '')
  }
  
  
  changeSet(id: 'drop-view', author: 'tlberglund') {
    dropView(schemaName: '', viewName: '')
  }
  
  
  changeSet(id: 'merge-columns', author: 'tlberglund') {
    mergeColumns(schemaName: '', tableName: '', column1Name: '', column2Name: '', finalColumnName: '', finalColumnType: '', joinString: ' ')
  }
  
  
  changeSet(id: 'create-stored-proc', author: 'tlberglund') {
    createStoredProcedure """
      CREATE OR REPLACE PROCEDURE testMonkey
      IS
      BEGIN
       -- do something with the monkey
      END;
    """
  }
  
  
  changeSet(id: 'add-lookup-table', author: 'tlberglund') {
    addLookupTable(existingTableName: '', existingColumnName: '', newTableName: '', newColumnName: '', constraintName: '')
  }
  
  
  changeSet(id: 'add-not-null-constraint', author: 'tlberglund') {
    addNotNullConstraint(tableName: '', columnName: '', defaultNullValue: '')
  }
  
  
  changeSet(id: 'drop-not-null-constraint', author: 'tlberglund') {
    dropNotNullConstraint(schemaName: '', tableName: '', columnName: '', columnDataType: '')
  }
  
  
  changeSet(id: 'add-unique-constraint', author: 'tlberglund') {
    addUniqueConstraint(tableName: '', columnNames: '', constraintName: '')
  }
  
  
  changeSet(id: 'drop-unique-constraint', author: 'tlberglund') {
    dropUniqueConstraint(schemaName: '', tableName: '', constraintName: '')
  }
  
  
  changeSet(id: 'create-sequence', author: 'tlberglund') {
    createSequence(sequenceName: '', schemaName: '', incrementBy: '', minValue: '', maxValue: '', ordered: true, startValue: '')
  }
  
  
  changeSet(id: 'drop-sequence', author: 'tlberglund') {
    dropSequence(sequenceName: '')
  }
  
  
  changeSet(id: 'add-auto-increment', author: 'tlberglund') {
    addAutoIncrement(schemaName: '', tableName: '', columnName: '', columnDataType: '')
  }
  
  
  changeSet(id: 'add-default-value', author: 'tlberglund') {
    addDefaultValue(schemaName: '', tableName: '', columnName: '', defaultValue: '')
    addDefaultValue(schemaName: '', tableName: '', columnName: '', defaultValueNumeric: '')
    addDefaultValue(schemaName: '', tableName: '', columnName: '', defaultValueBoolean: '')
    addDefaultValue(schemaName: '', tableName: '', columnName: '', defaultValueDate: '')
  }
  
  
  changeSet(id: 'drop-default-value', author: 'tlberglund') {
    dropDefaultValue(schemaName: '', tableName: '', columnName: '')
  }
  
  
  changeSet(id: 'add-foreign-key-constraint', author: 'tlberglund') {
    addForeignKeyConstraint(constraintName: '', 
                            baseTableName: '', baseTableSchemaName: '', baseColumnNames: '',
                            referencedTableName: '', referencedTableSchemaName: '', referencedColumnNames: '',
                            deferrable: true,
                            initiallyDeferred: false,
                            deleteCascase: true,
                            onDelete: 'CASCADE|SET NULL|SET DEFAULT|RESTRICT|NO ACTION',
                            onUpdate: 'CASCADE|SET NULL|SET DEFAULT|RESTRICT|NO ACTION')
  }
  
  
  changeSet(id: 'drop-foreign-key', author: 'tlberglund') {
    dropForeignKeyConstraint(constraintName: '', baseTableName: '', baseTableSchemaName: '')
  }
  
  
  changeSet(id: 'add-primary-key', author: 'tlberglund') {
    addPrimaryKey(schemaName: '', tablespace: '', tableName: '', columnNames: '', constraintName: '')
  }
  
  
  changeSet(id: 'drop-primary-key', author: 'tlberglund') {
    dropPrimaryKey(schemaName: '', tableName: '', constraintName: '')
  }
  
  
  changeSet(id: 'insert-data', author: 'tlberglund') {
    insert(schemaName: '', tableName: '') {
      column(name: '', value: '')
      column(name: '', valueNumeric: '')
      column(name: '', valueDate: '')
      column(name: '', valueBoolean: '')
    }
  }
  
  
  changeSet(id: 'load-data', author: 'tlberglund') {
    loadData(schemaName: '', tableName: '', file: '', encoding: 'UTF8|etc') {
      column(name: '', index: 2, type: 'NUMERIC')
      column(name: '', index: 3, type: 'BOOLEAN')
      column(name: '', header: 'shipDate', type: 'DATE')
      column(name: '', index: 5, type: 'STRING')
    }
  }
  
  
  changeSet(id: 'load-update-data', author: 'tlberglund') {
    loadUpdateData(schemaName: '', tableName: '', primaryKey: '', file: '', encoding: '') {
      column(name: '', index: 2, type: 'NUMERIC')
      column(name: '', index: 3, type: 'BOOLEAN')
      column(name: '', header: 'shipDate', type: 'DATE')
      column(name: '', index: 5, type: 'STRING')
    }
  }
  
  
  changeSet(id: 'update', author: 'tlberglund') {
    update(schemaName: '', tableName: '') {
      column(name: '', value: '')
      column(name: '', valueNumeric: '')
      column(name: '', valueDate: '')
      column(name: '', valueBoolean: '')
      where "species='monkey' AND status='angry'"
    }
  }
  
  
  changeSet(id: 'delete-data', author: 'tlberglund') {
    delete(schemaName: '', tableName: '') {
        where "id=39" // optional
    }
  }
  
  
  changeSet(id: 'tag', author: 'tlberglund') {
    tagDatabase(tag: 'monkey')
  }
  
  
  changeSet(id: 'stop', author: 'tlberglund') {
    stop('Migration stopped because something bad went down')
  }
  
  
  changeSet(id: 'create-index', author: 'tlberglund') {
    createIndex(schemaName: '', tablespace: '', tableName: '', indexName: '', unique: true) {
      column(name: '')
      column(name: '')
      column(name: '')
    }
  }
  
  
  changeSet(id: 'drop-index', author: 'tlberglund') {
    dropIndex(tableName: '', indexName: '')
  }
  
  
  changeSet(id: 'custom-sql', author: 'tlberglund') {
    sql(stripComments: true, splitStatements: false, endDelimiter: ';') {
      "INSERT INTO ANIMALS (id, species, status) VALUES (1, 'monkey', 'angry')"
    }
  }
  
  
  changeSet(id: 'sql-file', author: 'tlberglund') {
    sqlFile(path: '', stripComments: true, splitStatements: '', encoding: '', endDelimiter: '')
  }
  
  
  changeSet(id: 'custom-refactoring', author: 'tlberglund') {
    customChange(class: 'net.saliman.liquibase.MonkeyRefactoring') {
      tableName('animal')
      species('monkey')
      status('angry')
    }
  }
  
  
  changeSet(id: 'shell-command', author: 'tlberglund') {
    executeCommand(executable: '') {
      arg('--monkey')
      arg('--skip:1')
    }
  }
    
}

标签:groovy,changeSet,tlberglund,author,tableName,语法,schemaName,id
From: https://www.cnblogs.com/luolin-cn/p/18071649

相关文章

  • groovy-test
    /**Copyright2011-2014TimBerglundandStevenC.Saliman**LicensedundertheApacheLicense,Version2.0(the"License");*youmaynotusethisfileexceptincompliancewiththeLicense.*YoumayobtainacopyoftheLicenseat......
  • 编写Makefile文件语法,持续更新中~
    一、什么是Makefile?我们写大型项目时,会用到很多源文件,源文件在不同目录中的文件夹里包含着,一个一个编译起来很麻烦,makefile就能够方便我们编译链接。使用makefile进行编译连接时会用到make命令,Makefile的会在执行make命令时指定编译和链接的规则,包括源代码文件之间的链接......
  • 使用IDEA+groovy快速生成entity、dto、dao、service、serviceImpl
    groovy代码importcom.intellij.database.model.DasTableimportcom.intellij.database.util.Caseimportcom.intellij.database.util.DasUtilimportjava.text.SimpleDateFormat/**Availablecontextbindings:*SELECTIONIterable<DasObject>*PROJ......
  • c++基础语法
    文章目录前言命名空间命名空间的使用缺省参数缺省参数的使用函数重载函数重载的作用函数重载的使用函数重载原理引用引用的使用引用的使用场景引用和指针externCinlineauto范围fornullptr前言大家好我是jiantaoyab,这篇文章给大家带来的是c语言没有的一些特性之......
  • C语言救赎之路,有些鸟儿是困不住的(其三)。main+头文件+分支和循环语句(基本语法)
    前言:              在将之前先给大家分享个好玩的,这是我今天在课上的发生的。       今天老师在讲java与C语言主函数的都是什么开始的,老师让我们回答,不就是main吗?我突然想到什么?main?main?卧槽牢大!man!一口流利的洛杉矶口音的man随口而出。引来大家的wha......
  • springboot-yaml语法
    SpringBoot使用一个全局的配置文件,配置文件名称是固定的application.properties语法结构:key=valueserver.port=8080application.yml语法结构:key:空格value普通的key-valueserver:port:8080yaml后缀配置可以存储对象,而properties只能保存键值对yaml不仅可以用来......
  • MYSQL语法:左连接、右连接、内连接、全外连接
    概念leftjoin(左连接):返回包括左表中的所有记录和右表中连接字段相等的记录。rightjoin(右连接):返回包括右表中的所有记录和左表中连接字段相等的记录。innerjoin(内连接):只返回两个表中连接字段相等的行。fulljoin(全外连接):返回左右表中所有的记录和左右表中连接字段相等的记录......
  • yaml语法
    1、yaml复杂结构如下。在线转换网站https://tool.ip138.com/yamljson/env:-name:PROVISIONER_NAMEvalue:k8s-sigs.io/nfs-subdir-external-provisioner-name:NFS_SERVERvalue:192.168.10.94-name:NFS_PATHvalue:/data/nfs/auto......
  • Django模板语法
    Django模版语法(1)传数据模版语法可以传递的后端python数据类型(可迭代)后端:deftest2(request):name='heart'float=11.11str_name='你好'boolean_test=Truelist_test=[1,2,3]tuple_test=(1,2,3)dict_test={'name�......
  • 第六十九天 BBS项目之五 js与模板语法 inclusion_tag实操,文章详情,点赞点踩
    一、昨日内容回顾#1首页文章的渲染 -模板语法的for循环-bootstrap的媒体组-显示头像:articel.blog.userinfo有可能没有:在admin中建立关系 -注册---》申请开启博客功能-图标库 -font-awesome-4.7.0#2个人站点样式 -头部导航栏-......