Patch backfill data

This commit is contained in:
Maidul Islam
2023-06-05 20:19:15 -07:00
parent 08868681d8
commit b0e7304bff

View File

@@ -335,6 +335,19 @@ export const backfillSecretFolders = async () => {
}
);
await SecretVersion.updateMany(
{
folder: {
$exists: false,
},
},
{
$set: {
folder: "root",
},
}
);
let secretSnapshots = await SecretSnapshot.find({
environment: {
$exists: false,
@@ -352,12 +365,15 @@ export const backfillSecretFolders = async () => {
groupSnapByEnv[secVer.environment].push(secVer);
});
const newSnapshots = Object.keys(groupSnapByEnv).map((snapEnv) => ({
...secSnapshot.toObject({ virtuals: false }),
_id: new Types.ObjectId(),
environment: snapEnv,
secretVersions: groupSnapByEnv[snapEnv],
}));
const newSnapshots = Object.keys(groupSnapByEnv).map((snapEnv) => {
const secretIdsOfEnvGroup = groupSnapByEnv[snapEnv] ? groupSnapByEnv[snapEnv].map(secretVersion => secretVersion._id) : []
return {
...secSnapshot.toObject({ virtuals: false }),
_id: new Types.ObjectId(),
environment: snapEnv,
secretVersions: secretIdsOfEnvGroup,
}
});
await SecretSnapshot.insertMany(newSnapshots);
await secSnapshot.delete();
@@ -369,7 +385,7 @@ export const backfillSecretFolders = async () => {
},
})
.populate<{ secretVersions: ISecretVersion[] }>("secretVersions")
.limit(50);
.limit(5000);
}
console.log("Migration: Folder migration v1 complete")