From d6d56e036bc7ac45bb217d09b6a82f195ce74554 Mon Sep 17 00:00:00 2001 From: George J Padayatti Date: Thu, 2 Nov 2023 16:11:02 +0530 Subject: [PATCH] Upd: Make migrations idempotent Signed-off-by: George J Padayatti --- internal/migrate/migrate.go | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/internal/migrate/migrate.go b/internal/migrate/migrate.go index 662d9b5..faf6ff7 100644 --- a/internal/migrate/migrate.go +++ b/internal/migrate/migrate.go @@ -17,52 +17,23 @@ func Migrate() { func migrateThirdPartyDataSharingToTrueInPolicyCollection() { policyCollection := policy.Collection() - filter := bson.M{"thirdpartydatasharing": ""} + filter := bson.M{"thirdpartydatasharing": bson.M{"$nin": []interface{}{true, false}}} update := bson.M{"$set": bson.M{"thirdpartydatasharing": true}} _, err := policyCollection.UpdateMany(context.TODO(), filter, update) if err != nil { fmt.Println(err) } - filter = bson.M{"thirdpartydatasharing": "true"} - update = bson.M{"$set": bson.M{"thirdpartydatasharing": true}} - _, err = policyCollection.UpdateMany(context.TODO(), filter, update) - if err != nil { - fmt.Println(err) - } - filter = bson.M{"thirdpartydatasharing": "false"} - update = bson.M{"$set": bson.M{"thirdpartydatasharing": true}} - _, err = policyCollection.UpdateMany(context.TODO(), filter, update) - if err != nil { - fmt.Println(err) - } } func migrateThirdPartyDataSharingToTrueInDataAgreementsCollection() { dataAgreementCollection := dataagreement.Collection() - filter := bson.M{"policy.thirdpartydatasharing": ""} + filter := bson.M{"policy.thirdpartydatasharing": bson.M{"$nin": []interface{}{true, false}}} update := bson.M{"$set": bson.M{"policy.thirdpartydatasharing": true}} _, err := dataAgreementCollection.UpdateMany(context.TODO(), filter, update) if err != nil { fmt.Println(err) } - - filter = bson.M{"policy.thirdpartydatasharing": "true"} - update = bson.M{"$set": bson.M{"policy.thirdpartydatasharing": true}} - - _, err = dataAgreementCollection.UpdateMany(context.TODO(), filter, update) - if err != nil { - fmt.Println(err) - } - - filter = bson.M{"policy.thirdpartydatasharing": "false"} - update = bson.M{"$set": bson.M{"policy.thirdpartydatasharing": true}} - - _, err = dataAgreementCollection.UpdateMany(context.TODO(), filter, update) - if err != nil { - fmt.Println(err) - } // TODO: Handle impact towards revisions - }