From a205093e2400d074d9b4cb86c4f0ce86bb909c08 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Wed, 1 Nov 2023 18:47:51 +0530 Subject: [PATCH] avniproject/avni-client#1161 | Create migation to remove individuals with lowestAddressLevel = null --- src/Schema.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Schema.js b/src/Schema.js index 002fa12..bd556aa 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -186,7 +186,7 @@ const entities = [ function createRealmConfig() { return { //order is important, should be arranged according to the dependency - schemaVersion: 179, + schemaVersion: 180, onMigration: function (oldDB, newDB) { console.log("[AvniModels.Schema]", `Running migration with old schema version: ${oldDB.schemaVersion} and new schema version: ${newDB.schemaVersion}`); if (oldDB.schemaVersion < 10) { @@ -795,6 +795,15 @@ function createRealmConfig() { } }); } + if (oldDB.schemaVersion < 180) { + General.logDebug("Migration180", "Migration execution started") + const individualsOfInterest = newDB.objects(Individual.schema.name).filtered("lowestAddressLevel = null"); + _.forEach(individualsOfInterest, (individual) => { + General.logDebug("Migration180", "Deleting individual " + individual.uuid) + newDB.delete(individual) + }) + General.logDebug("Migration180", "Migration execution completed") + } }, }; }