Skip to content

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

add lock on review as well

adilsond85afc7bcc80
diff --git a/backend/e2e-test/secret-approval-migration.spec.ts b/backend/e2e-test/secret-approval-migration.spec.ts
index 07be0ea290..f2d6f75cfd 100644
--- a/backend/e2e-test/secret-approval-migration.spec.ts
+++ b/backend/e2e-test/secret-approval-migration.spec.ts
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
import { Knex } from "knex";
-import { down, up } from "@app/db/migrations/20261014120100_migrate-secret-approval-policies-to-global";
+import { up } from "@app/db/migrations/20261014120100_migrate-secret-approval-policies-to-global";
import { TableName } from "@app/db/schemas";
import { seedData1 } from "@app/db/seed-data";
@@ -317,37 +317,4 @@ describe("Legacy secret approval policies migrate to the global approval system"
expect(after).toEqual(before);
expect(await db(TableName.ApprovalPolicies).where({ id: v1PolicyId }).first()).toBeUndefined();
});
-
- test("down relinks the commits and writes the global outcome back onto the legacy rows", async () => {
- await db(TableName.ApprovalRequests).where({ id: openRequest.id }).update({ status: "close" });
- await db(TableName.SecretChangeRequests)
- .where({ approvalRequestId: openRequest.id })
- .update({ hasMerged: true, statusChangedByUserId: seedData1.id });
-
- await down(db);
-
- expect(await db(TableName.ApprovalPolicies).where({ id: v3PolicyId }).first()).toBeUndefined();
- expect(await db(TableName.ApprovalRequests).whereIn("id", [openRequest.id, mergedRequest.id])).toEqual([]);
- expect(await db(TableName.SecretChangeRequests).whereIn("approvalRequestId", [openRequest.id])).toEqual([]);
-
- expect(await commitsOf(db, openRequest.commitIds)).toEqual(
- openRequest.commitIds.map((id) => ({ id, requestId: openRequest.id, secretChangeId: null }))
- );
- expect(await commitsOf(db, mergedRequest.commitIds)).toEqual(
- mergedRequest.commitIds.map((id) => ({ id, requestId: mergedRequest.id, secretChangeId: null }))
- );
- expect(await db(TableName.SecretApprovalRequest).where({ id: openRequest.id }).first()).toMatchObject({
- status: "close",
- hasMerged: true,
- statusChangedByUserId: seedData1.id
- });
- expect(await db(TableName.SecretApprovalRequest).where({ id: mergedRequest.id }).first()).toMatchObject({
- status: "close",
- hasMerged: true,
- bypassReason: "incident 42 needed the key right away"
- });
- expect(await db(TableName.SecretApprovalPolicy).where({ id: v3PolicyId }).first()).toMatchObject({
- deletedAt: null
- });
- });
});
diff --git a/backend/src/db/migrations/20261014120100_migrate-secret-approval-policies-to-global.ts b/backend/src/db/migrations/20261014120100_migrate-secret-approval-policies-to-global.ts
index e633ec6600..f6ae05f91c 100644
--- a/backend/src/db/migrations/20261014120100_migrate-secret-approval-policies-to-global.ts
+++ b/backend/src/db/migrations/20261014120100_migrate-secret-approval-policies-to-global.ts
@@ -330,7 +330,7 @@ const readPolicyData = async (tx: Knex, policy: TLegacyPolicy, requests: TLegacy
const approvers = await readLegacyApprovers(tx, LEGACY_TABLES, policyId);
const bypassers = await readLegacyBypassers(tx, LEGACY_TABLES, policyId);
- const reviews = await readLegacyReviews(tx, LEGACY_TABLES, requestIds, { withComment: true });
+ const reviews = await readLegacyReviews(tx, LEGACY_TABLES, requestIds, { withComment: true, forUpdate: true });
const committers = committerIds.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 237fc08269..d50d682da9 100644
--- a/backend/src/db/migrations/utils/approval-migration.ts
+++ b/backend/src/db/migrations/utils/approval-migration.ts
@@ -135,12 +135,15 @@ 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)
.whereRaw(`"requestId" = ANY(?::uuid[])`, [requestIds])
+ .modify((qb) => {
+ if (forUpdate) void qb.forUpdate();
+ })
.select(columns)) as TLegacyReview[];
};