mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 08:27:36 +00:00
Patch backfill data
This commit is contained in:
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user