6
6
import ch .ergon .adam .core .helper .Pair ;
7
7
8
8
import java .util .LinkedHashSet ;
9
+ import java .util .List ;
9
10
import java .util .Set ;
10
11
11
12
import static java .util .Comparator .comparing ;
@@ -29,7 +30,7 @@ public class DefaultMigrationStrategy implements MigrationStrategy {
29
30
Set <View > viewsToDrop = new LinkedHashSet <>();
30
31
Set <DbEnum > enumsToCreate = new LinkedHashSet <>();
31
32
Set <DbEnum > enumsToUpdate = new LinkedHashSet <>();
32
- Set <Field > fieldsToChangeTypeForEnumMigration = new LinkedHashSet <>();
33
+ Set <Field > tableFieldsToChangeTypeForEnumMigration = new LinkedHashSet <>();
33
34
Set <DbEnum > enumsToDrop = new LinkedHashSet <>();
34
35
Set <Constraint > constraintsToDrop = new LinkedHashSet <>();
35
36
Set <Constraint > constraintsToCreate = new LinkedHashSet <>();
@@ -214,7 +215,10 @@ public void enumRemoved(DbEnum oldEnum) {
214
215
public void enumUpdated (DbEnum oldEnum , DbEnum newEnum ) {
215
216
enumsToUpdate .add (oldEnum );
216
217
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 );
218
222
}
219
223
220
224
@ Override
@@ -275,7 +279,7 @@ public void apply(SchemaSink sink) {
275
279
276
280
sequencesToDrop .forEach (sink ::dropSequence );
277
281
278
- fieldsToChangeTypeForEnumMigration .forEach (field -> {
282
+ tableFieldsToChangeTypeForEnumMigration .forEach (field -> {
279
283
sink .dropDefault (field );
280
284
sink .changeFieldType (field , field , DataType .CLOB );
281
285
});
@@ -284,7 +288,7 @@ public void apply(SchemaSink sink) {
284
288
285
289
enumsToCreate .forEach (sink ::createEnum );
286
290
287
- fieldsToChangeTypeForEnumMigration .forEach (field -> {
291
+ tableFieldsToChangeTypeForEnumMigration .forEach (field -> {
288
292
sink .changeFieldType (field , field , field .getDataType ());
289
293
sink .setDefault (field );
290
294
});
0 commit comments