Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(server): added index for audit log to resolve high latency or timeout caused
Akhil Mohan8e7cf5f9aca7
diff --git a/backend/src/db/migrations/20240429154610_audit-log-index.ts b/backend/src/db/migrations/20240429154610_audit-log-index.tsnew file mode 100644index 0000000000..40a1cb24d6--- /dev/null+++ b/backend/src/db/migrations/20240429154610_audit-log-index.ts@@ -0,0 +1,28 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ const doesOrgIdExist = await knex.schema.hasColumn(TableName.AuditLog, "orgId");+ const doesProjectIdExist = await knex.schema.hasColumn(TableName.AuditLog, "projectId");+ const doesCreatedAtExist = await knex.schema.hasColumn(TableName.AuditLog, "createdAt");+ if (await knex.schema.hasTable(TableName.AuditLog)) {+ await knex.schema.alterTable(TableName.AuditLog, (t) => {+ if (doesProjectIdExist && doesCreatedAtExist) t.index(["projectId", "createdAt"]);+ if (doesOrgIdExist && doesCreatedAtExist) t.index(["orgId", "createdAt"]);+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ const doesOrgIdExist = await knex.schema.hasColumn(TableName.AuditLog, "orgId");+ const doesProjectIdExist = await knex.schema.hasColumn(TableName.AuditLog, "projectId");+ const doesCreatedAtExist = await knex.schema.hasColumn(TableName.AuditLog, "createdAt");++ if (await knex.schema.hasTable(TableName.AuditLog)) {+ await knex.schema.alterTable(TableName.AuditLog, (t) => {+ if (doesProjectIdExist && doesCreatedAtExist) t.dropIndex(["projectId", "createdAt"]);+ if (doesOrgIdExist && doesCreatedAtExist) t.dropIndex(["orgId", "createdAt"]);+ });+ }+}