flyway

25
Flyway The agile database migration framework for Java Kaunas JUG Saulius Tvarijonas · [email protected]

Upload: kaunas-java-user-group

Post on 20-May-2015

454 views

Category:

Documents


10 download

DESCRIPTION

Flyway: The agile database migration framework for Java

TRANSCRIPT

Page 1: Flyway

FlywayThe agile database migration framework for Java

Kaunas JUG

Saulius Tvarijonas · [email protected]

Page 2: Flyway

Why migration tool?

● Multiple environments (dev[1..*], staging, prod)

● Multiple developers

Page 3: Flyway

Questions?

● What is current state of database?

● Has script already applied or not?

● Has quick fix to production applied to test

environment also?

● How do you set up a new database instance?

Page 4: Flyway

How it works?

● Metadata table SCHEMA_VERSION

● Each change is recorded in metadata table

● Scans classpath for available migrations. SQL

or Java.

● The migrations are then sorted based on their

version number and applied in order

Page 5: Flyway

How it works?

Page 6: Flyway

How it works?

Page 7: Flyway

Preparing an existing database

● Create an initial migration script that will

recreate your current state and give it a low

version number

● Use flyway:init to create the metadata table

and set this script as the current version

Page 8: Flyway

Preparing existing database

Page 9: Flyway

Design Goals

● Cooperation between DEV and DBA

● Use full power of the DB

● Almost no lock-in

● Automatic so you can forget about it

Page 10: Flyway

It just works

● Keep it simple

● Convention over configuration

● Zero required dependencies

Page 11: Flyway

Versions and namingExamples of valid versions:

● 1● 001● 5.2● 5_2 (5.2 at runtime)● 1.2.3.4.5.6.7.8.9● 205.68● 20130115113556● 2013.1.15.11.35.56● 2013.01.15.11.35.56

Page 12: Flyway

Commands

INFO

MIGRATE

CLEAN

INIT

VALIDATE

REPAIR

Page 13: Flyway

Integrations

● Java API (also works on Android) for migrating

the database on application startup

● Maven plugin, Gradle plugin, SBT plugin, Ant

tasks or the Command-line client

Page 14: Flyway

DatabasesOracle

SQL Server

SQL Azure

DB2

MySQL (inc. Amazon RDS)

MariaDB

Google Cloud SQL

PostgreSQL (inc. Amazon RDS and Heroku)

H2

Hsql Derby

SQLite

Page 15: Flyway

Architecture

Page 16: Flyway

Java

Page 17: Flyway

Maven

Page 18: Flyway

Apply to production

Page 19: Flyway

The Fear of DDL

Page 20: Flyway

DML ⇔ DDL

Page 21: Flyway

Cluster on start-up

Page 22: Flyway

When SQL isn’t enough

● Advanced text formatting

● BLOB

Page 23: Flyway

Java Migrations

Page 24: Flyway

Recommended

Page 25: Flyway

Java Forever

Thank

You!