AGILE DATABASE DEVELOPMENT WITH Tim Berglund June, 2009
TIM BERGLUND
WE BELIEVE CODE CHANGES
WE BELIEVE CODE CHANGES
WE ACT LIKE THE DATABASE DOESN’T
WE ACT LIKE THE DATABASE DOESN’T
TERMINAL MALADAPTION
EMBALMING
WON’T DIE
NOT REALLY ALIVE
CURSES THE DBA WHO CHANGES IT
WE WILL BREAK THE CURSE
AGILE DATABASE DEVELOPMENT
Refactoring Evolutionary Automated Data Testing Modeling Agile Database Development Source Sandboxes Control
REFACTORING
REFACTORING
REFACTORING This term occasionally gets abused!
REFACTORING A disciplined way to make small changes to your source code to improve its design, making it easier to work with.
REFACTORING Not adding features!
REFACTORING Not fixing bugs!
REFACTORING Opportunistically improving design to accommodate change.
DATABASE REFACTORING A simple change to a database schema that improves its design while retaining both its behavioral and informational semantics.
EVOLUTIONARY DATA MODELING
EVOLUTIONARY DATA MODELING NOT TRYING TO “GET IT RIGHT UP FRONT.”
EVOLUTIONARY DATA MODELING MAYBE SOME BIG THOUGHTS AT FIRST
EVOLUTIONARY DATA MODELING BUILD THE SIMPLEST THING THAT CAN POSSIBLY WORK...EVERY DAY
DATABASE TESTS TDD IN THE DB
DATABASE TESTS
DATABASE TESTS STORED PROCEDURES
DATABASE TESTS STORED PROCEDURES SQLUNIT
DATABASE TESTS STORED PROCEDURES SQLUNIT DBUNIT
DATABASE TESTS STORED PROCEDURES SQLUNIT DBUNIT CUSTOM HYBRIDS
SOURCE CONTROL
SOURCE CONTROL LIKE MOTHER TAUGHT YOU
SOURCE CONTROL
SOURCE CONTROL DDL EXTRACT/MIGRATION SCRIPTS REFERENCE DATA STORED PROCS/TRIGGERS
SANDBOXES
COMMAND-LINE TOOL
COMMAND-LINE TOOL JAVA/JDBC
COMMAND-LINE TOOL JAVA/JDBC CROSS-PLATFORM
COMMAND-LINE TOOL JAVA/JDBC CROSS-PLATFORM ANT, MAVEN, SPRING, GRAILS
CHANGELOG
CHANGELOG COMMANDS
CHANGELOG COMMANDS MIGRATION SCENARIOS
CHANGELOG
CHANGELOG SQL IN XML
CHANGELOG SQL IN XML COHERENT GROUPS OF OPERATIONS
CHANGELOG SQL IN XML COHERENT GROUPS OF OPERATIONS TRACKED IN DATABASE
CHANGELOG <changeSet author="tlberglund (generated)" id="1236660747556-11"> <createTable tableName="scshoppingcart"> <column autoIncrement="true" name="id" type="INT"> <constraints nullable="false"/> </column> <column name="userid" type="INT"> <constraints nullable="false"/> </column> <column name="lastmodified" type="DATETIME"/> <column name="name" type="VARCHAR(50)"/> </createTable> </changeSet> <changeSet author="tlberglund" id="spot-1-1-2"> <renameTable oldTableName="scscrubrecordwarehouse" newTableName="scrub_record_log" /> </changeSet>
LIQUIBASE COMMANDS
LIQUIBASE COMMANDS generateChangeLog
LIQUIBASE COMMANDS changeLogSync
LIQUIBASE COMMANDS update
LIQUIBASE COMMANDS tag
LIQUIBASE COMMANDS rollback
LIQUIBASE COMMANDS diff
DEMO
AND WE’RE BACK
Refactoring Evolutionary Automated Data Testing Modeling Agile Database Development Source Sandboxes Control
CULTIVATING THE BROWNFIELD
LEGACY ENTERPRISE APP
NEW GRAILS HOTNESS
HARD CUTOVER
CREATIVE ORM MAPPINGS
WITHERING ON THE VINE
BROWNFIELD DATA INTEGRATION
BROWNFIELD DATA INTEGRATION TIME ZERO MIGRATION
BROWNFIELD DATA INTEGRATION TIME ZERO MIGRATION
BROWNFIELD TESTING
BROWNFIELD TESTING INTEGRATION TEST DATA
BROWNFIELD TESTING
BROWNFIELD TESTING T0 MIGRATION SCRIPTS
BROWNFIELD TESTING
THE CURSE IS BROKEN
THANK YOU! TIM BERGLUND AUGUST TECHNOLOGY GROUP, LLC http://www.augusttechgroup.com tim.berglund@augusttechgroup.com @tlberglund
PHOTO CREDITS HAMMER SHATTERING GLASS: HTTP://WWW.FLICKR.COM/PHOTOS/WHISPERWOLF/3486270713 DODO: HTTP://WWW.INTERNATIONALDOVESOCIETY.COM/MISCSPECIES/DODO.HTM EMBALMING: HTTP://LIBRARY.THINKQUEST.ORG/C0116982/HTML%20PAGE%20FOLDER/ HMUMMIFICATION.HTM ATTACKING MUMMY: HTTP://WWW.FLICKR.COM/PHOTOS/ROONBABOON/292393932/ CREEPY MUMMY HEAD: HTTP://WWW.FLICKR.COM/PHOTOS/DR-INI/446311713/ MARTIN FOWLER: HTTP://WWW.FLICKR.COM/PHOTOS/PRAGDAVE/173640462/ SCOTT AMBLER: HTTP://WWW.AMBYSOFT.COM/SCOTTAMBLER.HTML BRENDEN FRASER: HTTP://SCRAPETV.COM/NEWS/NEWS%20PAGES/ENTERTAINMENT/UNIVERSAL-FIRE- ACCIDENTAL-NEW-MUMMY-MOVIE-DELIBERATE-SCRAPE-TV-THE-WORLD-ON-YOUR-SIDE.HTML SAND: HTTP://WWW.FLICKR.COM/PHOTOS/LEVIATHOR/207625319/ MOTHER AND CHILD: HTTP://WWW.FLICKR.COM/PHOTOS/PATRICK_Q/268149208/ BROWN FIELD: HTTP://WWW.FLICKR.COM/PHOTOS/ARTUR02/471094378/ JALOPY: HTTP://WWW.FLICKR.COM/PHOTOS/DRAGONFLEYE/3246153/ JALOPY ON RT 66: HTTP://WWW.FLICKR.COM/PHOTOS/EVOETSCH/2436023218/ PIMPMOBILE: HTTP://WWW.FLICKR.COM/PHOTOS/AIRGAP/1053594933/ JUNKED JALOPY: HTTP://WWW.FLICKR.COM/PHOTOS/JABOOBIE/61014658/ PAINTING CAR: HTTP://WWW.FLICKR.COM/PHOTOS/GARETHJMSAUNDERS/2066690016/

