Start by downloading the Flyway Command-line Tool for your platform and extract it.
Let's jump into our new directory:
> cd flyway-4.2.0
We can now configure Flyway by editing /conf/flyway.conf
like this:
flyway.url=jdbc:h2:file:./foobardb flyway.user=SA flyway.password=
Now we can 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 );
It's now time to execute Flyway to migrate our database:
flyway-4.2.0> flyway migrate
If all went well, you should see the following output:
Creating Metadata table: "PUBLIC"."schema_version" 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.062s).
If we 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-4.2.0> flyway migrate
We now get:
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.090s).
In this brief tutorial we saw how to
These migrations were then successfully found and executed.