Skip to content

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

fix position

adilson4b6d00a97755
diff --git a/backend/e2e-test/routes/v1/project-env.spec.ts b/backend/e2e-test/routes/v1/project-env.spec.ts
index 6023a30f64..cb094c4147 100644
--- a/backend/e2e-test/routes/v1/project-env.spec.ts
+++ b/backend/e2e-test/routes/v1/project-env.spec.ts
@@ -123,7 +123,7 @@ describe("Project Environment Router", async () => {
id: deletedProjectEnvironment.id,
name: mockProjectEnv.name,
slug: mockProjectEnv.slug,
- position: 5,
+ position: DEFAULT_PROJECT_ENVS.length + 1,
createdAt: expect.any(String),
updatedAt: expect.any(String)
})
diff --git a/backend/src/services/project-env/project-env-dal.ts b/backend/src/services/project-env/project-env-dal.ts
index 3258aa522f..2f05f8ad7c 100644
--- a/backend/src/services/project-env/project-env-dal.ts
+++ b/backend/src/services/project-env/project-env-dal.ts
@@ -140,7 +140,6 @@ export const projectEnvDALFactory = (db: TDbClient) => {
const lastPos = await (tx || db)(TableName.Environment)
.where({ projectId })
- .whereNull("hardDeletesAt")
.max("position", { as: "position" })
.first();
@@ -190,17 +189,6 @@ export const projectEnvDALFactory = (db: TDbClient) => {
.decrement("position", 1);
};
- // Closes a gap at `pos` only among active environments. Soft-deleted rows
- // must keep their tail positions so a new soft-delete can move into the
- // pre-shift max active slot without colliding on (projectId, position).
- const closeActivePositionGap = async (projectId: string, pos: number, tx?: Knex) => {
- await (tx || db)(TableName.Environment)
- .where({ projectId })
- .whereNull("hardDeletesAt")
- .andWhere("position", ">", pos)
- .decrement("position", 1);
- };
-
const findExpiredForHardDelete = async (tx?: Knex) => {
try {
const result = await (tx || db.replicaNode())(TableName.Environment)
@@ -227,7 +215,6 @@ export const projectEnvDALFactory = (db: TDbClient) => {
updateAllPosition,
shiftPositions,
closePositionGap,
- closeActivePositionGap,
findExpiredForHardDelete
};
};
diff --git a/backend/src/services/project-env/project-env-queue.ts b/backend/src/services/project-env/project-env-queue.ts
index f88788546c..3cec40f8ec 100644
--- a/backend/src/services/project-env/project-env-queue.ts
+++ b/backend/src/services/project-env/project-env-queue.ts
@@ -90,7 +90,7 @@ export const projectEnvQueueFactory = ({
enabled: !appCfg.isSecondaryInstance,
handler: async () => {
logger.info(`cron[${CronJobName.ProjectEnvHardDelete}]: task started`);
- const expiredEnvs = await projectEnvDAL.findExpiredForHardDelete();
+ const expiredEnvs = await projectEnvDAL.transaction((tx) => projectEnvDAL.findExpiredForHardDelete(tx));
logger.info(
`cron[${CronJobName.ProjectEnvHardDelete}]: found ${expiredEnvs.length} expired environment(s) to hard-delete`
);
diff --git a/backend/src/services/project-env/project-env-service.ts b/backend/src/services/project-env/project-env-service.ts
index 9ef46ff2db..319f2d98f9 100644
--- a/backend/src/services/project-env/project-env-service.ts
+++ b/backend/src/services/project-env/project-env-service.ts
@@ -299,7 +299,7 @@ export const projectEnvServiceFactory = ({
// Shift active rows first (closes the gap at oldPos), then place the
// soft-deleted row at the pre-shift max active position. That slot is
// now free since its previous active occupant was shifted down.
- await projectEnvDAL.closeActivePositionGap(projectId, target.position, tx);
+ await projectEnvDAL.closePositionGap(projectId, target.position, tx);
const softDeletedAt = new Date();
const hardDeletesAt = new Date(softDeletedAt.getTime() + SOFT_DELETE_GRACE_MS);