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. 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. 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. 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. 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. 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. References
● Evolutionary Database Design – Martin Fowler, 200
● Industrialisation des développements : automatisez
● Continuous Database Integration