This brief tutorial will teach how to get up and running with the MigrateDB 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.
Start by downloading the MigrateDB Command-line Tool for your platform and extract it.
The JDBC drivers are not part of the distribution, but you can download them easily:
./migratedb download-drivers
INFO Processing artifacts for 'DB2 11.5.7.0' INFO Downloading 'https://repo1.maven.org/maven2/com/ibm/db2/jcc/11.5.7.0/jcc-11.5.7.0.jar' INFO Validating 'com.ibm.db2.jcc-11.5.7.0.jar.tmp' ... INFO Validating 'org.xerial.sqlite-jdbc-3.34.0.jar.tmp' INFO Successfully downloaded 15 drivers
Let’s now jump into our new directory created from downloading MigrateDB:
cd migratedb-1.0.0
Configure MigrateDB by editing /conf/migratedb.conf
, like this:
migratedb.url=jdbc:h2:file:./foobardb
migratedb.user=SA
migratedb.password=
Now create your 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 MigrateDB to migrate your database:
./migratedb 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"."migratedb_state" 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)
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:
migratedb-1.0.0> migratedb 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)
In this brief tutorial we saw how to:
These migrations were then successfully found and executed.