Patch backfill data

This commit is contained in:
Maidul Islam
2023-06-05 20:19:15 -07:00
parent 08868681d8
commit b0e7304bff
+23 -7
View File
@@ -335,6 +335,19 @@ export const backfillSecretFolders = async () => {
} }
); );
await SecretVersion.updateMany(
{
folder: {
$exists: false,
},
},
{
$set: {
folder: "root",
},
}
);
let secretSnapshots = await SecretSnapshot.find({ let secretSnapshots = await SecretSnapshot.find({
environment: { environment: {
$exists: false, $exists: false,
@@ -352,12 +365,15 @@ export const backfillSecretFolders = async () => {
groupSnapByEnv[secVer.environment].push(secVer); groupSnapByEnv[secVer.environment].push(secVer);
}); });
const newSnapshots = Object.keys(groupSnapByEnv).map((snapEnv) => ({ const newSnapshots = Object.keys(groupSnapByEnv).map((snapEnv) => {
...secSnapshot.toObject({ virtuals: false }), const secretIdsOfEnvGroup = groupSnapByEnv[snapEnv] ? groupSnapByEnv[snapEnv].map(secretVersion => secretVersion._id) : []
_id: new Types.ObjectId(), return {
environment: snapEnv, ...secSnapshot.toObject({ virtuals: false }),
secretVersions: groupSnapByEnv[snapEnv], _id: new Types.ObjectId(),
})); environment: snapEnv,
secretVersions: secretIdsOfEnvGroup,
}
});
await SecretSnapshot.insertMany(newSnapshots); await SecretSnapshot.insertMany(newSnapshots);
await secSnapshot.delete(); await secSnapshot.delete();
@@ -369,7 +385,7 @@ export const backfillSecretFolders = async () => {
}, },
}) })
.populate<{ secretVersions: ISecretVersion[] }>("secretVersions") .populate<{ secretVersions: ISecretVersion[] }>("secretVersions")
.limit(50); .limit(5000);
} }
console.log("Migration: Folder migration v1 complete") console.log("Migration: Folder migration v1 complete")