【工具链】flyway使用详解

1 Flyway的工作原理

简介:

Flyway是一款数据库迁移(migration)工具。简单点说,就是在你部署应用的时候,帮你执行数据库脚本的工具。

1.1 Flyway的校验版本号算法

flyway在升级数据库时会先计算之前已经升级过的脚本的checksum值和数据库的checkSum值进行比对,如果老脚本发生了变化后checkSum校验就会失败,从而抛出异常,checkSum计算算法为(CRC32 (循环冗余校验码)算法)。
新增的脚本则会和数据库中的版本号进行比较,如果小于数据库存储的最后一个版本号,也不会继续执行。

命名规范

TODO 规范还有R开头的

TODO 规范还有U开头的

1.1.1 实战

场景1:当数据库为空时,执行flyway初始化数据库

用户表:V1_0_1__user_demo.sql 

create table user
(
        user_no  varchar(32) not null comment '人员编号',
        user_name varchar(32) not null comment '人员姓名',
        sex     varchar(8) not null comment '性别',
        primary key (user_no)
);

订单表:V1_0_2__order_demo.sql

create table order_demo
(
        order_no  varchar(32) not null comment '订单编号',
        order_name varchar(32) not null comment '订单姓名',
        order_type     varchar(8) not null comment '订单类型',
        primary key (order_no)
);
执行flyway命令:flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

场景2:数据库脚本升级

错误案例一:直接在用户表:V1_0_1__user_demo.sql中修改


create table user
(
        user_no  varchar(32) not null comment '人员编号',
        user_name varchar(32) not null comment '人员姓名',
        sex     varchar(8) not null comment '性别',
        primary key (user_no)
);
添加新的建表语句
create table user_info
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);

执行flyway命令:flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url=‘jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true’ -user=root -password=123456 migrate

结果报错,说用户表:V1_0_1__user_demo.sql的checksum与flyway_schema_history中记录的不匹配。

错误案例二:用户信息表:V1_0_0__userinfo_demo.sql

用户表:V1_0_1__user_demo.sql 

create table user
(
        user_no  varchar(32) not null comment '人员编号',
        user_name varchar(32) not null comment '人员姓名',
        sex     varchar(8) not null comment '性别',
        primary key (user_no)
);

订单表:V1_0_2__order_demo.sql

create table order_demo
(
        order_no  varchar(32) not null comment '订单编号',
        order_name varchar(32) not null comment '订单姓名',
        order_type     varchar(8) not null comment '订单类型',
        primary key (order_no)
);

用户信息表:V1_0_0__userinfo_demo.sql
create table user_info
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);

执行flyway命令:flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url=‘jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true’ -user=root -password=123456 migrate

正确案例:用户信息表:V1_0_0__userinfo_demo.sql

要改成比1_0_2要大,这里重命名sql脚本为V1_0_3__userinfo_demo.sql

用户表:V1_0_1__user_demo.sql 

create table user
(
        user_no  varchar(32) not null comment '人员编号',
        user_name varchar(32) not null comment '人员姓名',
        sex     varchar(8) not null comment '性别',
        primary key (user_no)
);

订单表:V1_0_2__order_demo.sql

create table order_demo
(
        order_no  varchar(32) not null comment '订单编号',
        order_name varchar(32) not null comment '订单姓名',
        order_type     varchar(8) not null comment '订单类型',
        primary key (order_no)
);

用户信息表:V1_0_3__userinfo_demo.sql
create table user_info
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url=‘jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true’ -user=root -password=123456 migrate

1.1.2 总结

1、sql文件需要按照flyway的命名规范进行命名

2、执行flyway时要保证后面执行的脚本编号要比数据库flyway_schema_history表存储的最后一个版本号要大(错误案例二)。

3、以前执行过的脚本不能进行修改(错误案例一)

1.2 Flyway的参数

1.2.1 flyway命令行参数

