首页 > 其他分享 >groovy-test

groovy-test

时间:2024-03-13 22:14:54浏览次数:26  
标签:groovy changeSet tlberglund author tableName test 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,test,schemaName,id
From: https://www.cnblogs.com/luolin-cn/p/18071648

相关文章

  • pytest-参数request的使用
    如果想把登录操作放到前置操作里,也就是用到@pytest.fixture装饰器,传参就用默认的request参数user=request.param这一步是接收传入的参数,下面演示一个参数的情况  那当request传递两个参数的时候,如果用到@pytest.fixture,里面用2个参数情况,可以把多个参数用一个字典去存储,这......
  • pytest测试框架基本使用
    一、pytest测试框架简介pytest是Python中的单元测试框架1、pytest特点:。容易上手,入门简单,丰富的文档资料,文档中有很多实例可进行参考。支持参数化。执行用例过程中可以进行标记跳过用例,标记失败用例。支持重复执行失败的用例。具有很多的第三方插件,并且可以实现自定义......
  • AtCoder Grand Contest 022 E Median Replace
    洛谷传送门AtCoder传送门考虑对于一个确定的串怎么判断合法性。容易发现删到某个时刻若\(1\)的个数大于\(0\)的个数了,因为我们肯定不会蠢到在不是全\(1\)的时候删\(111\),所以\(c_1-c_0\)在不是全\(1\)的时候至少是不会变小的。所以我们的目标就是让\(c_1-c_0......
  • 【自动化测试入门】用Airtest - Selenium对Firefox进行自动化测试(0基础也能学会)
    1.前言本文将详细介绍如何使用AirtestIDE驱动Firefox测试,以及脱离AirtestIDE怎么驱动Firefox(VScode为例)。看完本文零基础小白也能学会Firefox浏览器自动化测试!!!2.如何使用AirtestIDE驱动Firefox浏览器对于Web自动化测试,目前AirtestIDE支持chrome浏览器和Firefox2种浏览器,今天......
  • 使用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......
  • Dwango Programming Contest 6th D 题解
    正好测试一下专栏的题解系统。我省选寄了都怪洛谷/fn/fn/fn/fn/fn/fn/fn题解显然可以对于所有关系建有向边,显然是基环外向树森林。由于是字典序最小,因此找到最小的上一个点没有直接连向边的点一定最优。但是有时取最优会导致最后无法选完,我们考虑无法选完的情况。第一种是......
  • linux Shell 命令行-05-test 检查某个条件是否成立
    拓展阅读linuxShell命令行-00-intro入门介绍linuxShell命令行-02-var变量linuxShell命令行-03-array数组linuxShell命令行-04-operator操作符linuxShell命令行-05-test验证是否符合条件linuxShell命令行-06-flowcontrol流程控制linuxShell命令行-07-f......
  • AtCoder Beginner Contest 344 A-G 题解
    AtCoderBeginnerContest344A-SpoilerQuestion删除两个|之间的字符Solution按照题意模拟即可Code#include<bits/stdc++.h>usingnamespacestd;intmain(){strings;cin>>s;stringp1,p2;for(inti=0;i<s.size();i++){......
  • Toyota Programming Contest 2024#3(AtCoder Beginner Contest 344)
    C先预处理出三个数组能拼出的数,存放到map中。查询的时候只需要看这个数是否出现在map里即可。时间复杂度\(O(n^3\logv+Q\logv)\),\(n\leq100\),\(\logv\)是map的时间复杂度。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=3e......
  • The Best Car Diagnostic Tool Among Diagnostic and Testing Tools
    Inthismodernera,carshavebecomeanessentialpartofourlives.However,likeanyothermachine,theyarepronetobreakdownsandmalfunctions.Whenfacedwithcartroubles,itiscrucialtohavetherightdiagnosticandtestingtoolsatyourdisposa......