Slide 1

Slide 1 text

AXEL FONTAINE @axelfontaine axel@boxfuse.com Database Migrations made Easy

Slide 2

Slide 2 text

About Axel Fontaine • Founder and CEO of Boxfuse • Over 15 years industry experience • Continuous Delivery expert & trainer • Regular speaker at tech conferences • JavaOne RockStar in 2014 @axelfontaine

Slide 3

Slide 3 text

flywaydb.org

Slide 4

Slide 4 text

boxfuse.com

Slide 5

Slide 5 text

about questions

Slide 6

Slide 6 text

Who is using a relational database ?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Why should you use a relational database ? • ACID • Battle-tested reliability • Performance • Scaling up • Slice & dice data • Defer decisions

Slide 9

Slide 9 text

relational databases should be the default choice for new projects

Slide 10

Slide 10 text

What about scaling ???

Slide 11

Slide 11 text

Algorithms are for people who don’t know how to buy RAM. Clay Shirky

Slide 12

Slide 12 text

RAM is the new disk

Slide 13

Slide 13 text

The secrets of scaling • Buy RAM (it’s cheap!) • Keep LOBs out of the DB (only store a reference) • Only then look at techniques like sharding

Slide 14

Slide 14 text

Here is a small story

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

What about NoSQL ???

Slide 17

Slide 17 text

NoSQL databases are like divas They can be great, but you’d better know how to please them

Slide 18

Slide 18 text

Now let’s talk about database migrations ...

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

POLL: how are you doing database migrations? • Ad-hoc individual statements • Scripts (ad-hoc) • In-house tool (automated) • DB Migration tool • DB Migration API on App startup

Slide 21

Slide 21 text

APP

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

APP

Slide 24

Slide 24 text

APP Axel APP Prod APP Test APP CI APP Christian

Slide 25

Slide 25 text

SQL

Slide 26

Slide 26 text

SQL SQL SQL ? ? ?

Slide 27

Slide 27 text

flywaydb.org

Slide 28

Slide 28 text

5 years old

Slide 29

Slide 29 text

250 000+ downloads in 2014

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

With techniques such as continuous delivery becoming more mainstream, automated database migrations are a baseline capability for many software teams. While there are many tools in this space, we continue to recommend Flyway for its low-friction approach. Flyway has a vibrant open-source community behind it, and support for both traditional and cloud-based databases such as Amazon Redshift and Google Cloud SQL. -- ThoughtWorks

Slide 33

Slide 33 text

How does Flyway work ???

Slide 34

Slide 34 text

SQL SQL SQL ? ? ?

Slide 35

Slide 35 text

How does Flyway work ??? Empty DB

Slide 36

Slide 36 text

How does Flyway work ??? Empty DB Version 2 Version 1

Slide 37

Slide 37 text

What were Flyway’s design goals ???

Slide 38

Slide 38 text

It just works

Slide 39

Slide 39 text

Keeping it simple (saying no)

Slide 40

Slide 40 text

Convention over Configuration

Slide 41

Slide 41 text

No Lock-in

Slide 42

Slide 42 text

0 required dependencies

Slide 43

Slide 43 text

6 commands info clean migrate baseline validate repair

Slide 44

Slide 44 text

Demo

Slide 45

Slide 45 text

Supported databases

Slide 46

Slide 46 text

Supported execution platforms

Slide 47

Slide 47 text

Third party plugins

Slide 48

Slide 48 text

Basic architecture Migration Resolver API Database- specific support Metadata Table Migration Executor

Slide 49

Slide 49 text

Flyway flyway = new Flyway(); flyway.setDataSource(url, user, password); flyway.migrate();

Slide 50

Slide 50 text

mvn flyway:migrate … … …

Slide 51

Slide 51 text

Slide 52

Slide 52 text

flyway migrate -url=… -user=… -password=…

Slide 53

Slide 53 text

gradle flywayMigrate flyway { url = ‘…’ user = ‘…’ password = ‘…’ }

Slide 54

Slide 54 text

Demo

Slide 55

Slide 55 text

When should you migrate the database ???

Slide 56

Slide 56 text

Code and database share the same lifecycle So why risk having them not fit together?

Slide 57

Slide 57 text

Database migration should be performed on application startup

Slide 58

Slide 58 text

Flyway flyway = new Flyway(); flyway.setDataSource(url, user, password); flyway.migrate();

Slide 59

Slide 59 text

The Fear of DDL

Slide 60

Slide 60 text

VS DML DDL

Slide 61

Slide 61 text

Name Balance Homer 163 Marge 214 Bart 9 Lisa 25

Slide 62

Slide 62 text

VS DML DDL Name Balance Homer 0 Marge 0 Bart 0 Lisa 0 Name Homer Marge Bart Lisa From a business perspective the risk of DML and DDL is the same

Slide 63

Slide 63 text

Demo

Slide 64

Slide 64 text

A word about in-memory databases

Slide 65

Slide 65 text

Do you really want to test your code with a different query engine from the one you have in production???

Slide 66

Slide 66 text

Getting started

Slide 67

Slide 67 text

http://flywaydb.org/getstarted

Slide 68

Slide 68 text

Summary • Use a database migration tool

Slide 69

Slide 69 text

Summary • Use a database migration tool • Run it on application startup • Get started tomorrow 

Slide 70

Slide 70 text

flywaydb.org

Slide 71

Slide 71 text

Thanks ! AXEL FONTAINE @axelfontaine flywaydb.org boxfuse.com