flyway [options] command

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     : [pro] 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
connectRetries               : Maximum number of retries when attempting to connect to the database
initSql                      : SQL statements to run to initialize a new database connection
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       : [pro] 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
stream                       : [pro] Stream SQL migrations when executing them
batch                        : [pro] Batch SQL statements when executing them
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
validateMigrationNaming      : Validate file names of SQL migrations (including callbacks)
ignoreMissingMigrations      : Allow missing migrations when validating
ignoreIgnoredMigrations      : Allow ignored migrations when validating
ignorePendingMigrations      : Allow pending 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                 : [pro] File where to output the SQL statements of a migration dry run
errorOverrides               : [pro] Rules to override specific SQL states and errors codes
oracle.sqlplus               : [pro] Enable Oracle SQL*Plus command support
licenseKey                   : [pro] Your Flyway license key
color                        : Whether to colorize output. Values: always, never, or auto (default)
outputFile                   : Send output to the specified file alongside the console

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
-json       : Print the output in JSON format
-community  : Run the Flyway Community Edition (default)
-pro        : Run the Flyway Pro Edition
-enterprise : Run the Flyway Enterprise Edition

1.2.2 flyway命令行参数说明及实战

命令模块

1、flyway migrate 执行数据库脚本

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

2、flyway clean 清除数据库所有的对象

flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

3、flyway info 打印有关已应用、当前和待处理迁移的信息

4、flyway validate 是对比Metadata表与本地Migrations的Checksum值,如果值相同则验证通过,否则验证失败,从而可以防止对已经Apply到数据库的本地Migrations的无意修改。

5、flyway undo 撤消最近应用的版本化迁移基线,在基线版本上对现有数据库进行基线(版本回滚)

6、flyway repair 操作能够修复flyway_schema_history表,该操作在flyway_schema_history表出现错误时是非常有用的。

  • 移除失败的 Migration 记录,该问题只是针对不支持DDL事务的数据库。DDL(Data Definition Languages)语句数据定义语言,这些语句定义了不同的数据段、数据库、表、列、索引等数据库对象的定义。常用的语句关键字主要包括 create、drop、alter等。
  • 重新调整已经应用的 Migratons 的 checksum 值,比如:某个 Migration 已经被应用,但本地进行了修改,又期望重新应用并调整 checksum 值,不过尽量不要这样操作,否则可能造成其它环境失败。
例如在用户信息表:V1_0_3__userinfo_demo.sql中添加一个用户信息扩展表
create table user_info
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);

create table user_info_ext
(
        user_no  varchar(32) not null comment '人员编号',
        key varchar(32) not null comment 'key',
		value varchar(32) not null comment 'value',
        primary key (user_no)
);

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 repair

这种场景就像上面的错误案例一,错误案例一报错执行不成功,此命令修改错误的 SQL 文件校验码的值,再执行 migrate 就没问题了,但是,修改的内容还是不会被执行!因为 flyway_schema_history 数据表的 success 值为 1 ,便不会在重新执行脚本。

7、flyway baseline 在基线版本上对现有数据库设置基线(当前数据库不是空的,且没有flyway_schema_history。这种情况就是,项目在中途的时候才引入flyway作为数据库版本迁移。这个时候,我们就需要用baseline这个命令了)

选项模块

Options (Format: -key=value)

参考命令:

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

driver : Fully qualified classname of the JDBC driver

指数据库驱动,
mysql:-driver=com.mysql.cj.jdbc.Driver
oracle:-driver=oracle.jdbc.OracleDriver

url : Jdbc url to use to connect to the database

数据库url:url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true'

user : User to use to connect to the database

数据库用户名

password : Password to use to connect to the database

数据库密码

connectRetries : Maximum number of retries when attempting to connect to the database

尝试连接数据库时的最大重试次数

initSql : SQL statements to run to initialize a new database connection

