Flyway - database migrations made easy

jstack_eu 1,172 views 22 slides Jun 07, 2016
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

5 minute ignite about Flyway: Database migrations made easy. Version control for your database so you can migrate it with ease and confidence.


Slide Content

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 PROD Hmm, 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 s chema_version

How does it work Step 1: version control Creates a table SCHEMA_VERSION Step 2: scanning Scan filesystem/ classpath for new migrations s chema_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 s chema_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 s chema_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 Gradle Ant 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 Repair Validate Baseline