0.3.2 • Published 8 years ago

grunt-flyway v0.3.2

Weekly downloads
347
License
-
Repository
github
Last release
8 years ago

grunt-flyway

Run Flyway database migration tool with Grunt.

WARNING

This Grunt plugin and has not been tested thoroughly yet so use it at your own risk!

The plugin supports all Flyway configuration options for clean, baseline, migrate, repair, validate and info commands.

Getting Started

Installing the plugin

This plugin requires Grunt ~0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-flyway --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-flyway');

Installing Java

The plugin uses Flyway "The Agile Database Migration Framework" which is developed in Java.

So, you have to install Java and have the java executable available in your PATH.

Flyway version

The plugin uses Flyway 3.2.

The "flyway" task

Overview

In your project's Gruntfile, add a section named flyway to the data object passed into grunt.initConfig().

grunt.initConfig({
  flyway: {
    options: {
      driver: 'com.mysql.jdbc.Driver',
      url: 'jdbc:mysql://localhost/flyway',
      user: 'flyway',
      password: 'flyway'
    },
    clean: {
      command: 'clean'
    },
    baseline: {
      options: {
        baselineDescription: 'Sample database created using Flyway:-)',
        baselineVersion: '1.0'
      },
      command: 'baseline'
    },
    migrate: {
      options: {
        locations: 'filesystem:src/main/resources/sql/migration'
      },
      command: 'migrate'
    }
  }
})

The name of the Grunt targets to use inside the flyway task configuration are not pre-defined, you can choose what you want to name those targets.

Any number of targets can be defined and you can have multiple targets with different configurations, for example:

grunt.initConfig({
  flyway: {
    options: {
      driver: 'com.mysql.jdbc.Driver',
      url: 'jdbc:mysql://localhost/db1',
      user: 'flyway',
      password: 'flyway'
    },
    clean_db1: {
      command: 'clean'
    },
    clean_db2: {
      options {
        url: 'jdbc:mysql://localhost/db2'
      },
      command: 'clean',
    },
    baseline_db1: {
      options: {
        baselineDescription: 'Sample database created using Flyway:-)',
        baselineVersion: '1.0'
      },
      command: 'baseline'
    },
    baseline_db2: {
      options {
        url: 'jdbc:mysql://localhost/db2',
        baselineDescription: 'Sample database created using Flyway:-)',
        baselineVersion: '1.0'
      },
      command: 'baseline'
    },
    migrate_db1: {
      options: {
        locations: 'filesystem:src/main/resources/sql/migration'
      },
      command: 'migrate'
    },
    migrate_db2: {
      options {
        url: 'jdbc:mysql://localhost/db2',
        locations: 'filesystem:src/main/resources/sql/migration',
        placeholders: {
          name: 'Tom'
        }
      },
      command: 'migrate'
    }
  }
})

The only commands which are supported for the moment are clean, baseline, migrate, repair, validate and info.

Options

Options' descriptions come from Flyway's documentation.

NOTE: These options may be out of sync with the official documentation. Please only use this version as a basic reference and consult the official docs for accurate information.

clean

optionrequireddefaultdescription
urlyesThe jdbc url to use to connect to the database
drivernoAuto-detected based on urlThe fully qualified classname of the jdbc driver to use to connect to the database
usernoThe user to use to connect to the database
passwordnoThe password to use to connect to the database
schemasnodefault schema of the connectionComma-separated case-sensitive list of schemas managed by Flyway. The schemas will be cleaned in the order of this list.
jarDirno<install-dir>/jarsThe directory containing the JDBC driver

baseline

optionrequireddefaultdescription
urlyesThe jdbc url to use to connect to the database
drivernoAuto-detected based on urlThe fully qualified classname of the jdbc driver to use to connect to the database
usernoThe user to use to connect to the database
passwordnoThe password to use to connect to the database
schemasnodefault schema of the connectionComma-separated case-sensitive list of schemas managed by Flyway. The first schema will be the one containing the metadata table.
tablenoschema_versionThe name of Flyway's metadata table. By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the datasource. When the schemas property is set (multi-schema mode), the metadata table is placed in the first schema of the list.
jarDirno<install-dir>/jarsThe directory containing the JDBC driver
baselineVersionno1The initial version to put in the database
baselineDescriptionno<< Flyway Baseline >>The description of the initial version

migrate

