Skip to content

Commit

Permalink
Merge pull request #212 from AdaptiveScale/release-2.2.2
Browse files Browse the repository at this point in the history
Release 2.2.2
  • Loading branch information
nbesimi authored Apr 24, 2024
2 parents f35fac1 + eeeeb8e commit 714979c
Show file tree
Hide file tree
Showing 13 changed files with 482 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = 'com.adaptivescale'
version = '2.2.1'
version = '2.2.2'
sourceCompatibility = 11
targetCompatibility = 11
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
@Slf4j
@CommandLine.Command(name = "cli",
mixinStandardHelpOptions = true,
version = "2.2.1",
version = "2.2.2",
description = "Declarative Database Management - DDL Transpiler"
)
class Cli implements Callable<Void> {
Expand Down Expand Up @@ -400,7 +400,7 @@ private void diff(@CommandLine.Option(names = {"-s", "--source"}) String sourceN
Database localDatabase = databases.get(0);
Database targetDatabase = SourceGeneratorFactory.sourceGenerator(sourceConnection).generate(sourceConnection);

Diff<List<String>, Database, Database> tester = DiffFactory.diff();
Diff<List<String>, Database, Database> tester = DiffFactory.diff(localDatabase.getDatabaseType());

List<String> changeList = tester.find(localDatabase, targetDatabase);
if (changeList.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private Map<Integer, List<TranslationAttributeModel>> readTranslationAttributes(
if (translationAttributesMappedByTranslationId.containsKey(translationAttributeModel.getTranslationId())) {
translationAttributesMappedByTranslationId.get(translationAttributeModel.getTranslationId()).add(translationAttributeModel);
} else {
translationAttributesMappedByTranslationId.put(translationAttributeModel.getTranslationId(), Arrays.asList(translationAttributeModel));
translationAttributesMappedByTranslationId.put(translationAttributeModel.getTranslationId(), new ArrayList<>(Arrays.asList(translationAttributeModel)));
}
String insertStatement = translationAttributeModel.generateInsertStatement(TRANSLATION_ATTRIBUTE_TABLE_NAME);
attributesInsertQuery.append(insertStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public enum RosettaModuleTypes {
COLUMN_EXTRACTOR,
TABLE_EXTRACTOR,
VIEW_EXTRACTOR,
DIFF_TESTER,
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,6 @@ public class KineticaForeignKeyChangeComparator implements Comparator<Change<?>>
*/
@Override
public int compare(Change changeA, Change changeB) {

boolean isFKChangeA = changeA.getType() == Change.Type.FOREIGN_KEY;
boolean isFKChangeB = changeB.getType() == Change.Type.FOREIGN_KEY;

boolean isFKDropChangeA = isFKChangeA && changeA.getStatus() == Change.Status.DROP;
boolean isFKDropChangeB = isFKChangeB && changeB.getStatus() == Change.Status.DROP;

if (isFKDropChangeA && isFKDropChangeB) {
return 0;
}

if (isFKDropChangeA) {
return -1;
}

if (isFKDropChangeB) {
return 1;
}

//now changes are not ForeignKey with drop status
if (isFKChangeA && isFKChangeB) {
return 0;
}

if (isFKChangeA) {
return 1;
}

if (isFKChangeB) {
return -1;
}

//if change is drop, put ahead of all other changes
if (changeA.getStatus() == Change.Status.DROP) {
return -1;
}

//other changes we don't care
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
ALTER TABLE "[(${schemaName})]"."[(${tableName})]" ADD FOREIGN KEY ("[(${foreignkeyColumn})]") REFERENCES "[(${primaryTableSchema})]"."[(${primaryTableName})]"("[(${foreignKeyPrimaryColumnName})]") AS [(${foreignkeyName})];
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
ALTER TABLE "[(${schemaName})]"."[(${tableName})]" DROP FOREIGN KEY "[(${foreignkeyName})]";
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.adaptivescale.rosetta.ddl.change.model.Change;
import com.adaptivescale.rosetta.ddl.targets.kinetica.KineticaDDLGenerator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void addColumnWithProperties() throws IOException {
}

@Test
@Disabled
public void addColumnWithForeignKey() throws IOException {
String ddl = generateDDL("add_column_with_foreign_key");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"PLAYER\" ADD \"POSITION_ID\" numeric;\r" +
Expand Down Expand Up @@ -113,40 +115,46 @@ public void alterColumnNewProperty() throws IOException {
}

@Test
@Disabled
public void dropColumnWithForeignKey() throws IOException {
String ddl = generateDDL("drop_column_with_foreign_key");
Assertions.assertEquals("ALTER TABLE \"FBAL\".\"PLAYER\" DROP FOREIGN KEY \"PLAYER_FK\";\r" +
"ALTER TABLE \"FBAL\".\"PLAYER\" DROP COLUMN \"POSITION_ID\";", ddl);
}

@Test
@Disabled
public void dropColumnWithPrimaryKeyReferenced() throws IOException {
String ddl = generateDDL("drop_column_with_primary_key_referenced");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";\r" +
"ALTER TABLE \"ROSETTA\".\"PLAYER\" DROP COLUMN \"ID\";", ddl);
}

@Test
@Disabled
public void dropTableWhereColumnIsReferenced() throws IOException {
String ddl = generateDDL("drop_table_where_column_is_referenced");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK_TEAM\";\r" +
"DROP TABLE IF EXISTS \"ROSETTA\".\"TEAM\";", ddl);
}

@Test
@Disabled
public void addForeignKey() throws IOException {
String ddl = generateDDL("add_foreign_key");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"PLAYER\" ADD FOREIGN KEY (\"POSITION_ID\") " +
"REFERENCES \"ROSETTA\".\"Position\"(\"ID\") AS PLAYER_FK;", ddl);
}

@Test
@Disabled
public void dropForeignKey() throws IOException {
String ddl = generateDDL("drop_foreign_key");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";", ddl);
}

@Test
@Disabled
public void alterForeignKeyName() throws IOException {
String ddl = generateDDL("alter_foreign_key_name");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";\r" +
Expand All @@ -155,13 +163,15 @@ public void alterForeignKeyName() throws IOException {
}

@Test
@Disabled
public void alterForeignKey() throws IOException {
String ddl = generateDDL("alter_foreign_key");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";\r" +
"ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" ADD FOREIGN KEY (\"PLAYERID\") REFERENCES \"ROSETTA\".\"PLAYER\"(\"ID\") AS TEAMPLAYERS_FK;", ddl);
}

@Test
@Disabled
public void dropPrimaryKeyColumnAndAlterForeignKey() throws IOException {
String ddl = generateDDL("drop_pk_column_and_alter_fk");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";\r" +
Expand All @@ -170,6 +180,7 @@ public void dropPrimaryKeyColumnAndAlterForeignKey() throws IOException {
}

@Test
@Disabled
public void dropTableWithPrimaryKeyColumnAndAlterForeignKey() throws IOException {
String ddl = generateDDL("drop_table_with_pk_column_and_alter_fk");
Assertions.assertEquals("ALTER TABLE \"ROSETTA\".\"TEAMPLAYERS\" DROP FOREIGN KEY \"TEAMPLAYERS_FK\";\r" +
Expand Down
20 changes: 18 additions & 2 deletions diff/src/main/java/com/adaptivescale/rosetta/diff/DiffFactory.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
package com.adaptivescale.rosetta.diff;

import com.adaptivescale.rosetta.common.helpers.ModuleLoader;
import com.adaptivescale.rosetta.common.models.Database;
import com.adaptivescale.rosetta.common.types.RosettaModuleTypes;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;

public class DiffFactory {

public static Diff<List<String>,Database, Database> diff(){
return new DefaultTester();
public static Diff<List<String>,Database, Database> diff(String databaseType) {

Optional<Class<?>> diffTester = ModuleLoader.loadModuleByAnnotationClassValues(
DiffFactory.class.getPackageName(), RosettaModuleTypes.DIFF_TESTER, databaseType);

if (diffTester.isEmpty()) {
return new DefaultTester();
}

try {
return (Diff<List<String>, Database, Database>) diffTester.get().getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
Loading

0 comments on commit 714979c

Please sign in to comment.