DB Migration Automation
Why
When things go wrong
Tools for the job
How we work
How it works
Why
●
The database has a version
– SQL is code and evolve in the same manner
●
Change/evolve quickly (be Agile)
– Commit a...
When things go wrong
● Fail-Fast
– When a migration cannot be applied, the process is
halted
– Guarantee that the version ...
Error example
[FATAL]
com.googlecode.flyway.core.api.FlywayExcepti
on: Migration of schema `tsm-db` to version
07.049.00.0...
Tools
● Flyway
– Simple & efficient
– SQL and Java migrations
● Liquibase
– Book “Database refactoring patterns”
– Multi D...
How we works
● Build team
– New feature → new SQL script → add it to the correct location
– On next startup or manually, F...
How it works
●
On startup, Flyway is called
– As simple as : flyway.migrate()
● Versioning table
– “schema_version” for Fl...
References
● Evolutionary Database Design – Martin Fowler, 200
● Industrialisation des développements : automatisez
● Cont...
Upcoming SlideShare
Loading in …5
×

Db migration automation

1,563 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,563
On SlideShare
0
From Embeds
0
Number of Embeds
171
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Db migration automation

  1. 1. DB Migration Automation Why When things go wrong Tools for the job How we work How it works
  2. 2. Why ● The database has a version – SQL is code and evolve in the same manner ● Change/evolve quickly (be Agile) – Commit a new SQL script → DB is up-to-date ● For everyone ● For everywhere – Feedback loop ● Integrate continuously – Validate the correctness of the DB changes – “Evolutionary Database Design” - Martin Fowler, 2003 ● “Techniques that allow a database design to evolve as an application develops” ● Automate – No human intervention needed
  3. 3. When things go wrong ● Fail-Fast – When a migration cannot be applied, the process is halted – Guarantee that the version of the DB is the same as the version of the Code ● No more runtime error, validation occurs on startup – Explicit error ● This script does something wrong
  4. 4. Error example [FATAL] com.googlecode.flyway.core.api.FlywayExcepti on: Migration of schema `tsm-db` to version 07.049.00.001 failed! Please restore backups and roll back database and code! You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Oops I mad a Misteack [ERROR] KEY `index_multi01` (`msisdn`,`cardState`,`creationDate`
  5. 5. Tools ● Flyway – Simple & efficient – SQL and Java migrations ● Liquibase – Book “Database refactoring patterns” – Multi DB supported – Feature complete – Complex – XML ● Built-ins into Play, Grails, Rails... and many others
  6. 6. How we works ● Build team – New feature → new SQL script → add it to the correct location – On next startup or manually, Flyway will pick-up that script and run it against the current DB ● If the webapp starts : all went ok ● Else : check the script, repair, rerun ● Run team – Hum... just check the success of the startup – Required to start our main webapp first (like it is done actually)
  7. 7. How it works ● On startup, Flyway is called – As simple as : flyway.migrate() ● Versioning table – “schema_version” for Flyway – Contains all run scripts ● Name – V07_070_00_001__multiple_tacs_for_a_handset.sql – V07_070_00_002__unswapIccid.sql ● Date ● Hash – Not used – Has the script be modified since if was run ? ● If yes, the DB may not reflect the reality
  8. 8. References ● Evolutionary Database Design – Martin Fowler, 200 ● Industrialisation des développements : automatisez ● Continuous Database Integration

×