Call EntityMigration SchemaMigration because that's what it's for and I want to
add a new DataMigration mechanism so that people can stop using schema migrations to do data migration.
This commit is contained in:
@@ -514,9 +514,9 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
* This is called by the persistence context to register a migration for the entity managed by
|
||||
* this marshaller.
|
||||
*/
|
||||
protected void registerMigration (EntityMigration migration)
|
||||
protected void registerMigration (SchemaMigration migration)
|
||||
{
|
||||
_migrations.add(migration);
|
||||
_schemaMigs.add(migration);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -727,9 +727,9 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
log.info("Migrating " + getTableName() + " from " + currentVersion + " to " +
|
||||
_schemaVersion + "...");
|
||||
|
||||
if (_migrations.size() > 0) {
|
||||
if (_schemaMigs.size() > 0) {
|
||||
// run our pre-default-migrations
|
||||
for (EntityMigration migration : _migrations) {
|
||||
for (SchemaMigration migration : _schemaMigs) {
|
||||
if (migration.runBeforeDefault() &&
|
||||
migration.shouldRunMigration(currentVersion, _schemaVersion)) {
|
||||
migration.init(getTableName(), _fields);
|
||||
@@ -887,7 +887,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
});
|
||||
}
|
||||
|
||||
// we do not auto-remove columns but rather require that EntityMigration.Drop records be
|
||||
// we do not auto-remove columns but rather require that SchemaMigration.Drop records be
|
||||
// registered by hand to avoid accidentally causing the loss of data
|
||||
|
||||
// we don't auto-remove indices either because we'd have to sort out the potentially
|
||||
@@ -895,7 +895,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
// index was hand defined in a @Column clause)
|
||||
|
||||
// run our post-default-migrations
|
||||
for (EntityMigration migration : _migrations) {
|
||||
for (SchemaMigration migration : _schemaMigs) {
|
||||
if (!migration.runBeforeDefault() &&
|
||||
migration.shouldRunMigration(currentVersion, _schemaVersion)) {
|
||||
migration.init(getTableName(), _fields);
|
||||
@@ -1107,8 +1107,8 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
/** Indicates that we have been initialized (created or migrated our tables). */
|
||||
protected boolean _initialized;
|
||||
|
||||
/** A list of hand registered entity migrations to run prior to doing the default migration. */
|
||||
protected ArrayList<EntityMigration> _migrations = new ArrayList<EntityMigration>();
|
||||
/** A list of hand registered schema migrations to run prior to doing the default migration. */
|
||||
protected ArrayList<SchemaMigration> _schemaMigs = new ArrayList<SchemaMigration>();
|
||||
|
||||
/** The name of the table we use to track schema versions. */
|
||||
protected static final String SCHEMA_VERSION_TABLE = "DepotSchemaVersion";
|
||||
|
||||
@@ -189,19 +189,18 @@ public class PersistenceContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a migration for the specified entity class.
|
||||
* Registers a schema migration for the specified entity class.
|
||||
*
|
||||
* <p> This method must be called <b>before</b> an Entity is used by any repository. Thus you
|
||||
* should register all migrations immediately after creating your persistence context or if you
|
||||
* are careful to ensure that your Entities are only used by a single repository, you can
|
||||
* register your migrations in the constructor for that repository.
|
||||
* should register all migrations in the constructor of the repository that declares them in
|
||||
* its {@link DepotRepository#getManagedRecords} method.
|
||||
*
|
||||
* <p> Note that the migration process is as follows:
|
||||
*
|
||||
* <ul><li> Note the difference between the entity's declared version and the version recorded
|
||||
* in the database.
|
||||
* <li> Run all registered pre-migrations
|
||||
* <li> Perform all default migrations (column additions and removals)
|
||||
* <li> Perform all default migrations (column and index additions, index removals)
|
||||
* <li> Run all registered post-migrations </ul>
|
||||
*
|
||||
* Thus you must either be prepared for the entity to be at <b>any</b> version prior to your
|
||||
@@ -215,7 +214,7 @@ public class PersistenceContext
|
||||
* guaranteed to be run in registration order and with predictable pre- and post-conditions.
|
||||
*/
|
||||
public <T extends PersistentRecord> void registerMigration (
|
||||
Class<T> type, EntityMigration migration)
|
||||
Class<T> type, SchemaMigration migration)
|
||||
{
|
||||
getRawMarshaller(type).registerMigration(migration);
|
||||
}
|
||||
|
||||
+6
-6
@@ -35,12 +35,12 @@ import static com.samskivert.jdbc.depot.Log.log;
|
||||
* migrations. See {@link PersistenceContext#registerPreMigration} and {@link
|
||||
* PersistenceContext#registerPostMigration}.
|
||||
*/
|
||||
public abstract class EntityMigration extends Modifier
|
||||
public abstract class SchemaMigration extends Modifier
|
||||
{
|
||||
/**
|
||||
* A convenient migration for dropping a column from an entity.
|
||||
*/
|
||||
public static class Drop extends EntityMigration
|
||||
public static class Drop extends SchemaMigration
|
||||
{
|
||||
public Drop (int targetVersion, String columnName) {
|
||||
super(targetVersion);
|
||||
@@ -64,7 +64,7 @@ public abstract class EntityMigration extends Modifier
|
||||
/**
|
||||
* A convenient migration for renaming a column in an entity.
|
||||
*/
|
||||
public static class Rename extends EntityMigration
|
||||
public static class Rename extends SchemaMigration
|
||||
{
|
||||
public Rename (int targetVersion, String oldColumnName, String newColumnName) {
|
||||
super(targetVersion);
|
||||
@@ -121,7 +121,7 @@ public abstract class EntityMigration extends Modifier
|
||||
* instantiated with the name of a persistent field, not the name of a database column. These
|
||||
* can be very different things for classes that use @Column annotations.
|
||||
*/
|
||||
public static class Retype extends EntityMigration
|
||||
public static class Retype extends SchemaMigration
|
||||
{
|
||||
public Retype (int targetVersion, String fieldName) {
|
||||
super(targetVersion);
|
||||
@@ -158,7 +158,7 @@ public abstract class EntityMigration extends Modifier
|
||||
*
|
||||
* @see Column#defaultValue
|
||||
*/
|
||||
public static class Add extends EntityMigration
|
||||
public static class Add extends SchemaMigration
|
||||
{
|
||||
public Add (int targetVersion, String fieldName, String defaultValue) {
|
||||
super(targetVersion);
|
||||
@@ -215,7 +215,7 @@ public abstract class EntityMigration extends Modifier
|
||||
return (currentVersion < _targetVersion);
|
||||
}
|
||||
|
||||
protected EntityMigration (int targetVersion)
|
||||
protected SchemaMigration (int targetVersion)
|
||||
{
|
||||
super();
|
||||
_targetVersion = targetVersion;
|
||||
Reference in New Issue
Block a user