Database Migration - Flyway

Data System Architecture

Database Migration - Flyway

About

Flyway is a database migration tool.

Structure

Type of script

  • versioned (prefix= 1,2,…)
  • repetable (prefix=R).

State

State by script:

  • pending,
  • outdated,
  • success

Syntax

flyway [options] command

By default, the configuration will be read from conf/flyway.conf.

Options passed from the command-line override the configuration.

Commands:

  • migrate : Migrates the database
  • clean : Drops all objects in the configured schemas
  • info : Prints the information about applied, current and pending migrations
  • validate : Validates the applied migrations against the ones on the classpath
  • undo : Undoes the most recently applied versioned migration
  • baseline : Baselines an existing database at the baselineVersion
  • repair : Repairs the schema history table

Options (Format: -key=value):

  • driver : Fully qualified classname of the JDBC driver
  • url : Jdbc url to use to connect to the database
  • user : User to use to connect to the database
  • password : Password to use to connect to the database
  • schemas : Comma-separated list of the schemas managed by Flyway
  • table : Name of Flyway's schema history table
  • locations : Classpath locations to scan recursively for migrations
  • resolvers : Comma-separated list of custom MigrationResolvers
  • skipDefaultResolvers : Skips default resolvers (jdbc, sql and Spring-jdbc)
  • sqlMigrationPrefix : File name prefix for versioned SQL migrations
  • undoSqlMigrationPrefix : File name prefix for undo SQL migrations
  • repeatableSqlMigrationPrefix : File name prefix for repeatable SQL migrations
  • sqlMigrationSeparator : File name separator for sql migrations
  • sqlMigrationSuffixes : Comma-separated list of file name suffixes for sql migrations
  • mixed : Allow mixing transactional and non-transactional statements
  • encoding : Encoding of sql migrations
  • placeholderReplacement : Whether placeholders should be replaced
  • placeholders : Placeholders to replace in sql migrations
  • placeholderPrefix : Prefix of every placeholder
  • placeholderSuffix : Suffix of every placeholder
  • installedBy : Username that will be recorded in the schema history table
  • target : Target version up to which Flyway should use migrations
  • outOfOrder : Allows migrations to be run “out of order”
  • callbacks : Comma-separated list of FlywayCallback classes
  • skipDefaultCallbacks : Skips default callbacks (sql)
  • validateOnMigrate : Validate when running migrate
  • ignoreMissingMigrations : Allow missing migrations when validating
  • ignoreFutureMigrations : Allow future migrations when validating
  • cleanOnValidationError : Automatically clean on a validation error
  • cleanDisabled : Whether to disable clean
  • baselineVersion : Version to tag schema with when executing baseline
  • baselineDescription : Description to tag schema with when executing baseline
  • baselineOnMigrate : Baseline on migrate against uninitialized non-empty schema
  • configFiles : Comma-separated list of config files to use
  • configFileEncoding : Encoding to use when loading the config files
  • jarDirs : Comma-separated list of dirs for Jdbc drivers & Java migrations
  • dryRunOutput : File where to output the SQL statements of a migration dry run
  • errorHandlers : Comma-separated list of handlers for errors and warnings

Flags


  • -X : Print debug output
  • -q : Suppress all output, except for errors and warnings
  • -n : Suppress prompting for a user and password
  • -v : Print the Flyway version and exit
  • -? : Print this usage info and exit

Example

flyway -user=myuser -password=s3cr3t -url=jdbc:h2:mem -placeholders.abc=def migrate

Management

info

flyway info
+------------+---------+---------------------+------+---------------------+----------+
| Category   | Version | Description         | Type | Installed On        | State    |
+------------+---------+---------------------+------+---------------------+----------+
| Versioned  | 1       | Create person table | SQL  | 2018-04-05 07:03:22 | Success  |
| Versioned  | 2       | Add people.sql      | SQL  | 2018-04-05 07:03:22 | Success  |
| Repeatable |         | People view.sql     | SQL  | 2018-04-05 07:03:42 | Outdated |
| Repeatable |         | People view.sql     | SQL  |                     | Pending  |
+------------+---------+---------------------+------+---------------------+----------+

Documentation / Reference





Discover More
Data System Architecture
Database - Migration (Deployment|Versioning|Change Management)

with SQL database. Database migration is the process of changing the structure of the database in an other with mostly DDL statement. The flow sometimes will block any change that risks data-loss. See...
Card Puncher Data Processing
What is the H2 Database?

H2 is an embedded and standalone ANSI-SQL89 compliant SQL engine on top of the internal key-value mvstore. The database is implemented in Java (It was...



Share this page:
Follow us:
Task Runner