Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flyway - Database Migrations Made Easy

Flyway - Database Migrations Made Easy

We all take version control for granted. And it is, when it comes to code. On the database side, however schema evolution is often performed ad-hoc: a quick statement here, a little script there. The result: confusion and uncertainty. Has this update already been applied on this instance? Should we apply this other script first? Is our application going to run against this database?

No more! This is where database migration tools come to the rescue! We'll look at a popular open-source choice called Flyway. By the end of the session, you'll have a solid understanding of what it does, how it works and how to effectively integrate it into your project. We'll look at concepts and solutions. We'll tackle the hard problems and show you how this fits in a Continuous Delivery and Zero Downtime workflow. This will transform how you deal with your database, and you'll never look back.

2d505d3fd867e284a384986533c2e5f8?s=128

Axel Fontaine

June 18, 2015
Tweet

More Decks by Axel Fontaine

Other Decks in Technology

Transcript

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

  2. 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
  3. flywaydb.org

  4. boxfuse.com

  5. about questions

  6. Who is using a relational database ?

  7. None
  8. Why should you use a relational database ? • ACID

    • Battle-tested reliability • Performance • Scaling up • Slice & dice data • Defer decisions
  9. relational databases should be the default choice for new projects

  10. What about scaling ???

  11. Algorithms are for people who don’t know how to buy

    RAM. Clay Shirky
  12. RAM is the new disk

  13. 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
  14. Here is a small story

  15. None
  16. What about NoSQL ???

  17. NoSQL databases are like divas They can be great, but

    you’d better know how to please them
  18. Now let’s talk about database migrations ...

  19. None
  20. 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
  21. APP

  22. None
  23. APP

  24. APP Axel APP Prod APP Test APP CI APP Christian

  25. SQL

  26. SQL SQL SQL ? ? ?

  27. flywaydb.org

  28. 5 years old

  29. 250 000+ downloads in 2014

  30. None
  31. None
  32. 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
  33. How does Flyway work ???

  34. SQL SQL SQL ? ? ?

  35. How does Flyway work ??? Empty DB

  36. How does Flyway work ??? Empty DB Version 2 Version

    1
  37. What were Flyway’s design goals ???

  38. It just works

  39. Keeping it simple (saying no)

  40. Convention over Configuration

  41. No Lock-in

  42. 0 required dependencies

  43. 6 commands info clean migrate baseline validate repair

  44. Demo

  45. Supported databases

  46. Supported execution platforms

  47. Third party plugins

  48. Basic architecture Migration Resolver API Database- specific support Metadata Table

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

  50. mvn flyway:migrate <configuration> <url>…</url> <user>…</user> <password>…</password> </configuration>

  51. <flyway:migrate url=“…” user=“…” password=“…”/>

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

  53. gradle flywayMigrate flyway { url = ‘…’ user = ‘…’

    password = ‘…’ }
  54. Demo

  55. When should you migrate the database ???

  56. Code and database share the same lifecycle So why risk

    having them not fit together?
  57. Database migration should be performed on application startup

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

  59. The Fear of DDL

  60. VS DML DDL

  61. Name Balance Homer 163 Marge 214 Bart 9 Lisa 25

  62. 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
  63. Demo

  64. A word about in-memory databases

  65. Do you really want to test your code with a

    different query engine from the one you have in production???
  66. Getting started

  67. http://flywaydb.org/getstarted

  68. Summary • Use a database migration tool

  69. Summary • Use a database migration tool • Run it

    on application startup • Get started tomorrow 
  70. flywaydb.org

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