Package org.dellroad.stuff.schema
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
.
-
ClassDescriptionSupport superclass for
SchemaUpdate
implementations with standard bean property implementations.Handles the initialization and schema maintenance of a database.ADataSource
that wraps an innerDataSource
and automatically performs some update operation on the innerDataSource
on first access.Database action interface.SchemaUpdate<T>A one-time database schema update.TopologicalSorter.EdgeLister
implementation reflectingSchemaUpdate
predecessor constraints.ADataSource
that wraps an innerDataSource
and automatically intializes and updates the database schema using aSQLSchemaUpdater
on first access.An SQLDatabaseAction
that executes a single SQL statement.Holds and executes a configured SQL script, possibly containing multiple statements.Concrete extension ofAbstractSchemaUpdater
for SQL databases.Exception thrown by aAbstractSchemaUpdater.initializeAndUpdateDatabase(D)
when it encounters one or more recorded updates that are not recognized.Exception thrown by anAbstractUpdatingDataSource
operating in asynchronous mode whengetConnection()
is invoked while an update is still in progress.ADataSource
that wraps an innerDataSource
and automatically applies a configuredSQLCommandList
on first access.