() {
@Override
public URL valueOf(PropertyInput propertyInput) {
return propertyInput.getPropertyFilePath();
@@ -167,8 +167,8 @@ public URL valueOf(PropertyInput propertyInput) {
}
});
- if (warnings.notEmpty()) {
- LOG.warn("Warnings on platform configuration file setup; please address in the future, but program will proceed:\n{}", warnings.makeString("\n"));
+ if (debugMessages.notEmpty()) {
+ LOG.debug("Debug notices on platform configuration file setup:\n{}", debugMessages.makeString("\n"));
}
if (errors.notEmpty()) {
diff --git a/obevo-core/src/main/java/com/gs/obevo/impl/MainDeployer.kt b/obevo-core/src/main/java/com/gs/obevo/impl/MainDeployer.kt
index 63d68004..68d438dc 100644
--- a/obevo-core/src/main/java/com/gs/obevo/impl/MainDeployer.kt
+++ b/obevo-core/src/main/java/com/gs/obevo/impl/MainDeployer.kt
@@ -15,9 +15,25 @@
*/
package com.gs.obevo.impl
-import com.gs.obevo.api.appdata.*
+import com.gs.obevo.api.appdata.Change
+import com.gs.obevo.api.appdata.ChangeIncremental
+import com.gs.obevo.api.appdata.ChangeKey
+import com.gs.obevo.api.appdata.ChangeRerunnable
+import com.gs.obevo.api.appdata.DeployExecution
+import com.gs.obevo.api.appdata.DeployExecutionImpl
+import com.gs.obevo.api.appdata.DeployExecutionStatus
+import com.gs.obevo.api.appdata.Environment
import com.gs.obevo.api.factory.PlatformConfiguration
-import com.gs.obevo.api.platform.*
+import com.gs.obevo.api.platform.ChangeAuditDao
+import com.gs.obevo.api.platform.ChangeCommand
+import com.gs.obevo.api.platform.CommandExecutionContext
+import com.gs.obevo.api.platform.DeployExecutionDao
+import com.gs.obevo.api.platform.DeployExecutionException
+import com.gs.obevo.api.platform.DeployMetrics
+import com.gs.obevo.api.platform.FailedChange
+import com.gs.obevo.api.platform.GraphExportFormat
+import com.gs.obevo.api.platform.MainDeployerArgs
+import com.gs.obevo.api.platform.Platform
import com.gs.obevo.impl.graph.GraphEnricher
import com.gs.obevo.impl.graph.GraphUtil
import com.gs.obevo.impl.text.TextDependencyExtractableImpl
@@ -35,13 +51,19 @@ import org.eclipse.collections.impl.block.factory.StringFunctions
import org.eclipse.collections.impl.factory.Lists
import org.eclipse.collections.impl.factory.Sets
import org.jgrapht.DirectedGraph
-import org.jgrapht.ext.*
+import org.jgrapht.ext.DOTExporter
+import org.jgrapht.ext.GmlExporter
+import org.jgrapht.ext.GraphMLExporter
+import org.jgrapht.ext.IntegerEdgeNameProvider
+import org.jgrapht.ext.IntegerNameProvider
+import org.jgrapht.ext.MatrixExporter
+import org.jgrapht.ext.VertexNameProvider
import org.jgrapht.graph.DefaultEdge
import org.slf4j.LoggerFactory
import java.io.FileWriter
import java.io.Writer
import java.sql.Timestamp
-import java.util.*
+import java.util.Date
import java.util.concurrent.TimeUnit
/**
@@ -188,23 +210,30 @@ class MainDeployer>(
// TODO refactor into separate method
if (env.platform.isDropOrderRequired) {
+ // In this block, we set the "dependentChanges" field on the drop objects to ensure they can be sorted for dependencies later on
val dropsToEnrich = changePairs
.filter { it.changeKey.changeType.isRerunnable && it.sourceChange == null && it.deployedChange != null }
.map { it.deployedChange!! }
- val drops = dropsToEnrich.map {drop ->
+ val dropsByObjectName = dropsToEnrich.associateBy { env.platform.convertDbObjectName().valueOf(it.objectName) }
+
+ val dropsForTextProcessing = dropsToEnrich.map { drop ->
val sql = changeTypeBehaviorRegistry.getChangeTypeBehavior(drop.changeType).getDefinitionFromEnvironment(drop);
LOG.debug("Found the sql from the DB for dropping: {}", sql)
TextDependencyExtractableImpl(drop.objectName, sql ?: "", drop)
}
- val dropDependencies = this.textDependencyExtractor.calculateDependencies(drops)
-
- drops.forEach { it.codeDependencies = Sets.immutable.ofAll(dropDependencies.get(it)) }
+ val dropDependencies = this.textDependencyExtractor.calculateDependencies(dropsForTextProcessing)
- val dependencyGraph = graphEnricher.createDependencyGraph(sourceChanges, deployerArgs.isRollback)
+ dropsForTextProcessing.forEach { it.codeDependencies = Sets.immutable.ofAll(dropDependencies.get(it)) }
- dropsToEnrich.forEach { it.dependentChanges = GraphUtil.getDependencyNodes(dependencyGraph, it) }
+ for (drop in dropsForTextProcessing) {
+ drop.codeDependencies?.let { deps ->
+ if (deps.notEmpty()) {
+ drop.payload.dependentChanges = Sets.immutable.ofAll(deps.map { dropsByObjectName[it.target] })
+ }
+ }
+ }
}
diff --git a/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractable.kt b/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractable.kt
index b73e8292..3703cc08 100644
--- a/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractable.kt
+++ b/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractable.kt
@@ -37,7 +37,7 @@ interface TextDependencyExtractable {
*
* @since 6.4.0
*/
- val codeDependencies: ImmutableSet
+ val codeDependencies: ImmutableSet?
/**
* The dependencies to exclude from the text. This is to let the user specify the false-positive dependencies that
diff --git a/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractableImpl.kt b/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractableImpl.kt
index 0f0fff68..b8b6ef27 100644
--- a/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractableImpl.kt
+++ b/obevo-core/src/main/java/com/gs/obevo/impl/text/TextDependencyExtractableImpl.kt
@@ -27,7 +27,7 @@ class TextDependencyExtractableImpl (
override val contentForDependencyCalculation: String,
val payload: T
) : TextDependencyExtractable {
- override var codeDependencies: ImmutableSet = Sets.immutable.empty()
+ override var codeDependencies: ImmutableSet? = null
override val excludeDependencies: ImmutableSet
get() = Sets.immutable.empty()
diff --git a/obevo-db-impls/obevo-db-postgresql/obevo-db-postgresql.iml b/obevo-db-impls/obevo-db-postgresql/obevo-db-postgresql.iml
index 19eb5bfe..78c1e2b2 100644
--- a/obevo-db-impls/obevo-db-postgresql/obevo-db-postgresql.iml
+++ b/obevo-db-impls/obevo-db-postgresql/obevo-db-postgresql.iml
@@ -78,6 +78,10 @@
+
+
+
+
diff --git a/obevo-db-impls/obevo-db-postgresql/pom.xml b/obevo-db-impls/obevo-db-postgresql/pom.xml
index 09914838..2b2db99c 100644
--- a/obevo-db-impls/obevo-db-postgresql/pom.xml
+++ b/obevo-db-impls/obevo-db-postgresql/pom.xml
@@ -49,6 +49,21 @@
postgresql
+
+ com.goldmansachs.obevo
+ obevo-db-h2
+ ${project.version}
+ true
+
+
+
+ com.goldmansachs.obevo
+ obevo-db-hsql
+ ${project.version}
+ true
+
+
+
com.goldmansachs.obevo
obevo-db-internal-test-helper
diff --git a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDbPlatform.java b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDbPlatform.java
index f2782aa4..97596992 100644
--- a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDbPlatform.java
+++ b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDbPlatform.java
@@ -1,117 +1,130 @@
-/**
- * Copyright 2017 Goldman Sachs.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.gs.obevo.db.impl.platforms.postgresql;
-
-import com.gs.obevo.api.platform.ChangeType;
-import com.gs.obevo.api.platform.DeployerAppContext;
-import com.gs.obevo.db.api.appdata.GrantTargetType;
-import com.gs.obevo.db.api.platform.DbChangeType;
-import com.gs.obevo.db.api.platform.DbChangeTypeImpl;
-import com.gs.obevo.db.apps.reveng.AbstractDdlReveng;
-import com.gs.obevo.db.impl.platforms.AbstractDbPlatform;
-import org.eclipse.collections.api.block.function.Function;
-import org.eclipse.collections.api.list.ImmutableList;
-import org.eclipse.collections.api.list.MutableList;
-import org.eclipse.collections.api.set.ImmutableSet;
-import org.eclipse.collections.impl.block.factory.Predicates;
-import org.eclipse.collections.impl.block.factory.StringFunctions;
-
-/**
- * PostgreSQL DBMS platform implementation.
- */
-public class PostgreSqlDbPlatform extends AbstractDbPlatform {
- public PostgreSqlDbPlatform() {
- super("POSTGRESQL");
- }
-
- /**
- * Protected constructor to allow for the Amazon-based platforms that leverage PostgreSQL as their SQL interface.
- */
- protected PostgreSqlDbPlatform(String name) {
- super(name);
- }
-
- @Override
- public Class extends DeployerAppContext> initializeAppContextBuilderClass() {
- return PostgreSqlAppContext.class;
- }
-
- @Override
- protected String initializeDefaultDriverClassName() {
- return "org.postgresql.Driver";
- }
-
- @Override
- protected ImmutableList initializeChangeTypes() {
- MutableList changeTypes = super.initializeChangeTypes().toList();
-
- DbChangeType sequenceType = getChangeType(changeTypes, ChangeType.SEQUENCE_STR);
- sequenceType = DbChangeTypeImpl.newDbChangeType(sequenceType).setGrantObjectQualifier("SEQUENCE").build();
- replaceChangeType(changeTypes, sequenceType);
-
- DbChangeType functionType = getChangeType(changeTypes, ChangeType.FUNCTION_STR);
- functionType = DbChangeTypeImpl.newDbChangeType(functionType).setGrantObjectQualifier("FUNCTION").build();
- replaceChangeType(changeTypes, functionType);
-
- return changeTypes.toImmutable();
- }
-
- @Override
- public boolean isDropOrderRequired() {
- return true;
- }
-
- @Override
- protected String getGrantTargetTypeStrDbSpecific(GrantTargetType grantTargetType) {
- // only user must have the blank defined; GROUP can still be specified
- switch (grantTargetType) {
- case USER:
- return "";
- default:
- return grantTargetType.name();
- }
- }
-
- @Override
- public Function convertDbObjectName() {
- return StringFunctions.toLowerCase();
- }
-
- @Override
- public String getNullMarkerForCreateTable() {
- return ""; // for DB2 create statement, a blank implies NULL. Adding NULL explicitly was not allowed prior to
- // v9.7, so we leave this here
- }
-
- @Override
- public String getTimestampType() {
- return "TIMESTAMP";
- }
-
- @Override
- public ImmutableSet getRequiredValidationObjectTypes() {
- // there is currently a quirk w/ PostgreSQL where view SQL definitions will not have the objects qualified w/
- // the schema name in the connection that creates the SQL; but in subsequent connections, it will be qualified.
- // Until we work out this issue, we will exclude views from PostgreSQL processing.
- return super.getRequiredValidationObjectTypes()
- .reject(Predicates.equal(ChangeType.VIEW_STR));
- }
-
- @Override
- public AbstractDdlReveng getDdlReveng() {
- return new PostgreSqlPgDumpReveng();
- }
-}
+/**
+ * Copyright 2017 Goldman Sachs.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.gs.obevo.db.impl.platforms.postgresql;
+
+import com.gs.obevo.api.platform.ChangeType;
+import com.gs.obevo.api.platform.DeployerAppContext;
+import com.gs.obevo.db.api.appdata.GrantTargetType;
+import com.gs.obevo.db.api.platform.DbChangeType;
+import com.gs.obevo.db.api.platform.DbChangeTypeImpl;
+import com.gs.obevo.db.api.platform.DbPlatform;
+import com.gs.obevo.db.api.platform.DbTranslationDialect;
+import com.gs.obevo.db.apps.reveng.AbstractDdlReveng;
+import com.gs.obevo.db.impl.platforms.AbstractDbPlatform;
+import org.eclipse.collections.api.block.function.Function;
+import org.eclipse.collections.api.list.ImmutableList;
+import org.eclipse.collections.api.list.MutableList;
+import org.eclipse.collections.api.set.ImmutableSet;
+import org.eclipse.collections.impl.block.factory.Predicates;
+import org.eclipse.collections.impl.block.factory.StringFunctions;
+
+/**
+ * PostgreSQL DBMS platform implementation.
+ */
+public class PostgreSqlDbPlatform extends AbstractDbPlatform {
+ public PostgreSqlDbPlatform() {
+ super("POSTGRESQL");
+ }
+
+ /**
+ * Protected constructor to allow for the Amazon-based platforms that leverage PostgreSQL as their SQL interface.
+ */
+ protected PostgreSqlDbPlatform(String name) {
+ super(name);
+ }
+
+ @Override
+ public Class extends DeployerAppContext> initializeAppContextBuilderClass() {
+ return PostgreSqlAppContext.class;
+ }
+
+ @Override
+ protected String initializeDefaultDriverClassName() {
+ return "org.postgresql.Driver";
+ }
+
+ @Override
+ protected ImmutableList initializeChangeTypes() {
+ MutableList changeTypes = super.initializeChangeTypes().toList();
+
+ DbChangeType sequenceType = getChangeType(changeTypes, ChangeType.SEQUENCE_STR);
+ sequenceType = DbChangeTypeImpl.newDbChangeType(sequenceType).setGrantObjectQualifier("SEQUENCE").build();
+ replaceChangeType(changeTypes, sequenceType);
+
+ DbChangeType functionType = getChangeType(changeTypes, ChangeType.FUNCTION_STR);
+ functionType = DbChangeTypeImpl.newDbChangeType(functionType).setGrantObjectQualifier("FUNCTION").build();
+ replaceChangeType(changeTypes, functionType);
+
+ DbChangeType typeType = DbChangeTypeImpl.newDbChangeType(ChangeType.USERTYPE_STR, true, 1, "TYPE").build();
+ changeTypes.add(typeType);
+
+ return changeTypes.toImmutable();
+ }
+
+ @Override
+ public boolean isDropOrderRequired() {
+ return true;
+ }
+
+ @Override
+ protected String getGrantTargetTypeStrDbSpecific(GrantTargetType grantTargetType) {
+ // only user must have the blank defined; GROUP can still be specified
+ switch (grantTargetType) {
+ case USER:
+ return "";
+ default:
+ return grantTargetType.name();
+ }
+ }
+
+ @Override
+ public Function convertDbObjectName() {
+ return StringFunctions.toLowerCase();
+ }
+
+ @Override
+ public String getNullMarkerForCreateTable() {
+ return "";
+ }
+
+ @Override
+ public String getTimestampType() {
+ return "TIMESTAMP";
+ }
+
+ @Override
+ public ImmutableSet getRequiredValidationObjectTypes() {
+ // there is currently a quirk w/ PostgreSQL where view SQL definitions will not have the objects qualified w/
+ // the schema name in the connection that creates the SQL; but in subsequent connections, it will be qualified.
+ // Until we work out this issue, we will exclude views from PostgreSQL processing.
+ return super.getRequiredValidationObjectTypes()
+ .reject(Predicates.equal(ChangeType.VIEW_STR));
+ }
+
+ @Override
+ public AbstractDdlReveng getDdlReveng() {
+ return new PostgreSqlPgDumpReveng();
+ }
+
+ @Override
+ public DbTranslationDialect getDbTranslationDialect(DbPlatform targetDialect) {
+ if (targetDialect.getClass().getName().equals("com.gs.obevo.db.impl.platforms.hsql.HsqlDbPlatform")) {
+ return new PostgreSqlToHsqlTranslationDialect();
+ } else {
+ return super.getDbTranslationDialect(targetDialect);
+ }
+ }
+}
diff --git a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlPgDumpReveng.java b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlPgDumpReveng.java
index bbf7bd2b..f9729559 100644
--- a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlPgDumpReveng.java
+++ b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlPgDumpReveng.java
@@ -56,9 +56,10 @@ public class PostgreSqlPgDumpReveng extends AbstractDdlReveng {
}
private static ImmutableList getRevengPatterns() {
- String schemaNameSubPattern = getObjectPattern("", "");
+ String schemaNameSubPattern = getSchemaObjectPattern("", "");
+ String objectNameSubPattern = getObjectPattern("", "");
- NamePatternType namePatternType = NamePatternType.ONE;
+ NamePatternType namePatternType = NamePatternType.TWO;
return Lists.immutable.with(
new RevengPattern(ChangeType.SEQUENCE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?sequence\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
@@ -66,33 +67,52 @@ private static ImmutableList getRevengPatterns() {
new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+sequence\\s+" + schemaNameSubPattern + "\\s+owned\\s+by\\s+" + schemaNameSubPattern, 2, 1, null).withPostProcessSql(REMOVE_QUOTES),
new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+(?:unique\\s+)index\\s+" + schemaNameSubPattern + "\\s+on\\s+" + schemaNameSubPattern, 2, 1, "INDEX").withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
new RevengPattern(ChangeType.FUNCTION_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?function\\s+" + schemaNameSubPattern),
+ new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?procedure\\s+" + schemaNameSubPattern),
new RevengPattern(ChangeType.VIEW_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?view\\s+" + schemaNameSubPattern),
new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)procedure\\s+" + schemaNameSubPattern),
new RevengPattern(ChangeType.PACKAGE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)package\\s+" + schemaNameSubPattern),
- new RevengPattern(ChangeType.TRIGGER_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+trigger\\s+" + schemaNameSubPattern)
+ new RevengPattern(ChangeType.TRIGGER_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+trigger\\s+" + schemaNameSubPattern),
+ new RevengPattern(ChangeType.USERTYPE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?type\\s+" + schemaNameSubPattern)
);
}
@Override
protected boolean doRevengOrInstructions(PrintStream out, AquaRevengArgs args, File interimDir) {
- out.println("1) Run the following command to generate the DDL file:");
- out.println(getCommandWithDefaults(args, "", "", "", "", "", "", ""));
- out.println("");
+ out.println("1) Create the folder for your interim output:");
+ out.println();
+ out.println("mkdir -p " + interimDir.getAbsolutePath());
+ out.println();
+ out.println();
+ out.println("2) Run the following command to generate the DDL file:");
+ out.println();
+ out.println("(without Docker)");
+ out.println(getCommandWithDefaults(false, args, interimDir, "", "", "", "", "", "", ""));
+ out.println();
+ out.println("(with Docker)");
+ out.println(getCommandWithDefaults(true, args, interimDir, "", "", "", "", "", "", ""));
+ out.println();
out.println("Here is an example command (in case your values are not filled in):");
- out.println(getCommandWithDefaults(args, "myuser", "mypassword", "myhost.myplace.com", "12345", "mydb", "myschema", "H:\\sybase-ddl-output.txt"));
- out.println("");
- out.println("The pg_dump command will ");
+ out.println();
+ out.println("(without Docker)");
+ out.println(getCommandWithDefaults(false, args, interimDir, "myuser", "mypassword", "myhost.myplace.com", "12345", "mydb", "myschema", "H:\\sybase-ddl-output.txt"));
+ out.println();
+ out.println("(with Docker)");
+ out.println(getCommandWithDefaults(true, args, interimDir, "myuser", "mypassword", "myhost.myplace.com", "12345", "mydb", "myschema", "H:\\sybase-ddl-output.txt"));
+ out.println();
return false;
}
- private String getCommandWithDefaults(AquaRevengArgs args, String username, String password, String dbHost, String dbPort, String dbName, String dbSchema, String outputDirectory) {
- return "pg_dump -O --disable-dollar-quoting -s" +
+ private String getCommandWithDefaults(boolean container, AquaRevengArgs args, File interimDir, String username, String password, String dbHost, String dbPort, String dbName, String dbSchema, String outputDirectory) {
+ String prefix = container ? "docker exec $CONTAINER_NAME " : "";
+ String fileSuffix = container ? "> " : " -f ";
+ fileSuffix += new File(interimDir, "revengoutput.txt").getAbsolutePath();
+ return prefix + "pg_dump -O -s --no-privileges" +
" -h " + ObjectUtils.defaultIfNull(args.getDbHost(), dbHost) +
" -p " + ObjectUtils.defaultIfNull(args.getDbPort(), dbPort) +
" --username=" + ObjectUtils.defaultIfNull(args.getUsername(), username) +
" -d " + ObjectUtils.defaultIfNull(args.getDbServer(), dbName) +
" -n " + ObjectUtils.defaultIfNull(args.getDbSchema(), dbSchema) +
- " -f " + ObjectUtils.defaultIfNull(args.getOutputPath(), outputDirectory);
+ " " + fileSuffix;
}
}
diff --git a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToH2TranslationDialect.java b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToH2TranslationDialect.java
new file mode 100644
index 00000000..d2efcbbd
--- /dev/null
+++ b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToH2TranslationDialect.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2017 Goldman Sachs.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.gs.obevo.db.impl.platforms.postgresql;
+
+import com.gs.obevo.db.impl.platforms.DefaultDbTranslationDialect;
+import org.eclipse.collections.api.list.ImmutableList;
+import org.eclipse.collections.impl.factory.Lists;
+
+public class PostgreSqlToH2TranslationDialect extends DefaultDbTranslationDialect {
+ @Override
+ public ImmutableList getInitSqls() {
+ return Lists.immutable.with("SET MODE PostgreSQL");
+ }
+}
diff --git a/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToHsqlTranslationDialect.java b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToHsqlTranslationDialect.java
new file mode 100644
index 00000000..df351769
--- /dev/null
+++ b/obevo-db-impls/obevo-db-postgresql/src/main/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlToHsqlTranslationDialect.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright 2017 Goldman Sachs.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.gs.obevo.db.impl.platforms.postgresql;
+
+import java.sql.Connection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.gs.obevo.api.platform.ChangeType;
+import com.gs.obevo.db.impl.core.jdbc.JdbcHelper;
+import com.gs.obevo.db.impl.platforms.DefaultDbTranslationDialect;
+import com.gs.obevo.db.impl.platforms.sqltranslator.InMemoryTranslator;
+import com.gs.obevo.db.impl.platforms.sqltranslator.PostColumnSqlTranslator;
+import com.gs.obevo.db.impl.platforms.sqltranslator.PreParsedSqlTranslator;
+import com.gs.obevo.db.impl.platforms.sqltranslator.SqlTranslatorConfigHelper;
+import com.gs.obevo.db.sqlparser.syntaxparser.CreateTable;
+import com.gs.obevo.db.sqlparser.syntaxparser.CreateTableColumn;
+import com.gs.obevo.impl.PrepareDbChange;
+import org.eclipse.collections.api.list.ImmutableList;
+import org.eclipse.collections.api.set.ImmutableSet;
+import org.eclipse.collections.impl.factory.Lists;
+import org.eclipse.collections.impl.factory.Sets;
+
+public class PostgreSqlToHsqlTranslationDialect extends DefaultDbTranslationDialect {
+ private final PostColumnSqlTranslator replaceNextvalWithIdentity = new PostColumnSqlTranslator() {
+ private final Pattern defaultPattern = Pattern.compile("(?i)default\\s+nextval.*", Pattern.DOTALL);
+
+ @Override
+ public String handlePostColumnText(String postColumnText, CreateTableColumn column, CreateTable table) {
+ Matcher defaultMatcher = defaultPattern.matcher(postColumnText);
+ if (defaultMatcher.find()) {
+ postColumnText = defaultMatcher.replaceFirst("IDENTITY");
+ }
+
+ return postColumnText;
+ }
+ };
+
+ private final PreParsedSqlTranslator substituteCreateOrReplace = new PreParsedSqlTranslator() {
+ Pattern pattern = Pattern.compile("(?i)^\\s*create\\s+or\\s+replace\\s+", Pattern.DOTALL);
+ @Override
+ public String preprocessSql(String sql) {
+ Matcher matcher = pattern.matcher(sql);
+ if (matcher.find()) {
+ sql = matcher.replaceFirst("create ");
+ }
+ return sql;
+ }
+ };
+
+ @Override
+ public ImmutableList getInitSqls() {
+ return Lists.immutable.with(
+ "SET DATABASE SQL SYNTAX PGS TRUE"
+ , "SET DATABASE TRANSACTION CONTROL MVCC"
+ );
+ }
+
+ @Override
+ public ImmutableList getAdditionalTranslators() {
+ SqlTranslatorConfigHelper configHelper = SqlTranslatorConfigHelper.createInMemoryDefault();
+
+ configHelper.getPreParsedSqlTranslators()
+ .with(substituteCreateOrReplace);
+ configHelper.getPostColumnSqlTranslators()
+ .with(replaceNextvalWithIdentity);
+ return Lists.immutable.with(new InMemoryTranslator(configHelper));
+ }
+
+ @Override
+ public void initSchema(JdbcHelper jdbc, Connection conn) {
+ updateAndIgnoreException(conn, jdbc, "create type int4 as integer");
+ }
+
+ @Override
+ public ImmutableSet getDisabledChangeTypeNames() {
+ return Sets.immutable.of(ChangeType.FUNCTION_STR, ChangeType.SP_STR);
+ }
+}
diff --git a/obevo-db-impls/obevo-db-postgresql/src/test/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDeployerIT.java b/obevo-db-impls/obevo-db-postgresql/src/test/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDeployerIT.java
index bb85f47f..f9de46fd 100644
--- a/obevo-db-impls/obevo-db-postgresql/src/test/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDeployerIT.java
+++ b/obevo-db-impls/obevo-db-postgresql/src/test/java/com/gs/obevo/db/impl/platforms/postgresql/PostgreSqlDeployerIT.java
@@ -1,89 +1,88 @@
-/**
- * Copyright 2017 Goldman Sachs.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.gs.obevo.db.impl.platforms.postgresql;
-
-import java.sql.Connection;
-import java.sql.Timestamp;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import com.gs.obevo.db.api.platform.DbDeployerAppContext;
-import com.gs.obevo.db.impl.core.jdbc.JdbcHelper;
-import org.apache.commons.dbutils.DbUtils;
-import org.eclipse.collections.api.block.function.primitive.IntToObjectFunction;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Parameterized.class)
-public class PostgreSqlDeployerIT {
- @Parameterized.Parameters
- public static Iterable