Class DefaultRevisionManager
-
- All Implemented Interfaces:
-
pro.fessional.wings.faceless.flywave.InteractiveManager,pro.fessional.wings.faceless.flywave.SchemaRevisionManager
public final class DefaultRevisionManager implements SchemaRevisionManager
Manage database version based on the names of the tables (including shard tables).
- Since:
2019-06-05
trydofor
-
-
Constructor Summary
Constructors Constructor Description DefaultRevisionManager(Map<String, DataSource> plainDataSources, DataSource shardDataSource, SqlStatementParser sqlStatementParser, SqlSegmentProcessor sqlSegmentProcessor, SchemaDefinitionLoader schemaDefinitionLoader, String schemaVersionTable)
-
Method Summary
Modifier and Type Method Description BiConsumer<String, String>logWay(BiConsumer<String, String> func)How to log the runtime token and message Function<String, Boolean>askWay(Function<String, Boolean> func)How to confirm, pass message, return to continue or stop BooleanneedAsk(SchemaRevisionManager.AskType ask, Boolean yes)Whether to confirm before undofinal UnitaddDropRegexp(String regexp)Add a RegExp to match drop statement. Map<String, Long>currentRevision()Get name and revision of each datasource Map<String, SortedMap<Long, SchemaRevisionManager.Status>>statusRevisions()Get the revision and its status of each datasource, sorted from lowest to highest. UnitpublishRevision(Long revision, Long commitId)Publish the given revision to the database, possibly cascading upgrades or downgrades. UnitbumpingRevision(Long revision, Long commitId)Only bump the revision number without executing scripts, used for handling manual execution cases. UnitforceApplyBreak(Long revision, Long commitId, Boolean isUpto, String dataSource)Force to run a breakpoint script (script only, no cascading upgrades or downgrades), usually to fix an abnormal operation. UnitcheckAndInitSql(SortedMap<Long, SchemaRevisionManager.RevisionSql> sqls, Long commitId, Boolean updateDiff)Compare the SQL between in local and in database. UnitforceUpdateSql(SchemaRevisionManager.RevisionSql revision, Long commitId)Force to insert/update the local SQL to the management table if inconsistent (do nothing if consistent) UnitforceUpdateSql(Long revision, String upto, String undo, Long commitId)Force to insert/update the local SQL to the management table if inconsistent (do nothing if consistent) UnitforceExecuteSql(String text)Force to execute a sql with flywave syntax, but no versioning, no stateful logging and checking. UnitforceExecuteSql(SortedMap<Long, SchemaRevisionManager.RevisionSql> sqls, Boolean isUpto)Force to execute the sqls with flywave syntax, but no versioning, no stateful logging and checking. -
-
Constructor Detail
-
DefaultRevisionManager
DefaultRevisionManager(Map<String, DataSource> plainDataSources, DataSource shardDataSource, SqlStatementParser sqlStatementParser, SqlSegmentProcessor sqlSegmentProcessor, SchemaDefinitionLoader schemaDefinitionLoader, String schemaVersionTable)
-
-
Method Detail
-
logWay
BiConsumer<String, String> logWay(BiConsumer<String, String> func)
How to log the runtime token and message
-
askWay
Function<String, Boolean> askWay(Function<String, Boolean> func)
How to confirm, pass message, return to continue or stop
-
needAsk
Boolean needAsk(SchemaRevisionManager.AskType ask, Boolean yes)
Whether to confirm before
undo- Parameters:
ask- ask typeyes- whether to confirm, true by default- Returns:
old value
-
addDropRegexp
final Unit addDropRegexp(String regexp)
Add a RegExp to match drop statement.
- Parameters:
regexp- RegExp
-
currentRevision
Map<String, Long> currentRevision()
Get name and revision of each datasource
-
statusRevisions
Map<String, SortedMap<Long, SchemaRevisionManager.Status>> statusRevisions()
Get the revision and its status of each datasource, sorted from lowest to highest.
nullmeans uninitialized.
-
publishRevision
Unit publishRevision(Long revision, Long commitId)
Publish the given revision to the database, possibly cascading upgrades or downgrades. If there is an inconsistency between the start and end points or a breakpoint, write to the log and skip the execution.
A breakpoint, a discontinuous APPLY state, is an abnormal or inserting state. When upgrading, the start point must be
APPLYand the end point must NOT beAPPLY. When downgrading, the start point and the end points must beAPPLY, ignoring the un-APPLY breakpoints in between.Be careful with backup data when downgrading, the data or table may be deleted.
- Parameters:
revision- To this version, i.e.commitId- commit id of Journal
-
bumpingRevision
Unit bumpingRevision(Long revision, Long commitId)
Only bump the revision number without executing scripts, used for handling manual execution cases.
-
forceApplyBreak
Unit forceApplyBreak(Long revision, Long commitId, Boolean isUpto, String dataSource)
Force to run a breakpoint script (script only, no cascading upgrades or downgrades), usually to fix an abnormal operation.
- Parameters:
revision- To this version, i.e.commitId- commit id of JournalisUpto- upto or undo, default upto(true).dataSource- name of datasource to execute,nullmeans all
-
checkAndInitSql
Unit checkAndInitSql(SortedMap<Long, SchemaRevisionManager.RevisionSql> sqls, Long commitId, Boolean updateDiff)
Compare the SQL between in local and in database. If not initialized, run the
REVISION_1ST_SCHEMArevision. If it does not exist, then save local to database. If it exists but the contents are not the same and has beenAPPLYthen log error, otherwise update it.- Parameters:
sqls- sql in localcommitId- commit id of JournalupdateDiff- Whether to auto update inconsistent sql, default false.
-
forceUpdateSql
Unit forceUpdateSql(SchemaRevisionManager.RevisionSql revision, Long commitId)
Force to insert/update the local SQL to the management table if inconsistent (do nothing if consistent)
- Parameters:
revision- revision sqlcommitId- commit id of Journal
-
forceUpdateSql
Unit forceUpdateSql(Long revision, String upto, String undo, Long commitId)
Force to insert/update the local SQL to the management table if inconsistent (do nothing if consistent)
- Parameters:
revision- revisionupto- upgrade sql textundo- downgrade sql textcommitId- commit id of Journal
-
forceExecuteSql
Unit forceExecuteSql(String text)
Force to execute a sql with flywave syntax, but no versioning, no stateful logging and checking.
- Parameters:
text- sql text
-
forceExecuteSql
Unit forceExecuteSql(SortedMap<Long, SchemaRevisionManager.RevisionSql> sqls, Boolean isUpto)
Force to execute the sqls with flywave syntax, but no versioning, no stateful logging and checking.
- Parameters:
sqls- sql in localisUpto- upto or undo, default true
-
-
-
-