From 593cba725091749fbe088cdcc6f1efa1f1492a5e Mon Sep 17 00:00:00 2001 From: sondermanish Date: Tue, 7 Jan 2025 17:38:51 +0530 Subject: [PATCH] added client side migration --- .../migrations/JsonSchemaMigration.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java index c5cb0f0843f..8d72075c6a4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java @@ -68,11 +68,35 @@ public Mono migrateApplicationJsonToLatestSchema( return Mono.empty(); } - return migrateServerSchema(applicationJson, baseApplicationId, refName); + return migrateClientSchema(appJson, baseApplicationId, refName) + .flatMap(clientJson -> migrateServerSchema(clientJson, baseApplicationId, refName)); }) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON))); } + private Mono migrateClientSchema( + ApplicationJson applicationJson, String baseApplicationId, String branchName) { + + Mono migrateApplicationJsonMono = Mono.just(applicationJson); + if (jsonSchemaVersions.getClientVersion().equals(applicationJson.getClientSchemaVersion())) { + return migrateApplicationJsonMono; + } + + // Run migration linearly + // Updating the schema version after each migration is not required as we are not exiting by breaking the switch + // cases, but this keeps the version number and the migration in sync + switch (applicationJson.getClientSchemaVersion()) { + case 0: + applicationJson.setClientSchemaVersion(1); + case 1: + applicationJson.setClientSchemaVersion(2); + default: + } + + applicationJson.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + return migrateApplicationJsonMono; + } + /** * This method may be moved to the publisher chain itself *