Skip to content

Commit

Permalink
Upd: Make migrations idempotent
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed Nov 2, 2023
1 parent 12b848b commit d6d56e0
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions internal/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

0 comments on commit d6d56e0

Please sign in to comment.