Package org.dellroad.stuff.schema


package org.dellroad.stuff.schema
Classes supporting automated database schema management.

Features include:

  • Automatic initialization of the database schema when the application runs for the first time
  • Automatic application of database schema updates as needed during each application startup cycle
  • Automated tracking and constraint-based ordering of schema updates supporting multiple code branches
  • Integration with Spring allowing simple XML declaration of updates
  • An ant task that verifies schema update correctness

See SpringSQLSchemaUpdater for an example of how to declare your DataSource and associated schema updates in a Spring application context.

Updates may have ordering constraints, and these should be declared explicitly. Once you have done so, then you may safely "cherry pick" individual schema updates for merging into different code branches without worrying whether the schema will get messed up, because any ordering constraint violations will be detected automatically. This verification step is required to detect inconsistencies between the updates and the current code.

See DellRoad Stuff's ant macros for the schemacheck ant macro that can be used to verify that your delcared schema updates, when applied to the original schema, yield the expected result (which is typically generated automatically by your schema generation tool from your current code). It is also a good idea to compare your generated shema matches to an expected result during each build to detect schema changes caused by e.g., inadvertent changes to model classes.

The central classes are SQLSchemaUpdater and SpringSQLSchemaUpdater.