GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ben-manes/gradle-flyway-plugin: Flyway database migration tasks for Gradle (deprecated)

This repository was archived by the owner on Apr 17, 2022. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

33 Commits
33 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
gradle/wrapper
gradle/wrapper
 
 
src/main
src/main
 
 
.gitignore
.gitignore
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

Gradle Flyway Plugin (deprecated)

Flyway database migration tasks for Gradle.

Flyway v2.2 includes an [official plugin](http://flywaydb.org/documentation/gradle) based on this one. Note that the feature set diverged after contributing, e.g. removal of multi-db support.

Usage

This plugin is hosted on the Maven Central Repository. All actions are logged at the info level.

See Flyway's command-line arguments for the configuration reference. If the locations configuration is not set and the java plugin is detected then setting is defaulted to the sourceSets.main.output.resourcesDir. If compiled classes are detected then the sourceSets.main.output.classesDir are added to the classpath and classpath:db/migration added to the default locations.

The flyway tasks may include Java migrations. This requires that the classes are compiled in a dependent task. The dependsOnTasks configuration acts as a dependsOn relationship that applies to all flyway tasks. This relationship is not required to allow for the inverse relationship, such as for code generating from the schema. See the gradle-jooq-plugin for one such example.

For a single-database environment, only a single database extension needs to be used. For an environment where deployments to multiple databases must be run as part of the release, defaults can be used in addition to databases. For lists, such as schemas and placeholders, the list that appears in both extensions will be combined. In all other cases, values specified in databases will take precedence over values in defaults.

apply plugin: 'flyway'

buildscript {
  repositories {
    mavenCentral()
  }

  dependencies {
    classpath 'com.h2database:h2:1.3.170'
    classpath 'com.github.ben-manes:gradle-flyway-plugin:0.7'
  }
}

flyway {
  databases {
    main {
      url = "jdbc:h2:${buildDir}/db/flyway"
    }
  }
}

Tasks

flywayClean

Drops all objects in the configured schemas.

flywayInit

Creates and initializes the metadata table in the schema.

flywayMigrate

Migrates the schema to the latest version.

flywayValidate

Validates the applied migrations against the ones available on the classpath.

flywayInfo

Prints the details and status information about all the migrations.

flywayRepair

Repairs the Flyway metadata table after a failed migration.

Sample for Single Database

flyway {
  dependsOnTasks(compileJava)
  databases {
    main {
      url = "jdbc:h2:${buildDir}/db/flyway"    
      driver = 'org.h2.Driver'
      user = 'SA'
      password = 'mySecretPwd'
      table = 'schema_history'
      schemas = [ 'schema1', 'schema2', 'schema3' ]
      initVersion = '1.0'
      initDescription = 'Base Migration'
      locations = [
        'classpath:com.mycompany.project.migration',
        'filesystem:/sql-migrations',
        'database/migrations'
      ]
      sqlMigrationPrefix = 'Migration-'
      sqlMigrationSuffix = '-OK.sql'
      encoding = 'ISO-8859-1'
      placeholders = [ 
        'aplaceholder': 'value',
        'otherplaceholder': 'value123'
      ]
      placeholderPrefix = '#['
      placeholderSuffix = ']'
      target = '5.1'
      outOfOrder = false
      validateOnMigrate = true
      cleanOnValidationError = false
      initOnMigrate = false
    }
  }
}

Sample for Multiple Databases

flyway {
  dependsOnTasks(compileJava)
  schemaDefaultFirst = true
  defaults {  
    driver = 'org.h2.Driver'
    user = 'SA'
    password = 'mySecretPwd'
    table = 'schema_history'
    schemas = [ 'schema1', 'schema2', 'schema3' ]
    initVersion = '1.0'
    initDescription = 'Base Migration'
    locations = [
      'classpath:com.mycompany.project.migration',
      'filesystem:/sql-migrations',
      'database/migrations'
    ]
    encoding = 'ISO-8859-1'
    placeholderPrefix = '#['
    placeholderSuffix = ']'
    target = '5.1'
    outOfOrder = false
    validateOnMigrate = true
    cleanOnValidationError = false
    initOnMigrate = false
    placeholders = [ 'aplaceholder': 'value' ]
  }
  databases {
    transactional {
      url = "jdbc:h2:${buildDir}/db/flyway/transaction" 
      sqlMigrationPrefix = 'Transaction-'
      sqlMigrationSuffix = '-OK.sql'
      placeholders = [ 'otherplaceholder': 'value123'
      schemas = [ 'schema4', 'schema5' ]
    }
    reporting {
      url = "jdbc:h2:${buildDir}/db/flyway/report" 
      sqlMigrationPrefix = 'Reporting-'
      sqlMigrationSuffix = '-OK.sql'
      placeholders = [ 'otherplaceholder': 'value456' ]
      schemas = [ 'schema6', 'schema7' ]
    }
  }
}

About

Flyway database migration tasks for Gradle (deprecated)

Resources

Readme
Apache-2.0 license
Activity

Stars

13 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.