added final String release field to migration BaseTask
This commit is contained in:
parent
1aabe9bf40
commit
f8e15ea69e
|
@ -22,7 +22,7 @@ public class FlywayMigration implements JavaMigration {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MigrationVersion getVersion() {
|
public MigrationVersion getVersion() {
|
||||||
return MigrationVersion.fromVersion(myTask.getVersion());
|
return MigrationVersion.fromVersion(myTask.getFlywayVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,6 +31,15 @@ public class AddColumnTask extends BaseTableColumnTypeTask<AddColumnTask> {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(AddColumnTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(AddColumnTask.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param theRelease
|
||||||
|
* @param theVersion
|
||||||
|
*/
|
||||||
|
public AddColumnTask(String theRelease, String theVersion) {
|
||||||
|
super(theRelease, theVersion);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws SQLException {
|
public void execute() throws SQLException {
|
||||||
|
|
|
@ -37,8 +37,8 @@ public class AddForeignKeyTask extends BaseTableColumnTask<AddForeignKeyTask> {
|
||||||
private String myForeignTableName;
|
private String myForeignTableName;
|
||||||
private String myForeignColumnName;
|
private String myForeignColumnName;
|
||||||
|
|
||||||
public AddForeignKeyTask(String theVersion) {
|
public AddForeignKeyTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstraintName(String theConstraintName) {
|
public void setConstraintName(String theConstraintName) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class AddIdGeneratorTask extends BaseTask<AddIdGeneratorTask> {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(AddIdGeneratorTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(AddIdGeneratorTask.class);
|
||||||
private final String myGeneratorName;
|
private final String myGeneratorName;
|
||||||
|
|
||||||
public AddIdGeneratorTask(String theVersion, String theGeneratorName) {
|
public AddIdGeneratorTask(String theRelease, String theVersion, String theGeneratorName) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
myGeneratorName = theGeneratorName;
|
myGeneratorName = theGeneratorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
|
||||||
private List<String> myColumns;
|
private List<String> myColumns;
|
||||||
private Boolean myUnique;
|
private Boolean myUnique;
|
||||||
|
|
||||||
public AddIndexTask(String theVersion) {
|
public AddIndexTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexName(String theIndexName) {
|
public void setIndexName(String theIndexName) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
||||||
private List<AddColumnTask> myAddColumnTasks = new ArrayList<>();
|
private List<AddColumnTask> myAddColumnTasks = new ArrayList<>();
|
||||||
private String myPkColumn;
|
private String myPkColumn;
|
||||||
|
|
||||||
public AddTableByColumnTask(String theVersion) {
|
public AddTableByColumnTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAddColumnTask(AddColumnTask theTask) {
|
public void addAddColumnTask(AddColumnTask theTask) {
|
||||||
|
|
|
@ -37,8 +37,8 @@ public class AddTableRawSqlTask extends BaseTableTask<AddTableRawSqlTask> {
|
||||||
private Map<DriverTypeEnum, List<String>> myDriverToSqls = new HashMap<>();
|
private Map<DriverTypeEnum, List<String>> myDriverToSqls = new HashMap<>();
|
||||||
private List<String> myDriverNeutralSqls = new ArrayList<>();
|
private List<String> myDriverNeutralSqls = new ArrayList<>();
|
||||||
|
|
||||||
public AddTableRawSqlTask(String theVersion) {
|
public AddTableRawSqlTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSql(DriverTypeEnum theDriverType, @Language("SQL") String theSql) {
|
public void addSql(DriverTypeEnum theDriverType, @Language("SQL") String theSql) {
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
|
||||||
private String myExecuteOnlyIfTableExists;
|
private String myExecuteOnlyIfTableExists;
|
||||||
private List<TableAndColumn> myConditionalOnExistenceOf = new ArrayList<>();
|
private List<TableAndColumn> myConditionalOnExistenceOf = new ArrayList<>();
|
||||||
|
|
||||||
public ArbitrarySqlTask(String theVersion, String theTableName, String theDescription) {
|
public ArbitrarySqlTask(String theRelease, String theVersion, String theTableName, String theDescription) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
myTableName = theTableName;
|
myTableName = theTableName;
|
||||||
myDescription = theDescription;
|
myDescription = theDescription;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public abstract class BaseTableColumnTask<T extends BaseTableTask> extends BaseT
|
||||||
|
|
||||||
private String myColumnName;
|
private String myColumnName;
|
||||||
|
|
||||||
public BaseTableColumnTask(String theVersion) {
|
public BaseTableColumnTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -39,8 +39,8 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public BaseTableColumnTypeTask(String theVersion) {
|
public BaseTableColumnTypeTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.H2_EMBEDDED, "integer");
|
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.H2_EMBEDDED, "integer");
|
||||||
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.DERBY_EMBEDDED, "integer");
|
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.DERBY_EMBEDDED, "integer");
|
||||||
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.MARIADB_10_1, "integer");
|
setColumnType(ColumnTypeEnum.INT, DriverTypeEnum.MARIADB_10_1, "integer");
|
||||||
|
|
|
@ -25,8 +25,8 @@ import org.apache.commons.lang3.Validate;
|
||||||
public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
|
public abstract class BaseTableTask<T extends BaseTableTask> extends BaseTask {
|
||||||
private String myTableName;
|
private String myTableName;
|
||||||
|
|
||||||
public BaseTableTask(String theVersion) {
|
public BaseTableTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTableName() {
|
public String getTableName() {
|
||||||
|
|
|
@ -43,10 +43,12 @@ public abstract class BaseTask<T extends BaseTask> {
|
||||||
private boolean myDryRun;
|
private boolean myDryRun;
|
||||||
private List<ExecutedStatement> myExecutedStatements = new ArrayList<>();
|
private List<ExecutedStatement> myExecutedStatements = new ArrayList<>();
|
||||||
private boolean myNoColumnShrink;
|
private boolean myNoColumnShrink;
|
||||||
private final String version;
|
private final String myRelease;
|
||||||
|
private final String myVersion;
|
||||||
|
|
||||||
protected BaseTask(String theVersion) {
|
protected BaseTask(String theRelease, String theVersion) {
|
||||||
version = theVersion;
|
myRelease = theRelease;
|
||||||
|
myVersion = theVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNoColumnShrink() {
|
public boolean isNoColumnShrink() {
|
||||||
|
@ -135,8 +137,8 @@ public abstract class BaseTask<T extends BaseTask> {
|
||||||
|
|
||||||
public abstract void execute() throws SQLException;
|
public abstract void execute() throws SQLException;
|
||||||
|
|
||||||
public String getVersion() {
|
public String getFlywayVersion() {
|
||||||
return version;
|
return myRelease + "." + myVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ExecutedStatement {
|
public static class ExecutedStatement {
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class CalculateHashesTask extends BaseTableColumnTask<CalculateHashesTask
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public CalculateHashesTask(String theVersion) {
|
public CalculateHashesTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class DropColumnTask extends BaseTableColumnTask<DropColumnTask> {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(DropColumnTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(DropColumnTask.class);
|
||||||
|
|
||||||
public DropColumnTask(String theVersion) {
|
public DropColumnTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,8 +40,8 @@ public class DropForeignKeyTask extends BaseTableTask<DropForeignKeyTask> {
|
||||||
private String myConstraintName;
|
private String myConstraintName;
|
||||||
private String myParentTableName;
|
private String myParentTableName;
|
||||||
|
|
||||||
public DropForeignKeyTask(String theVersion) {
|
public DropForeignKeyTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstraintName(String theConstraintName) {
|
public void setConstraintName(String theConstraintName) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class DropIdGeneratorTask extends BaseTask<DropIdGeneratorTask> {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(DropIdGeneratorTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(DropIdGeneratorTask.class);
|
||||||
private final String myGeneratorName;
|
private final String myGeneratorName;
|
||||||
|
|
||||||
public DropIdGeneratorTask(String theVersion, String theGeneratorName) {
|
public DropIdGeneratorTask(String theRelease, String theVersion, String theGeneratorName) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
myGeneratorName = theGeneratorName;
|
myGeneratorName = theGeneratorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ public class DropIndexTask extends BaseTableTask<DropIndexTask> {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(DropIndexTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(DropIndexTask.class);
|
||||||
private String myIndexName;
|
private String myIndexName;
|
||||||
|
|
||||||
public DropIndexTask(String theVersion) {
|
public DropIndexTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,8 +33,8 @@ public class DropTableTask extends BaseTableTask<DropTableTask> {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(DropTableTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(DropTableTask.class);
|
||||||
|
|
||||||
public DropTableTask(String theVersion) {
|
public DropTableTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class ExecuteRawSqlTask extends BaseTask<ExecuteRawSqlTask> {
|
||||||
private Map<DriverTypeEnum, List<String>> myDriverToSqls = new HashMap<>();
|
private Map<DriverTypeEnum, List<String>> myDriverToSqls = new HashMap<>();
|
||||||
private List<String> myDriverNeutralSqls = new ArrayList<>();
|
private List<String> myDriverNeutralSqls = new ArrayList<>();
|
||||||
|
|
||||||
public ExecuteRawSqlTask(String theVersion) {
|
public ExecuteRawSqlTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecuteRawSqlTask addSql(DriverTypeEnum theDriverType, @Language("SQL") String theSql) {
|
public ExecuteRawSqlTask addSql(DriverTypeEnum theDriverType, @Language("SQL") String theSql) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ public class LogStartSectionWithMessageTask extends BaseTask {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(LogStartSectionWithMessageTask.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(LogStartSectionWithMessageTask.class);
|
||||||
private final String myMessage;
|
private final String myMessage;
|
||||||
|
|
||||||
public LogStartSectionWithMessageTask(String theVersion, String theMessage) {
|
public LogStartSectionWithMessageTask(String theRelease, String theVersion, String theMessage) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
myMessage = theMessage;
|
myMessage = theMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,8 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
|
||||||
*
|
*
|
||||||
* @param theVersion
|
* @param theVersion
|
||||||
*/
|
*/
|
||||||
public ModifyColumnTask(String theVersion) {
|
public ModifyColumnTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,8 +38,8 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
private boolean myAllowNeitherColumnToExist;
|
private boolean myAllowNeitherColumnToExist;
|
||||||
private boolean myDeleteTargetColumnFirstIfBothExist;
|
private boolean myDeleteTargetColumnFirstIfBothExist;
|
||||||
|
|
||||||
public RenameColumnTask(String theVersion) {
|
public RenameColumnTask(String theRelease, String theVersion) {
|
||||||
super(theVersion);
|
super(theRelease, theVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeleteTargetColumnFirstIfBothExist(boolean theDeleteTargetColumnFirstIfBothExist) {
|
public void setDeleteTargetColumnFirstIfBothExist(boolean theDeleteTargetColumnFirstIfBothExist) {
|
||||||
|
|
|
@ -60,12 +60,12 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder forVersion(T theVersion) {
|
public Builder forVersion(T theRelease) {
|
||||||
IAcceptsTasks sink = theTask -> {
|
IAcceptsTasks sink = theTask -> {
|
||||||
theTask.validate();
|
theTask.validate();
|
||||||
myTasks.put(theVersion, theTask);
|
myTasks.put(theRelease, theTask);
|
||||||
};
|
};
|
||||||
return new Builder(sink);
|
return new Builder(theRelease.name(), sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IAcceptsTasks {
|
public interface IAcceptsTasks {
|
||||||
|
@ -74,14 +74,16 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
private final String myRelease;
|
||||||
private final IAcceptsTasks mySink;
|
private final IAcceptsTasks mySink;
|
||||||
|
|
||||||
public Builder(IAcceptsTasks theSink) {
|
public Builder(String theRelease, IAcceptsTasks theSink) {
|
||||||
|
myRelease = theRelease;
|
||||||
mySink = theSink;
|
mySink = theSink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderWithTableName onTable(String theTableName) {
|
public BuilderWithTableName onTable(String theTableName) {
|
||||||
return new BuilderWithTableName(mySink, theTableName);
|
return new BuilderWithTableName(myRelease, mySink, theTableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTask(BaseTask<?> theTask) {
|
public void addTask(BaseTask<?> theTask) {
|
||||||
|
@ -93,32 +95,32 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder executeRawSql(String theVersion, @Language("SQL") String theSql) {
|
public Builder executeRawSql(String theVersion, @Language("SQL") String theSql) {
|
||||||
mySink.addTask(new ExecuteRawSqlTask(theVersion).addSql(theSql));
|
mySink.addTask(new ExecuteRawSqlTask(myRelease, theVersion).addSql(theSql));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder executeRawSql(String theVersion, DriverTypeEnum theDriver, @Language("SQL") String theSql) {
|
public Builder executeRawSql(String theVersion, DriverTypeEnum theDriver, @Language("SQL") String theSql) {
|
||||||
mySink.addTask(new ExecuteRawSqlTask(theVersion).addSql(theDriver, theSql));
|
mySink.addTask(new ExecuteRawSqlTask(myRelease, theVersion).addSql(theDriver, theSql));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder startSectionWithMessage(String theMessage) {
|
public Builder startSectionWithMessage(String theMessage) {
|
||||||
Validate.notBlank(theMessage);
|
Validate.notBlank(theMessage);
|
||||||
addTask(new LogStartSectionWithMessageTask("log message", theMessage));
|
addTask(new LogStartSectionWithMessageTask(myRelease, "log message", theMessage));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddTableByColumns addTableByColumns(String theVersion, String theTableName, String thePkColumnName) {
|
public BuilderAddTableByColumns addTableByColumns(String theVersion, String theTableName, String thePkColumnName) {
|
||||||
return new BuilderAddTableByColumns(theVersion, mySink, theTableName, thePkColumnName);
|
return new BuilderAddTableByColumns(myRelease, theVersion, mySink, theTableName, thePkColumnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIdGenerator(String theVersion, String theGeneratorName) {
|
public void addIdGenerator(String theVersion, String theGeneratorName) {
|
||||||
AddIdGeneratorTask task = new AddIdGeneratorTask(theVersion, theGeneratorName);
|
AddIdGeneratorTask task = new AddIdGeneratorTask(myRelease, theVersion, theGeneratorName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropIdGenerator(String theVersion, String theIdGeneratorName) {
|
public void dropIdGenerator(String theVersion, String theIdGeneratorName) {
|
||||||
DropIdGeneratorTask task = new DropIdGeneratorTask(theVersion, theIdGeneratorName);
|
DropIdGeneratorTask task = new DropIdGeneratorTask(myRelease, theVersion, theIdGeneratorName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
private final AddTableRawSqlTask myTask;
|
private final AddTableRawSqlTask myTask;
|
||||||
|
|
||||||
protected BuilderAddTableRawSql(String theVersion, String theTableName) {
|
protected BuilderAddTableRawSql(String theVersion, String theTableName) {
|
||||||
myTask = new AddTableRawSqlTask(theVersion);
|
myTask = new AddTableRawSqlTask(myRelease, theVersion);
|
||||||
myTask.setTableName(theTableName);
|
myTask.setTableName(theTableName);
|
||||||
addTask(myTask);
|
addTask(myTask);
|
||||||
}
|
}
|
||||||
|
@ -146,17 +148,17 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
public class BuilderAddTableByColumns extends BuilderWithTableName implements IAcceptsTasks {
|
public class BuilderAddTableByColumns extends BuilderWithTableName implements IAcceptsTasks {
|
||||||
private final AddTableByColumnTask myTask;
|
private final AddTableByColumnTask myTask;
|
||||||
|
|
||||||
public BuilderAddTableByColumns(String theVersion, IAcceptsTasks theSink, String theTableName, String thePkColumnName) {
|
public BuilderAddTableByColumns(String theRelease, String theVersion, IAcceptsTasks theSink, String theTableName, String thePkColumnName) {
|
||||||
super(theSink, theTableName);
|
super(theRelease, theSink, theTableName);
|
||||||
myTask = new AddTableByColumnTask(theVersion);
|
myTask = new AddTableByColumnTask(myRelease, theVersion);
|
||||||
myTask.setTableName(theTableName);
|
myTask.setTableName(theTableName);
|
||||||
myTask.setPkColumn(thePkColumnName);
|
myTask.setPkColumn(thePkColumnName);
|
||||||
theSink.addTask(myTask);
|
theSink.addTask(myTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuilderWithTableName.BuilderAddColumnWithName addColumn(String theColumnName) {
|
public BuilderWithTableName.BuilderAddColumnWithName addColumn(String theVersion, String theColumnName) {
|
||||||
return new BuilderWithTableName.BuilderAddColumnWithName(theColumnName, this);
|
return new BuilderWithTableName.BuilderAddColumnWithName(myRelease, theVersion, theColumnName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,10 +172,12 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BuilderWithTableName implements IAcceptsTasks {
|
public static class BuilderWithTableName implements IAcceptsTasks {
|
||||||
private final String myTableName;
|
private final String myRelease;
|
||||||
private final IAcceptsTasks mySink;
|
private final IAcceptsTasks mySink;
|
||||||
|
private final String myTableName;
|
||||||
|
|
||||||
public BuilderWithTableName(IAcceptsTasks theSink, String theTableName) {
|
public BuilderWithTableName(String theRelease, IAcceptsTasks theSink, String theTableName) {
|
||||||
|
myRelease = theRelease;
|
||||||
mySink = theSink;
|
mySink = theSink;
|
||||||
myTableName = theTableName;
|
myTableName = theTableName;
|
||||||
}
|
}
|
||||||
|
@ -183,14 +187,14 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropIndex(String theVersion, String theIndexName) {
|
public void dropIndex(String theVersion, String theIndexName) {
|
||||||
DropIndexTask task = new DropIndexTask(theVersion);
|
DropIndexTask task = new DropIndexTask(myRelease, theVersion);
|
||||||
task.setIndexName(theIndexName);
|
task.setIndexName(theIndexName);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropThisTable(String theVersion) {
|
public void dropThisTable(String theVersion) {
|
||||||
DropTableTask task = new DropTableTask(theVersion);
|
DropTableTask task = new DropTableTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
}
|
}
|
||||||
|
@ -199,13 +203,13 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
return new BuilderAddIndexWithName(theIndexName);
|
return new BuilderAddIndexWithName(theIndexName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddColumnWithName addColumn(String theColumnName) {
|
public BuilderAddColumnWithName addColumn(String theVersion, String theColumnName) {
|
||||||
return new BuilderAddColumnWithName(theColumnName, this);
|
return new BuilderAddColumnWithName(myRelease, theVersion, theColumnName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropColumn(String theVersion, String theColumnName) {
|
public void dropColumn(String theVersion, String theColumnName) {
|
||||||
Validate.notBlank(theColumnName);
|
Validate.notBlank(theColumnName);
|
||||||
DropColumnTask task = new DropColumnTask(theVersion);
|
DropColumnTask task = new DropColumnTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
task.setColumnName(theColumnName);
|
task.setColumnName(theColumnName);
|
||||||
addTask(task);
|
addTask(task);
|
||||||
|
@ -236,7 +240,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
* @param theDeleteTargetColumnFirstIfBothEixst Setting this to true causes the migrator to be ok with the target column existing. It will make sure that there is no data in the column with the new name, then delete it if so in order to make room for the renamed column. If there is data it will still bomb out.
|
* @param theDeleteTargetColumnFirstIfBothEixst Setting this to true causes the migrator to be ok with the target column existing. It will make sure that there is no data in the column with the new name, then delete it if so in order to make room for the renamed column. If there is data it will still bomb out.
|
||||||
*/
|
*/
|
||||||
public BuilderWithTableName renameColumn(String theVersion, String theOldName, String theNewName, boolean theAllowNeitherColumnToExist, boolean theDeleteTargetColumnFirstIfBothEixst) {
|
public BuilderWithTableName renameColumn(String theVersion, String theOldName, String theNewName, boolean theAllowNeitherColumnToExist, boolean theDeleteTargetColumnFirstIfBothEixst) {
|
||||||
RenameColumnTask task = new RenameColumnTask(theVersion);
|
RenameColumnTask task = new RenameColumnTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
task.setOldName(theOldName);
|
task.setOldName(theOldName);
|
||||||
task.setNewName(theNewName);
|
task.setNewName(theNewName);
|
||||||
|
@ -252,7 +256,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
* @param theParentTableName the name of the table that exports the foreign key
|
* @param theParentTableName the name of the table that exports the foreign key
|
||||||
*/
|
*/
|
||||||
public void dropForeignKey(String theVersion, String theFkName, String theParentTableName) {
|
public void dropForeignKey(String theVersion, String theFkName, String theParentTableName) {
|
||||||
DropForeignKeyTask task = new DropForeignKeyTask(theVersion);
|
DropForeignKeyTask task = new DropForeignKeyTask(myRelease, theVersion);
|
||||||
task.setConstraintName(theFkName);
|
task.setConstraintName(theFkName);
|
||||||
task.setTableName(getTableName());
|
task.setTableName(getTableName());
|
||||||
task.setParentTableName(theParentTableName);
|
task.setParentTableName(theParentTableName);
|
||||||
|
@ -278,7 +282,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withColumns(String theVersion, String... theColumnNames) {
|
public void withColumns(String theVersion, String... theColumnNames) {
|
||||||
AddIndexTask task = new AddIndexTask(theVersion);
|
AddIndexTask task = new AddIndexTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
task.setIndexName(myIndexName);
|
task.setIndexName(myIndexName);
|
||||||
task.setUnique(myUnique);
|
task.setUnique(myUnique);
|
||||||
|
@ -331,7 +335,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ModifyColumnTask task = new ModifyColumnTask(theVersion);
|
ModifyColumnTask task = new ModifyColumnTask(myRelease, theVersion);
|
||||||
task.setColumnName(myColumnName);
|
task.setColumnName(myColumnName);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
if (theLength != null) {
|
if (theLength != null) {
|
||||||
|
@ -361,7 +365,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void references(String theVersion, String theForeignTable, String theForeignColumn) {
|
public void references(String theVersion, String theForeignTable, String theForeignColumn) {
|
||||||
AddForeignKeyTask task = new AddForeignKeyTask(theVersion);
|
AddForeignKeyTask task = new AddForeignKeyTask(myRelease, theVersion);
|
||||||
task.setTableName(myTableName);
|
task.setTableName(myTableName);
|
||||||
task.setConstraintName(myForeignKeyName);
|
task.setConstraintName(myForeignKeyName);
|
||||||
task.setColumnName(getColumnName());
|
task.setColumnName(getColumnName());
|
||||||
|
@ -373,26 +377,34 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BuilderAddColumnWithName {
|
public static class BuilderAddColumnWithName {
|
||||||
|
private final String myRelease;
|
||||||
|
private final String myVersion;
|
||||||
private final String myColumnName;
|
private final String myColumnName;
|
||||||
private final IAcceptsTasks myTaskSink;
|
private final IAcceptsTasks myTaskSink;
|
||||||
|
|
||||||
public BuilderAddColumnWithName(String theColumnName, IAcceptsTasks theTaskSink) {
|
public BuilderAddColumnWithName(String theRelease, String theVersion, String theColumnName, IAcceptsTasks theTaskSink) {
|
||||||
|
myRelease = theRelease;
|
||||||
|
myVersion = theVersion;
|
||||||
myColumnName = theColumnName;
|
myColumnName = theColumnName;
|
||||||
myTaskSink = theTaskSink;
|
myTaskSink = theTaskSink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddColumnWithNameNullable nullable() {
|
public BuilderAddColumnWithNameNullable nullable() {
|
||||||
return new BuilderAddColumnWithNameNullable(true);
|
return new BuilderAddColumnWithNameNullable(myRelease, myVersion, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddColumnWithNameNullable nonNullable() {
|
public BuilderAddColumnWithNameNullable nonNullable() {
|
||||||
return new BuilderAddColumnWithNameNullable(false);
|
return new BuilderAddColumnWithNameNullable(myRelease, myVersion, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BuilderAddColumnWithNameNullable {
|
public class BuilderAddColumnWithNameNullable {
|
||||||
private final boolean myNullable;
|
private final boolean myNullable;
|
||||||
|
private final String myRelease;
|
||||||
|
private final String myVersion;
|
||||||
|
|
||||||
public BuilderAddColumnWithNameNullable(boolean theNullable) {
|
public BuilderAddColumnWithNameNullable(String theRelease, String theVersion, boolean theNullable) {
|
||||||
|
myRelease = theRelease;
|
||||||
|
myVersion = theVersion;
|
||||||
myNullable = theNullable;
|
myNullable = theNullable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +413,7 @@ public class BaseMigrationTasks<T extends Enum> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
|
public void type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
|
||||||
AddColumnTask task = new AddColumnTask();
|
AddColumnTask task = new AddColumnTask(myRelease, myVersion);
|
||||||
task.setColumnName(myColumnName);
|
task.setColumnName(myColumnName);
|
||||||
task.setNullable(myNullable);
|
task.setNullable(myNullable);
|
||||||
task.setColumnType(theColumnType);
|
task.setColumnType(theColumnType);
|
||||||
|
|
Loading…
Reference in New Issue