Agile Database Development with Liquibase

Editor's Notes

  • #3 I&amp;#x2019;m your presenter.
  • #4 I&amp;#x2019;m a Java developer.
  • #5 I work with a lot of open source technologies.
  • #6 I haven&amp;#x2019;t written a lot of Java in the past year. Mostly these days I write Groovy.
  • #7 I participate in the local development community by serving on the boards of www.denveropensource.org and www.iasadenver.org.
  • #8 The August Technology Group is my consulting firm.
  • #9 As software developers and architects, our worlds are filled with data.
  • #10 Unfortunately, the data is not always in the condition we&amp;#x2019;d like. We try to do a good job structuring it, but the reality is that we often fail, and even when we succeed, the business changes enough so that even our successes are short-lived.
  • #11 Our tool sets and processes have developed to deal expertly with rapidly changing code.
  • #12 Our tool sets and processes have developed to deal expertly with rapidly changing code.
  • #13 The same tools and practices have not been applied to data. Leading to one of two problems...
  • #14 The same tools and practices have not been applied to data. Leading to one of two problems...
  • #15 Will it die? It is said of evolutionary systems that things that fail to adapt to change die out. If only this were the case with the enterprise database...
  • #16 Rather than going extinct, the production DBAs surround it like priests, carefully filling it with embalming fluid and wrapping it in linen strips. (And possibly putting some operations personnel in the tomb to serve the database in the afterlife.)
  • #17 Inability to change and overprotection lead us to this dread antipattern.
  • #18 There are long-lived Enterprise applications that rely on it, so it can&amp;#x2019;t just go away.
  • #19 It isn&amp;#x2019;t really alive either, because business needs are constantly changing, but the database can&amp;#x2019;t change with them.
  • #20 At least the production DBAs seem to think so!
  • #21 We&amp;#x2019;ll figure out how to manage changes to the database such that we can make them with confidence in a way that brings the best of developer tools to bear and is relatively friendly to DBA workflows. We&amp;#x2019;ll do this with a mindset and a tool.
  • #22 The fix is what Scott Ambler calls &amp;#x201C;evolutionary [or agile] database development.&amp;#x201D; This consists of five components.
  • #24 Martin sez...
  • #25 Martin sez...
  • #30 Scott sez.... Code refactorings are really only concerned about behavior. DBs have behavior (stored procs, triggers, etc.) but also information. The database must say the same thing in the same way after the refactoring.
  • #31 These are two mistakes here: one is thinking we&amp;#x2019;re smart enough to do all this designing correctly at the outset&amp;#x2014;we&amp;#x2019;re not. The other is thinking that the database&amp;#x2019;s business context is a static thing&amp;#x2014;it isn&amp;#x2019;t. There is no &amp;#x201C;right&amp;#x201D; up front, because requirements will change constantly.
  • #32 Which doesn&amp;#x2019;t mean we can&amp;#x2019;t do a couple of days of designing at first; we can. It makes sense to try to anticipate what we can and make big, hard-to-change commitments correctly. We always expect change, though.
  • #34 TDD adoption in software development is low enough, but it is virtually unheard of in database development. The tooling lags behind and the expertise is singularly rare.
  • #35 There are ways to do it. The tools aren&amp;#x2019;t what they are for TDD of code, but there are options.
  • #36 There are ways to do it. The tools aren&amp;#x2019;t what they are for TDD of code, but there are options.
  • #37 There are ways to do it. The tools aren&amp;#x2019;t what they are for TDD of code, but there are options.
  • #38 There are ways to do it. The tools aren&amp;#x2019;t what they are for TDD of code, but there are options.
  • #39 Bring all the knowledge, practices, and advantages of software source control to the database. Simply control all those text files in SVN or Git like you normally would. This practice is old hat.
  • #40 Every database artifact goes in to the repository.
  • #41 Developers need a place to deploy refactorings when they&amp;#x2019;re trying to get their tests to pass. This must be a local database not used by any other team member or system.
  • #42 If we learn how to refactor databases from Ambler and Sandalage, Liquibase is the tool that makes it easy. It is an XML-based love poem to Scott Ambler.
  • #43 Liquibase is fundamentally a command-line tool written in Java. It uses JDBC to communicate with the database, and can coexist well in a non-Java shop. I can be invoked from popular open-source build tools and frameworks.
  • #44 Liquibase is fundamentally a command-line tool written in Java. It uses JDBC to communicate with the database, and can coexist well in a non-Java shop. I can be invoked from popular open-source build tools and frameworks.
  • #45 Liquibase is fundamentally a command-line tool written in Java. It uses JDBC to communicate with the database, and can coexist well in a non-Java shop. I can be invoked from popular open-source build tools and frameworks.
  • #46 Liquibase is fundamentally a command-line tool written in Java. It uses JDBC to communicate with the database, and can coexist well in a non-Java shop. I can be invoked from popular open-source build tools and frameworks.
  • #47 We&amp;#x2019;ll consider three aspects of Liquibase. How it stores the schema, how it interacts with the database, and how to use it in some real-world scenarios.
  • #48 We&amp;#x2019;ll consider three aspects of Liquibase. How it stores the schema, how it interacts with the database, and how to use it in some real-world scenarios.
  • #49 We&amp;#x2019;ll consider three aspects of Liquibase. How it stores the schema, how it interacts with the database, and how to use it in some real-world scenarios.
  • #50 Must we rewrite our SQL in XML? We must. It&amp;#x2019;s painful and unappetizing, but worth it! Also, there&amp;#x2019;s a Grails plugin called Autobase that lets us do it in nice Groovy Builder syntax, which is preferable. We won&amp;#x2019;t address Autobase in detail here, but it&amp;#x2019;s worth looking in to.
  • #51 Must we rewrite our SQL in XML? We must. It&amp;#x2019;s painful and unappetizing, but worth it! Also, there&amp;#x2019;s a Grails plugin called Autobase that lets us do it in nice Groovy Builder syntax, which is preferable. We won&amp;#x2019;t address Autobase in detail here, but it&amp;#x2019;s worth looking in to.
  • #52 Must we rewrite our SQL in XML? We must. It&amp;#x2019;s painful and unappetizing, but worth it! Also, there&amp;#x2019;s a Grails plugin called Autobase that lets us do it in nice Groovy Builder syntax, which is preferable. We won&amp;#x2019;t address Autobase in detail here, but it&amp;#x2019;s worth looking in to.
  • #53 The changelog is a script that builds your schema one DDL statement at a time. Each changeSet is converted into a dialect-specific SQL statement and is executed in the database, then marked as complete in a log table.
  • #54 Extracts the database&amp;#x2019;s metadata and generates a changelog. This is the first step is getting started on a database that already exists.
  • #55 Since Liquibase tracks the status of all changesets in the changelog, we&amp;#x2019;ll need to tell it that our newly extracted changelog is in sync with the actual database. This command usually shouldn&amp;#x2019;t be executed except as the second step getting started with the tool.
  • #56 Plays any new changeSets in the changeLog against the database. This is the statement you&amp;#x2019;ll use the most during evolutionary database development with Liquibase.
  • #57 Marks the database for a future rollback.
  • #58 Rolls back changesets to given tag.
  • #59 Supposed to document the differences between the database and the changelog. I&amp;#x2019;ve not had good luck with this so far against MySQL and SQLServer databases.
  • #63 Evolutionary Database Development is not controversial among software developers, because we are largely persuaded of the core propositions. Moreover, Liquibase seems like a reasonable tool to help. Now let&amp;#x2019;s talk about some practices to put in place in a brownfield effort.
  • #64 People are using it, it works, it has literally years of knowledge and business process encoded in it. It&amp;#x2019;s also ugly and outdated, and its schema seems to have been built by the DBA Club after school. But you&amp;#x2019;re replacing it, with Grails...!