Class SchemaHistory
java.lang.Object
migratedb.v1.core.internal.schemahistory.SchemaHistory
The schema history used to track all applied migrations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddAppliedMigration(int installedRank, Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success) final voidaddAppliedMigration(Version version, String description, MigrationType type, String script, @Nullable Checksum checksum, int executionTime, boolean success) Records a new applied migration.final voidaddSchemasMarker(Schema<?, ?>[] schemas) Indicates in the schema history table that MigrateDb created these schemas.abstract List<AppliedMigration>protected intCalculates the installed rank for the new migration to be inserted.voidClears 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()final AppliedMigrationRetrieves the baseline marker from the schema history table.Table<?,?> getTable()final booleanChecks whether the schema history table contains at least one applied migration, not counting markers for schema creation or baselining.final booleanChecks 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.toString()abstract voidupdate(AppliedMigration appliedMigration, ResolvedMigration resolvedMigration) Updates this applied migration to match this resolved migration.abstract <T> TAcquires an exclusive read-write lock on the schema history table.
-
Field Details
-
EMPTY_SCHEMA_DESCRIPTION
- See Also:
-
NO_DESCRIPTION_MARKER
- See Also:
-
table
The schema history table used by MigrateDB. Non-final due to the table name fallback mechanism.
-
-
Constructor Details
-
SchemaHistory
public SchemaHistory()
-
-
Method Details
-
getTable
- Returns:
- The schema history table.
-
withLock
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
- 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
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
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.
-
getSchemasCreatedByMigrateDb
-
update
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
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) -
toString
-