Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Flyway - database migrations made easy

994 views

Published on

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

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Flyway - database migrations made easy

  1. 1. www.linkedin.com/in/bjornongenae @BjornOngenae Bjorn Ongenae
  2. 2. Development: The code side
  3. 3. Development: The database side (1/2)
  4. 4. Development: The database side (2/2) DEV PRODHmm, what to release this week? New tables, some data, a view or two,…
  5. 5. 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
  6. 6. 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
  7. 7. Ever considered database migrations? Recreate from scratch Clear state Easy version upgrades + + =
  8. 8. How does it work Step 1: version control Creates a table SCHEMA_VERSION schema_version
  9. 9. 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
  10. 10. 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
  11. 11. Inside the schema_version table
  12. 12. 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
  13. 13. Result after migration
  14. 14. 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 );
  15. 15. 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;
  16. 16. How do migrations look like? (3/3) Plain SQL Versioned Repeatable Java V1_2__Another_user
  17. 17. Where to store the migrations?
  18. 18. Yeah nice, but how to run the migrations? Maven API Command line GradleAnt Scala Build Tool
  19. 19. 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
  20. 20. Let’s migrate using Maven (2/2)
  21. 21. Any other commands? Migrate Clean Info RepairValidate Baseline

×