misc: add endpoint for environment terraform resource

This commit is contained in:
Sheen Capadngan
2024-07-23 02:35:37 +08:00
parent 5d945f432d
commit de686acc23
6 changed files with 100 additions and 3 deletions
@@ -24,10 +24,15 @@ export const projectEnvDALFactory = (db: TDbClient) => {
// we are using postion based sorting as its a small list
// this will return the last value of the position in a folder with secret imports
const findLastEnvPosition = async (projectId: string, tx?: Knex) => {
// acquire update lock on project environments.
// this ensures that concurrent invocations will wait and execute sequentially
await (tx || db)(TableName.Environment).where({ projectId }).forUpdate();
const lastPos = await (tx || db)(TableName.Environment)
.where({ projectId })
.max("position", { as: "position" })
.first();
return lastPos?.position || 0;
};