连接上数据库之后的初始化sql
flyway -locations=filesystem:/root/zj/dbdemo -initSql="create table inittable(user_no  varchar(32) not null comment '人员编号',address varchar(32) not null comment '地址',primary key (user_no))" -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 baseline

schemas : Comma-separated list of the schemas managed by Flyway

指定要操作的数据库schema,可以是单个schema或多个schema,多个schema之间使用逗号分隔。如果在schemas配置了多个schema,那么flyway_schema_history表在第一个schema里面

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306' -user=root -password=123456 -schemas=flywayDb,flywayDb1 migrate

table : Name of Flyway’s schema history table

默认名flyway_schema_history

locations : Classpath locations to scan recursively for migrations

-locations=filesystem:/root/zj/dbdemo 指定数据库脚本的路径

resolvers : Comma-separated list of custom MigrationResolvers

flyway对sql解析的扩展类列表,指定自定义的resolver,多个resolver之间使用逗号分隔。

skipDefaultResolvers : Skips default resolvers (jdbc, sql and Spring-jdbc)

指定是否跳过默认的resolver,默认为false。如果不使用内置解析器,同时又没有指定自定义解析器时,flyway不会执行任何sql,如下图

flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

flyway -locations=filesystem:/root/zj/dbdemo -skipDefaultResolvers=true -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

sqlMigrationPrefix : File name prefix for versioned SQL migrations

指定SQL脚本migration的前缀,默认为V。如下图,指定为C,则找不到相应的以C开头的脚本,则不会执行任意SQL

flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

flyway -locations=filesystem:/root/zj/dbdemo -sqlMigrationPrefix=C -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

undoSqlMigrationPrefix : [pro] File name prefix for undo SQL migrations

undo文件前缀,默认是U,sql回滚,仅限于商业版可用,社区版不可用
前缀+版本号+分割符+描述+后缀。例如:U1.1__Undo.sql

repeatableSqlMigrationPrefix : File name prefix for repeatable SQL migrations

指定可重复的SQL脚本migration的前缀,默认为R。命名规范:前缀+分割符+描述+后缀。例如:R__init_runs.sql

创建一个脚本R__init_runs.sql
create table inittable
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);
flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

flyway -locations=filesystem:/root/zj/dbdemo -repeatableSqlMigrationPrefix=R -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

sqlMigrationSeparator : File name separator for SQL migrations

migration文件分隔符,默认是__,可以设置成--看下效果
创建sql文件V1_0_1--user_demo.sql
create table user
(
        user_no  varchar(32) not null comment '人员编号',
        user_name varchar(32) not null comment '人员姓名',
        sex     varchar(8) not null comment '性别',
        primary key (user_no)
);

flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

flyway -locations=filesystem:/root/zj/dbdemo -sqlMigrationSeparator=-- -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

sqlMigrationSuffixes : Comma-separated list of file name suffixes for SQL migrations

migration文件后缀,默认是.sql

stream : [pro] Stream SQL migrations when executing them

是否对migration文件流化处理,而不是全部的加载到内存之后再处理(如果migration文件很大,如1GB,一般也不会遇到这样的情况),仅限于商业版可用,社区版不可用

batch : [pro] Batch SQL statements when executing them

是否对migration文件进行批处理(批处理指的是一次操作中执行多条SQL语句,相比于一次一次执行效率会提高很多),可以节约带宽,当然对于处理大的migration文件而言

mixed : Allow mixing transactional and non-transactional statements

TODO

encoding : Encoding of SQL migrations

指定SQL脚本的编码,默认为UTF-8。

placeholderReplacement : Whether placeholders should be replaced

是否进行占位符替换,默认为true
脚本中可能出现动态替换的情况,如时间等。这时候此配置要设置为false

创建表V1_0_4__placeholderReplacement.sql
create table placeholderReplacement
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);

insert into placeholderReplacement values('1','${123}')

flyway -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

flyway -locations=filesystem:/root/zj/dbdemo -placeholderReplacement=true -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

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

记录到schema history table中的用户名

