+ All Categories
Home > Technology > Flyway - database migrations made easy

Flyway - database migrations made easy

Date post: 16-Apr-2017
Category:
Upload: jstack
View: 824 times
Download: 16 times
Share this document with a friend
22
Transcript
Page 1: Flyway - database migrations made easy
Page 2: Flyway - database migrations made easy

www.linkedin.com/in/bjornongenae

@BjornOngenae

Bjorn Ongenae

Page 3: Flyway - database migrations made easy

Development: The code side

Page 4: Flyway - database migrations made easy

Development: The database side (1/2)

Page 5: Flyway - database migrations made easy

Development: The database side (2/2)

DEV

PRODHmm, what to release this week?

New tables, some data, a view or two,…

Page 6: Flyway - database migrations made easy

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

Page 7: Flyway - database migrations made easy

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

Page 8: Flyway - database migrations made easy

Ever considered database migrations?

Recreate from scratch

Clear state

Easy version upgrades

+

+=

Page 9: Flyway - database migrations made easy

How does it work

Step 1: version control

Creates a table SCHEMA_VERSION schema_version

Page 10: Flyway - database migrations made easy

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

Page 11: Flyway - database migrations made easy

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

Page 12: Flyway - database migrations made easy

Inside the schema_version table

Page 13: Flyway - database migrations made easy

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

Page 14: Flyway - database migrations made easy

Result after migration

Page 15: Flyway - database migrations made easy

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);

Page 16: Flyway - database migrations made easy

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;

Page 17: Flyway - database migrations made easy

How do migrations look like? (3/3)

Plain SQL

Versioned

Repeatable

Java

V1_2__Another_user

Page 18: Flyway - database migrations made easy

Where to store the migrations?

Page 19: Flyway - database migrations made easy

Yeah nice, but how to run the migrations?

Maven API Command line

GradleAnt Scala Build Tool

Page 20: Flyway - database migrations made easy

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

Page 21: Flyway - database migrations made easy

Let’s migrate using Maven (2/2)

Page 22: Flyway - database migrations made easy

Any other commands?

Migrate Clean Info

RepairValidate Baseline


Recommended