-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #441 migrate thirdPartySharing string values to boolean
- Loading branch information
1 parent
ccdc133
commit 12b848b
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package migrate | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/bb-consent/api/internal/dataagreement" | ||
"github.com/bb-consent/api/internal/policy" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func Migrate() { | ||
migrateThirdPartyDataSharingToTrueInPolicyCollection() | ||
migrateThirdPartyDataSharingToTrueInDataAgreementsCollection() | ||
} | ||
|
||
func migrateThirdPartyDataSharingToTrueInPolicyCollection() { | ||
policyCollection := policy.Collection() | ||
|
||
filter := bson.M{"thirdpartydatasharing": ""} | ||
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": ""} | ||
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 | ||
|
||
} |