target : Target version up to which Flyway should use migrations

	指定要升级到的目标schema版本号,默认为最新版本。migration时数据库的版本,最好使用默认值

outOfOrder : Allows migrations to be run “out of order”

	指定是否在发现migration不按顺序时报错,默认为false。

创建一个sql版本号为1.0.0的sql文件V1_0_0__outOfOrder.sql
(
        user_no  varchar(32) not null comment '人员编号',
        address varchar(32) not null comment '地址',
        primary key (user_no)
);
flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

flyway -locations=filesystem:/root/zj/dbdemo -outOfOrder=true -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

注意,outOfOrder插入的编号是1.0.0,flyway插入是按编号的大小,所以如果不用outOfOrder,那后面的脚本编号要大于1.0.4才能正常插入

callbacks : Comma-separated list of FlywayCallback classes

指定自定义的callback,多个callback之间使用逗号分隔。是一个flyway的扩展点,可以在命令执行时调用自定义的callback,常用的callback有beforeMigrate,afterMigrate等。生成的jar包替换flyway/lib/community的flyway-core-6.2.2.jar即可

skipDefaultCallbacks : Skips default callbacks (sql)

指定是否跳过默认的callback,默认为false

validateOnMigrate : Validate when running migrate

指定是否在执行migration时校验SQL脚本的正确性,默认为true

validateMigrationNaming : Validate file names of SQL migrations (including callbacks)

是否验证migration文件,默认是false,如果migration文件名格式不满足要求,skip,如果为true,快速失败

ignoreMissingMigrations : Allow missing migrations when validating

指定是否忽略缺失的migration,默认为false。如果之前的升级脚本sql文件删除了,与flyway_schema_history对应不上,则也不会报错,这样不太安全,建议设置成false

flyway -locations=filesystem:/root/zj/dbdemo -ignoreMissingMigrations=true -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 migrate

ignoreIgnoredMigrations : Allow ignored migrations when validating

TODO

ignorePendingMigrations : Allow pending migrations when validating

TODO

ignoreFutureMigrations : Allow future migrations when validating

TODO

cleanOnValidationError : Automatically clean on a validation error

指定在校验migration时出现错误时是否清空数据库,默认为false

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 validate

flyway -locations=filesystem:/root/zj/dbdemo -cleanOnValidationError=true -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 validate

cleanDisabled : Whether to disable clean

指定是否禁用clean操作,默认为false。

flyway -driver=com.mysql.cj.jdbc.Driver -cleanDisabled=true -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 clean

baselineVersion : Version to tag schema with when executing baseline

指定baseline的版本号,默认为1。

flyway -locations=filesystem:/root/zj/dbdemo -driver=com.mysql.cj.jdbc.Driver -url='jdbc:mysql://127.0.0.1:3306/flywayDb?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowMultiQueries=true' -user=root -password=123456 baseline

baselineDescription : Description to tag schema with when executing baseline

如上图,description字段

baselineOnMigrate : Baseline on migrate against uninitialized non-empty schema

指定是否在第一次执行migration时,执行baseline操作。

configFiles : Comma-separated list of config files to use

flyway -configFiles=config/flyway.conf migrate
指定flyway配置文件

configFileEncoding : Encoding to use when loading the config files

配置文件编码

jarDirs : Comma-separated list of dirs for Jdbc drivers & Java migrations

<install-dir>/jars

dryRunOutput : [pro] File where to output the SQL statements of a migration dry run

文件输出迁移试运行的SQL语句的位置

errorOverrides : [pro] Rules to override specific SQL states and errors codes

指定错误覆盖的规则,可以是warn、ignore、abort。

oracle.sqlplus : [pro] Enable Oracle SQL*Plus command support


licenseKey : [pro] Your Flyway license key
color : Whether to colorize output. Values: always, never, or auto (default)

输出颜色

outputFile : Send output to the specified file alongside the console

把执行日志输出到文件