flyway - database migrations made easy
TRANSCRIPT
www.linkedin.com/in/bjornongenae
@BjornOngenae
Bjorn Ongenae
Development: The code side
Development: The database side (1/2)
Development: The database side (2/2)
DEV
PRODHmm, what to release this week?
New tables, some data, a view or two,…
Let’s compare
Version well defined Say what?
Version controlled sources On a good day locally
Well defined release I’ll have a look
The code The database
Let’s focus on the database for once
Version well defined Say what?
Version controlled sources On a good day locally
Well defined release I’ll have a look
The code The database
Ever considered database migrations?
Recreate from scratch
Clear state
Easy version upgrades
+
+=
How does it work
Step 1: version control
Creates a table SCHEMA_VERSION schema_version
How does it work
Step 1: version control
Creates a table SCHEMA_VERSION
Step 2: scanning
Scan filesystem/classpath for new migrations
schema_version
version 1
How does it work
Step 1: version control
Creates a table SCHEMA_VERSION
Step 2: scanning
Scan filesystem/classpath for new migrations
Step 3: sorting
Sort the new migrations on version number
schema_version
version 2
Inside the schema_version table
Ready to migrate
Step 1: version control
Creates a table SCHEMA_VERSION
Step 2: scanning
Scan filesystem/classpath for new migrations
Step 3: sorting
Sort the new migrations on version number
schema_version
version 2.8.1
pending
Result after migration
How do migrations look like? (1/3)
Plain SQL
Versioned
Repeatable
Java
V2.1__create_bar_invite.sql
CREATE TABLE bar_invite ( id uuid NOT NULL, email text NOT NULL, registration uuid, created_on timestamp with time zone NOT NULL, bar_id uuid, user_id uuid, bartender boolean);
How do migrations look like? (2/3)
Plain SQL
Versioned
Repeatable
Java
R__create_bar_invite_view.sql
CREATE OR REPLACE VIEW bar_invite_emails AS select email from bar_invites;
How do migrations look like? (3/3)
Plain SQL
Versioned
Repeatable
Java
V1_2__Another_user
Where to store the migrations?
Yeah nice, but how to run the migrations?
Maven API Command line
GradleAnt Scala Build Tool
Let’s migrate using Maven (1/2)
Step 1: add dependency
Obtains the Flyway library
Step 2: configure
Configure database, user, password,…
Step 3: run
mvn flyway:migrate
Let’s migrate using Maven (2/2)
Any other commands?
Migrate Clean Info
RepairValidate Baseline