Flyway起步

目錄

MySQL

docker run --name flyway-demo -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.17

docker exec -i flyway-demo mysql -uroot -p123456  <<< "CREATE DATABASE IF NOT EXISTS flyway DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"

Flyway

Download

cd ~/Downloads

tar xf flyway-commandline-5.2.4-macosx-x64.tar.gz

cd flyway-5.2.4

Conf

vim conf/flyway.conf
flyway.url=jdbc:mysql://127.0.0.1:3306/flyway

flyway.user=root

flyway.password=123456

Migrate

  • V1.0.0
vim sql/V1.0.0__create_person_table.sql
create table person (
    ID int not null,
    NAME varchar(100) not null
);
./flyway migrate
Successfully validated 1 migration (execution time 00:00.014s)
Creating Schema History table: `flyway`.`flyway_schema_history`
Current version of schema `flyway`: << Empty Schema >>
Migrating schema `flyway` to version 1.0.0 - create person table
Successfully applied 1 migration to schema `flyway` (execution time 00:00.638s)
  • V1.0.1.1
vim sql/V1.0.1.1__add_first_people.sql
insert into person (ID, NAME) values (1, 'XiaoMing');
./flyway migrate
Successfully validated 2 migrations (execution time 00:00.018s)
Current version of schema `flyway`: 1.0.0
Migrating schema `flyway` to version 1.0.1.1 - add first people
Successfully applied 1 migration to schema `flyway` (execution time 00:00.097s)
  • V1.0.1.2
vim sql/V1.0.1.2__add_second_people.sql
insert into person (ID, NAME) values (2, 'XiaoHong');
./flyway migrate
Successfully validated 3 migrations (execution time 00:00.018s)
Current version of schema `flyway`: 1.0.1.1
Migrating schema `flyway` to version 1.0.1.2 - add second people
Successfully applied 1 migration to schema `flyway` (execution time 00:00.091s)
vim sql/V1.0.1.2__add_third_people.sql
insert into person (ID, NAME) values (3, 'XiaoZhang');
./flyway migrate
ERROR: Found more than one migration with version 1.0.1.2
Offenders:
-> /Users/kevin/Downloads/flyway-5.2.4/sql/V1.0.1.2__add_second_people.sql (SQL)
-> /Users/kevin/Downloads/flyway-5.2.4/sql/V1.0.1.2__add_third_people.sql (SQL)

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章