#1787 - Update CockroachDB support for DDL generation with autocommit and no history support

This commit is contained in:
rob bygrave
2019-08-08 23:22:58 +12:00
parent 762899ef10
commit cb6f0335b1
7 changed files with 15 additions and 17 deletions
@@ -577,7 +577,7 @@ public class DatabasePlatform {
/**
* Normally not needed - overridden in CockroachPlatform.
*/
public boolean isDdlCommitOnCreateIndex() {
public boolean isDdlAutoCommit() {
return false;
}
@@ -21,7 +21,7 @@ public class CockroachPlatform extends PostgresPlatform {
* Needs a commit after create index such that alter table add foreign key ... succeeds.
*/
@Override
public boolean isDdlCommitOnCreateIndex() {
public boolean isDdlAutoCommit() {
return true;
}
@@ -44,7 +44,7 @@ public class DdlGenerator {
private final boolean extraDdl;
private final boolean createOnly;
private final boolean jaxbPresent;
private final boolean ddlCommitOnCreateIndex;
private final boolean ddlAutoCommit;
private final String dbSchema;
private final ScriptTransform scriptTransform;
@@ -63,10 +63,10 @@ public class DdlGenerator {
if (!serverConfig.getTenantMode().isDdlEnabled() && serverConfig.isDdlRun()) {
log.warn("DDL can't be run on startup with TenantMode " + serverConfig.getTenantMode());
this.runDdl = false;
this.ddlCommitOnCreateIndex = false;
this.ddlAutoCommit = false;
} else {
this.runDdl = serverConfig.isDdlRun();
this.ddlCommitOnCreateIndex = server.getDatabasePlatform().isDdlCommitOnCreateIndex();
this.ddlAutoCommit = server.getDatabasePlatform().isDdlAutoCommit();
}
this.scriptTransform = createScriptTransform(serverConfig.getMigrationConfig());
this.baseDir = initBaseDir();
@@ -160,13 +160,11 @@ public class DdlGenerator {
DdlRunner runner = new DdlRunner(expectErrors, scriptName);
try {
if (expectErrors) {
if (expectErrors || ddlAutoCommit) {
connection.setAutoCommit(true);
} else if (ddlCommitOnCreateIndex) {
runner.setCommitOnCreateIndex();
}
int count = runner.runAll(scriptTransform.transform(content), connection);
if (expectErrors) {
if (expectErrors || ddlAutoCommit) {
connection.setAutoCommit(false);
}
connection.commit();
@@ -10,7 +10,6 @@ public class CockroachDdl extends PlatformDdl {
public CockroachDdl(DatabasePlatform platform) {
super(platform);
this.historyDdl = new PostgresHistoryDdl();
this.dropTableCascade = " cascade";
this.columnSetType = "type ";
this.alterTableIfExists = "if exists ";
@@ -33,7 +33,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
protected String currentTimestamp = "now(6)";
protected String sysPeriodType = "datetime(6)";
public DbTriggerBasedHistoryDdl() {
DbTriggerBasedHistoryDdl() {
}
@Override
@@ -252,7 +252,6 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
protected void appendColumnNames(DdlBuffer buffer, List<String> columns, String columnPrefix) throws IOException {
for (int i = 0; i < columns.size(); i++) {
if (i > 0) {
buffer.append(", ");
@@ -266,7 +265,6 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
* Append a single column to the buffer if it is not null.
*/
protected void appendColumnName(DdlBuffer buffer, String prefix, String columnName) throws IOException {
if (columnName != null) {
buffer.append(prefix).append(columnName);
}
@@ -281,7 +279,6 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
* </p>
*/
protected List<String> columnNamesForApply(MTable table) {
return table.allHistoryColumns(true);
}