Class SchemaHistory
- java.lang.Object
-
- migratedb.v1.core.internal.schemahistory.SchemaHistory
-
public abstract class SchemaHistory extends Object
The schema history used to track all applied migrations.
-
-
Field Summary
Fields Modifier and Type Field Description static StringEMPTY_SCHEMA_DESCRIPTIONstatic StringNO_DESCRIPTION_MARKERprotected TabletableThe schema history table used by MigrateDB.
-
Constructor Summary
Constructors Constructor Description SchemaHistory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddAppliedMigration(int installedRank, Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success)voidaddAppliedMigration(Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success)Records a new applied migration.voidaddSchemasMarker(Schema[] schemas)Indicates in the schema history table that MigrateDb created these schemas.abstract List<AppliedMigration>allAppliedMigrations()protected intcalculateInstalledRank()Calculates the installed rank for the new migration to be inserted.voidclearCache()Clears the applied migration cache.abstract voidcreate(boolean baseline)Creates the schema history.abstract voiddelete(AppliedMigration appliedMigration)Update the schema history to mark this migration as DELETEDabstract booleanexists()AppliedMigrationgetBaselineMarker()Retrieves the baseline marker from the schema history table.List<String>getSchemasCreatedByMigrateDb()TablegetTable()booleanhasAppliedMigrations()Checks whether the schema history table contains at least one applied migration, not counting markers for schema creation or baselining.booleanhasSchemasMarker()Checks whether the schema history table contains a marker row for schema creation.abstract booleanremoveFailedMigrations(RepairResult repairResult, List<MigrationPattern> migrationPatternFilter)Repairs the schema history table after a failed migration.StringtoString()abstract voidupdate(AppliedMigration appliedMigration, ResolvedMigration resolvedMigration)Updates this applied migration to match this resolved migration.abstract <T> TwithLock(Callable<T> callable)Acquires an exclusive read-write lock on the schema history table.
-
-
-
Field Detail
-
EMPTY_SCHEMA_DESCRIPTION
public static final String EMPTY_SCHEMA_DESCRIPTION
- See Also:
- Constant Field Values
-
NO_DESCRIPTION_MARKER
public static final String NO_DESCRIPTION_MARKER
- See Also:
- Constant Field Values
-
table
protected Table table
The schema history table used by MigrateDB. Non-final due to the table name fallback mechanism.
-
-
Method Detail
-
getTable
public Table getTable()
- Returns:
- The schema history table.
-
withLock
public abstract <T> T withLock(Callable<T> callable)
Acquires an exclusive read-write lock on the schema history table. This lock will be released automatically upon completion.- Returns:
- The result of the action.
-
exists
public abstract boolean exists()
- Returns:
- Whether the schema history table exists.
-
create
public abstract void create(boolean baseline)
Creates the schema history. Do nothing if it already exists.- Parameters:
baseline- Whether to include the creation of a baseline marker.
-
hasAppliedMigrations
public final boolean hasAppliedMigrations()
Checks whether the schema history table contains at least one applied migration, not counting markers for schema creation or baselining.- Returns:
trueif it does,falseif it doesn't.
-
allAppliedMigrations
public abstract List<AppliedMigration> allAppliedMigrations()
- Returns:
- The list of all migrations applied on the schema in the order they were applied (oldest first). An empty list if no migration has been applied so far.
-
getBaselineMarker
public final AppliedMigration getBaselineMarker()
Retrieves the baseline marker from the schema history table.- Returns:
- The baseline marker or
nullif none could be found.
-
removeFailedMigrations
public abstract boolean removeFailedMigrations(RepairResult repairResult, List<MigrationPattern> migrationPatternFilter)
Repairs the schema history table after a failed migration. This is only necessary for databases without DDL-transaction support.
On databases with DDL transaction support, a migration failure automatically triggers a rollback of all changes, including the ones in the schema history table.
- Parameters:
repairResult- The result object containing which failed migrations were removed.migrationPatternFilter- The migration patterns to filter by.
-
addSchemasMarker
public final void addSchemasMarker(Schema[] schemas)
Indicates in the schema history table that MigrateDb created these schemas.- Parameters:
schemas- The schemas that were created by MigrateDB.
-
hasSchemasMarker
public final boolean hasSchemasMarker()
Checks whether the schema history table contains a marker row for schema creation.- Returns:
trueif it does,falseif it doesn't.
-
update
public abstract void update(AppliedMigration appliedMigration, ResolvedMigration resolvedMigration)
Updates this applied migration to match this resolved migration.- Parameters:
appliedMigration- The applied migration to update.resolvedMigration- The resolved migration to source the new values from.
-
delete
public abstract void delete(AppliedMigration appliedMigration)
Update the schema history to mark this migration as DELETED- Parameters:
appliedMigration- The applied migration to mark as DELETED
-
clearCache
public void clearCache()
Clears the applied migration cache.
-
addAppliedMigration
public final void addAppliedMigration(Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success)
Records a new applied migration.- Parameters:
version- The target version of this migration.description- The description of the migration.type- The type of migration (BASELINE, SQL, ...)script- The name of the script to execute for this migration, relative to its classpath location.checksum- The checksum of the migration. (Optional)executionTime- The execution time (in millis) of this migration.success- Flag indicating whether the migration was successful or not.
-
calculateInstalledRank
protected int calculateInstalledRank()
Calculates the installed rank for the new migration to be inserted.- Returns:
- The installed rank.
-
addAppliedMigration
public abstract void addAppliedMigration(int installedRank, Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success)
-
-