Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

lock legacy reviews while migrating access approval requests

adilson684bf0484c6b
diff --git a/backend/src/db/migrations/20261013120000_migrate-access-approval-policies-to-global.ts b/backend/src/db/migrations/20261013120000_migrate-access-approval-policies-to-global.ts
index 2b62c9aeda..65d68f993c 100644
--- a/backend/src/db/migrations/20261013120000_migrate-access-approval-policies-to-global.ts
+++ b/backend/src/db/migrations/20261013120000_migrate-access-approval-policies-to-global.ts
@@ -465,7 +465,7 @@ const readPolicyData = async (tx: Knex, policy: TLegacyPolicy, requests: TLegacy
const environments = await readPolicyEnvironments(tx, LEGACY_TABLES, policyId);
const approvers = await readLegacyApprovers(tx, LEGACY_TABLES, policyId);
const bypassers = await readLegacyBypassers(tx, LEGACY_TABLES, policyId);
- const reviews = await readLegacyReviews(tx, LEGACY_TABLES, requestIds);
+ const reviews = await readLegacyReviews(tx, LEGACY_TABLES, requestIds, { forUpdate: true });
const requesters = requesterIds.length
? ((await tx(TableName.Users)
diff --git a/backend/src/db/migrations/utils/approval-migration.ts b/backend/src/db/migrations/utils/approval-migration.ts
index 812f17a515..00ec9a3998 100644
--- a/backend/src/db/migrations/utils/approval-migration.ts
+++ b/backend/src/db/migrations/utils/approval-migration.ts
@@ -135,11 +135,16 @@ export const readLegacyReviews = async (
tx: Knex,
tables: TLegacyApprovalTables,
requestIds: string[],
- { withComment = false }: { withComment?: boolean } = {}
+ { withComment = false, forUpdate = false }: { withComment?: boolean; forUpdate?: boolean } = {}
) => {
if (!requestIds.length) return [] as TLegacyReview[];
const columns = ["id", "requestId", "reviewerUserId", "status", "createdAt", ...(withComment ? ["comment"] : [])];
- return (await tx(tables.legacyReviewers).whereIn("requestId", requestIds).select(columns)) as TLegacyReview[];
+ return (await tx(tables.legacyReviewers)
+ .whereIn("requestId", requestIds)
+ .modify((qb) => {
+ if (forUpdate) void qb.forUpdate();
+ })
+ .select(columns)) as TLegacyReview[];
};
export const readApproverGroupMembers = async (tx: Knex, approvers: TLegacyApprover[]) => {