From 4a075628d7a2b47a321c4f373dff57f2ddb51ecf Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Thu, 23 Dec 2021 15:59:53 +0530 Subject: [PATCH] fix: add work around to handle bad data in Firestore UQI migration (#9966) * add another migration for those Firestore actions that could not be migrated. * handle ClassCastException via try catch and assigning default empty value. --- .../server/migrations/DatabaseChangelog.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java index 8094bf3a18..abe608e1c0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java @@ -3520,7 +3520,14 @@ public class DatabaseChangelog { uqiWhereMap.put(CONDITION_KEY, AND); uqiWhereMap.put(CHILDREN_KEY, new ArrayList<>()); - List> oldListOfConditions = (List>) value; + List> oldListOfConditions; + try { + oldListOfConditions = (List>) value; + } catch (ClassCastException e) { + System.out.println("value: " + value); + oldListOfConditions = new ArrayList<>(); + } + oldListOfConditions.stream() .forEachOrdered(oldCondition -> { /* Map old values to keys in the new UQI format. */ @@ -4536,6 +4543,11 @@ public class DatabaseChangelog { continue; } + /* It means that earlier migration had succeeded on this action, hence current migration can be skipped. */ + if (!CollectionUtils.isEmpty(unpublishedAction.getActionConfiguration().getFormData())) { + continue; + } + List pluginSpecifiedTemplates = unpublishedAction.getActionConfiguration().getPluginSpecifiedTemplates(); UQIMigrationDataTransformer uqiMigrationDataTransformer = new UQIMigrationDataTransformer(); @@ -4692,4 +4704,34 @@ public class DatabaseChangelog { ); } + /** + * This migration was required because migration numbered 104 failed on prod due to ClassCastException on some + * unexpected / bad older data. + */ + @ChangeSet(order = "107", id = "migrate-firestore-to-uqi-3", author = "") + public void migrateFirestorePluginToUqi3(MongockTemplate mongockTemplate) { + // Update Firestore plugin to indicate use of UQI schema + Plugin firestorePlugin = mongockTemplate.findOne( + query(where("packageName").is("firestore-plugin")), + Plugin.class + ); + firestorePlugin.setUiComponent("UQIDbEditorForm"); + + // Find all Firestore actions + final Query firestoreActionQuery = query( + where(fieldName(QNewAction.newAction.pluginId)).is(firestorePlugin.getId()) + .and(fieldName(QNewAction.newAction.deleted)).ne(true)); // setting `deleted` != `true` + firestoreActionQuery.fields() + .include(fieldName(QNewAction.newAction.id)); + + List firestoreActions = mongockTemplate.find( + firestoreActionQuery, + NewAction.class + ); + + migrateFirestoreToUQI(mongockTemplate, firestoreActions); + + // Update plugin data. + mongockTemplate.save(firestorePlugin); + } }