Skip to content

Commit 5c015b2

Browse files
committed
Do not try to migrate view fields on enum change
1 parent 1c1f890 commit 5c015b2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

core/src/main/java/ch/ergon/adam/core/db/DefaultMigrationStrategy.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ch.ergon.adam.core.helper.Pair;
77

88
import java.util.LinkedHashSet;
9+
import java.util.List;
910
import java.util.Set;
1011

1112
import static java.util.Comparator.comparing;
@@ -29,7 +30,7 @@ public class DefaultMigrationStrategy implements MigrationStrategy {
2930
Set<View> viewsToDrop = new LinkedHashSet<>();
3031
Set<DbEnum> enumsToCreate = new LinkedHashSet<>();
3132
Set<DbEnum> enumsToUpdate = new LinkedHashSet<>();
32-
Set<Field> fieldsToChangeTypeForEnumMigration = new LinkedHashSet<>();
33+
Set<Field> tableFieldsToChangeTypeForEnumMigration = new LinkedHashSet<>();
3334
Set<DbEnum> enumsToDrop = new LinkedHashSet<>();
3435
Set<Constraint> constraintsToDrop = new LinkedHashSet<>();
3536
Set<Constraint> constraintsToCreate = new LinkedHashSet<>();
@@ -214,7 +215,10 @@ public void enumRemoved(DbEnum oldEnum) {
214215
public void enumUpdated(DbEnum oldEnum, DbEnum newEnum) {
215216
enumsToUpdate.add(oldEnum);
216217
enumsToCreate.add(newEnum);
217-
fieldsToChangeTypeForEnumMigration.addAll(oldEnum.getReferencingFields());
218+
List<Field> referencingTableFields = oldEnum.getReferencingFields().stream()
219+
.filter(f -> f.getContainer() instanceof Table)
220+
.collect(toList());
221+
tableFieldsToChangeTypeForEnumMigration.addAll(referencingTableFields);
218222
}
219223

220224
@Override
@@ -275,7 +279,7 @@ public void apply(SchemaSink sink) {
275279

276280
sequencesToDrop.forEach(sink::dropSequence);
277281

278-
fieldsToChangeTypeForEnumMigration.forEach(field -> {
282+
tableFieldsToChangeTypeForEnumMigration.forEach(field -> {
279283
sink.dropDefault(field);
280284
sink.changeFieldType(field, field, DataType.CLOB);
281285
});
@@ -284,7 +288,7 @@ public void apply(SchemaSink sink) {
284288

285289
enumsToCreate.forEach(sink::createEnum);
286290

287-
fieldsToChangeTypeForEnumMigration.forEach(field -> {
291+
tableFieldsToChangeTypeForEnumMigration.forEach(field -> {
288292
sink.changeFieldType(field, field, field.getDataType());
289293
sink.setDefault(field);
290294
});

0 commit comments

Comments
 (0)