First Steps: Command-line

This brief tutorial will teach how to get up and running with the Flyway Command-line tool. It will take you through the steps on how to configure it and how to write and execute your first few database migrations.

This tutorial should take you about 5 minutes to complete.

Downloading and extracting Flyway

Start by downloading the Flyway Command-line Tool for your platform and extract it.

Let’s jump into our new directory:

cd flyway-5.2.4

Configuring Flyway

Once that is done, configure Flyway by editing /conf/flyway.conf like this:

flyway.url=jdbc:h2:file:./foobardb
flyway.user=SA
flyway.password=

Creating the first migration

Now create a first migration in the /sql directory called V1__Create_person_table.sql:

create table PERSON (
    ID int not null,
    NAME varchar(100) not null
);

Migrating the database

It’s now time to execute Flyway to migrate your database:

flyway-5.2.4> flyway migrate

If all went well, you should see the following output:

Database: jdbc:h2:file:./foobardb (H2 1.4)
Successfully validated 1 migration (execution time 00:00.008s)
Creating Schema History table: "PUBLIC"."flyway_schema_history"
Current version of schema "PUBLIC": << Empty Schema >>
Migrating schema "PUBLIC" to version 1 - Create person table
Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.033s)

Adding a second migration

If you now add a second migration to the /sql directory called V2__Add_people.sql:

insert into PERSON (ID, NAME) values (1, 'Axel');
insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
insert into PERSON (ID, NAME) values (3, 'Ms. Bar');

and execute it by issuing:

flyway-5.2.4> flyway migrate

You now get:

Database: jdbc:h2:file:./foobardb (H2 1.4)
Successfully validated 2 migrations (execution time 00:00.018s)
Current version of schema "PUBLIC": 1
Migrating schema "PUBLIC" to version 2 - Add people
Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.016s)

Summary

In this brief tutorial we saw how to:

  • install the Flyway Command-line tool
  • configure it so it can talk to our database
  • write our first couple of migrations

These migrations were then successfully found and executed.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(236)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-03-15 null in JavaScript
2017-03-15 查看计算机型号
2016-03-15 ConfigurationManager.AppSettings Property
2016-03-15 What is a good buffer size for socket programming?
2016-03-15 Protected vs protected internal (Again) in c#
2016-03-15 protected (C# Reference)
2016-03-15 abstract (C# Reference)
点击右上角即可分享
微信分享提示