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
add index for referencing columns in identity access token This PR will address issue with very long identity deletions due to a sequential scan over ALL identity access rows during CASCADE
Maidul Islam8719e3e75e19
diff --git a/backend/src/db/migrations/20250710022434_add-index-for-access-token.ts b/backend/src/db/migrations/20250710022434_add-index-for-access-token.tsnew file mode 100644index 0000000000..7f85af74d9--- /dev/null+++ b/backend/src/db/migrations/20250710022434_add-index-for-access-token.ts@@ -0,0 +1,47 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++const MIGRATION_TIMEOUT = 30 * 60 * 1000; // 30 minutes++export async function up(knex: Knex): Promise<void> {+ const result = await knex.raw('SHOW statement_timeout');+ const originalTimeout = result.rows[0].statement_timeout;++ try {+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);++ await knex.raw(`+ CREATE INDEX CONCURRENTLY IF NOT EXISTS ${TableName.IdentityAccessToken}_identityid_index+ ON ${TableName.IdentityAccessToken} ("identityId")+ `);++ await knex.raw(`+ CREATE INDEX CONCURRENTLY IF NOT EXISTS ${TableName.IdentityAccessToken}_identityuaclientsecretid_index+ ON ${TableName.IdentityAccessToken} ("identityUAClientSecretId")+ `);+ } finally {+ await knex.raw(`SET statement_timeout = '${originalTimeout}'`);+ }+}++export async function down(knex: Knex): Promise<void> {+ const result = await knex.raw('SHOW statement_timeout');+ const originalTimeout = result.rows[0].statement_timeout;++ try {+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);++ await knex.raw(`+ DROP INDEX IF EXISTS ${TableName.IdentityAccessToken}_identityid_index+ `);++ await knex.raw(`+ DROP INDEX IF EXISTS ${TableName.IdentityAccessToken}_identityuaclientsecretid_index+ `);+ } finally {+ await knex.raw(`SET statement_timeout = '${originalTimeout}'`);+ }+}++export const config = { transaction: false };\ No newline at end of file