optionrequireddefaultdescription
urlyesThe jdbc url to use to connect to the database
drivernoAuto-detected based on urlThe fully qualified classname of the jdbc driver to use to connect to the database
usernoThe user to use to connect to the database
passwordnoThe password to use to connect to the database
schemasnodefault schema of the connectionComma-separated case-sensitive list of schemas managed by Flyway. The first schema in the list will be automatically set as the default one during the migration. It will also be the one containing the metadata table.
tablenoschema_versionThe name of Flyway's metadata table. By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the datasource. When the schemas property is set (multi-schema mode), the metadata table is placed in the first schema of the list.
locationsnofilesystem:<install-dir>/sqlComma-separated list of locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both sql and java-based migrations. Locations starting with filesystem: point to a directory on the filesystem and may only contain sql migrations.
jarDirno<install-dir>/jarsThe directory containing the JDBC driver
sqlMigrationPrefixnoVThe file name prefix for sql migrations
sqlMigrationSuffixno.sqlThe file name suffix for sql migrations
encodingnoUTF-8The encoding of sql migrations
placeholders.namenoPlaceholders to replace in sql migrations
placeholderPrefixno${The prefix of every placeholder
placeholderSuffixno}The suffix of every placeholder
targetnolatest versionThe target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.
outOfOrdernofalseAllows migrations to be run "out of order". If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored.
validateOnMigratenofalseWhether to automatically call validate or not when running migrate. For each sql migration a CRC32 checksum is calculated when the sql script is executed. The validate mechanism checks if the sql migration in the classpath still has the same checksum as the sql migration already executed in the database.
cleanOnValidationErrornofalseWhether to automatically call clean or not when a validation error occurs. This is exclusively intended as a convenience for development. Even tough we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM. Warning! Do not enable in production!
baselineOnMigratenofalseWhether to automatically call baseline when migrate is executed against a non-empty schema with no metadata table. This schema will then be initialized with the baselineVersion before executing the migrations. Only migrations above baselineVersion will then be applied. This is useful for initial Flyway production deployments on projects with an existing DB. Be careful when enabling this as it removes the safety net that ensures Flyway does not migrate the wrong database in case of a configuration mistake!
baselineVersionno1The initial version to put in the database
baselineDescriptionno<< Flyway Baseline >>The description of the initial version

validate

optionrequireddefaultdescription
urlyesThe jdbc url to use to connect to the database
drivernoAuto-detected based on urlThe fully qualified classname of the jdbc driver to use to connect to the database
usernoThe user to use to connect to the database
passwordnoThe password to use to connect to the database
schemasnodefault schema of the connectionComma-separated case-sensitive list of schemas managed by Flyway. The first schema will be the one containing the metadata table.
tablenoschema_versionThe name of Flyway's metadata table. By default (single-schema mode) the metadata table is placed in the default schema for the connection provided by the datasource. When the schemas property is set (multi-schema mode), the metadata table is placed in the first schema of the list.
locationsnofilesystem:<install-dir>/sqlComma-separated list of locations to scan recursively for migrations. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both sql and java-based migrations. Locations starting with filesystem: point to a directory on the filesystem and may only contain sql migrations.
jarDirno<install-dir>/jarsThe directory containing the JDBC driver
sqlMigrationPrefixnoVThe file name prefix for sql migrations
sqlMigrationSuffixno.sqlThe file name suffix for sql migrations
encodingnoUTF-8The encoding of sql migrations
placeholders.namenoPlaceholders to replace in sql migrations
placeholderPrefixno${The prefix of every placeholder
placeholderSuffixno}The suffix of every placeholder
targetnolatest versionThe target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied.
outOfOrdernofalseAllows migrations to be run "out of order". If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored.
cleanOnValidationErrornofalseWhether to automatically call clean or not when a validation error occurs. This is exclusively intended as a convenience for development. Even tough we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM. Warning! Do not enable in production!

Usage Examples

Simply call the Flyway targets you've defined inside your Gruntfile:

grunt flyway:clean

grunt flyway:baseline

grunt flyway:migrate

grunt flyway:repair

grunt flyway:validate

grunt flyway:info

Release History

0.3.2

  • Upgrade to Flyway 3.2

0.3.0

  • Upgrade to Flyway 3.0

0.2.1

  • Add develop branch has been created, pull request have to be performed on this branch now
  • Upgrade to Flyway 2.3
  • WARNING : The plugin requires requires Grunt ~0.4.2 now

0.2.0

  • Added support for validate command
  • Added support for all options for each supported command
  • Added configuration validation
    • Required options cause an error when not present
    • Any extra option that is not available for selected command also causes an error
  • Fix JSHint Lint errors

0.1.1

  • Fix a Flyway classpath build problem under UNIX. The ';' character was used instead ':'.
0.3.2

8 years ago

0.2.1

10 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago