Skip to content

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

Add new database migrations for secret ID indexing

Victor Hugo dos Santosa3009e93502c
diff --git a/backend/src/db/migrations/20260825120000_add-secret-references-v2-secret-id-index.ts b/backend/src/db/migrations/20260825120000_add-secret-references-v2-secret-id-index.ts
new file mode 100644
index 0000000000..6f65c98994
--- /dev/null
+++ b/backend/src/db/migrations/20260825120000_add-secret-references-v2-secret-id-index.ts
@@ -0,0 +1,40 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const INDEX_NAME = "idx_secret_references_v2_secret_id";
+const COLUMN = "secretId";
+const MIGRATION_TIMEOUT = 60 * 60 * 1000; // 60 minutes
+const MIGRATION_LOCK_TIMEOUT = 30 * 1000; // 30 seconds
+
+export async function up(knex: Knex): Promise<void> {
+ const stmtResult = await knex.raw("SHOW statement_timeout");
+ const originalStatementTimeout = stmtResult.rows[0].statement_timeout;
+ const lockResult = await knex.raw("SHOW lock_timeout");
+ const originalLockTimeout = lockResult.rows[0].lock_timeout;
+
+ try {
+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
+ await knex.raw(`SET lock_timeout = ${MIGRATION_LOCK_TIMEOUT}`);
+
+ if (
+ (await knex.schema.hasTable(TableName.SecretReferenceV2)) &&
+ (await knex.schema.hasColumn(TableName.SecretReferenceV2, COLUMN))
+ ) {
+ await knex.raw(`
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "${INDEX_NAME}"
+ ON ${TableName.SecretReferenceV2} ("${COLUMN}")
+ `);
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalStatementTimeout}'`);
+ await knex.raw(`SET lock_timeout = '${originalLockTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS "${INDEX_NAME}"`);
+}
+
+const config = { transaction: false };
+export { config };
diff --git a/backend/src/db/migrations/20260825120100_add-secret-approval-secret-id-index.ts b/backend/src/db/migrations/20260825120100_add-secret-approval-secret-id-index.ts
new file mode 100644
index 0000000000..efc60a6c47
--- /dev/null
+++ b/backend/src/db/migrations/20260825120100_add-secret-approval-secret-id-index.ts
@@ -0,0 +1,41 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const INDEX_NAME = "idx_secret_approval_requests_secrets_v2_secret_id";
+const COLUMN = "secretId";
+const MIGRATION_TIMEOUT = 60 * 60 * 1000; // 60 minutes
+const MIGRATION_LOCK_TIMEOUT = 30 * 1000; // 30 seconds
+
+export async function up(knex: Knex): Promise<void> {
+ const stmtResult = await knex.raw("SHOW statement_timeout");
+ const originalStatementTimeout = stmtResult.rows[0].statement_timeout;
+ const lockResult = await knex.raw("SHOW lock_timeout");
+ const originalLockTimeout = lockResult.rows[0].lock_timeout;
+
+ try {
+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
+ await knex.raw(`SET lock_timeout = ${MIGRATION_LOCK_TIMEOUT}`);
+
+ if (
+ (await knex.schema.hasTable(TableName.SecretApprovalRequestSecretV2)) &&
+ (await knex.schema.hasColumn(TableName.SecretApprovalRequestSecretV2, COLUMN))
+ ) {
+ await knex.raw(`
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "${INDEX_NAME}"
+ ON ${TableName.SecretApprovalRequestSecretV2} ("${COLUMN}")
+ WHERE "${COLUMN}" IS NOT NULL
+ `);
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalStatementTimeout}'`);
+ await knex.raw(`SET lock_timeout = '${originalLockTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS "${INDEX_NAME}"`);
+}
+
+const config = { transaction: false };
+export { config };
diff --git a/backend/src/db/migrations/20260825120200_add-secret-rotation-mapping-secret-id-index.ts b/backend/src/db/migrations/20260825120200_add-secret-rotation-mapping-secret-id-index.ts
new file mode 100644
index 0000000000..23f29d9908
--- /dev/null
+++ b/backend/src/db/migrations/20260825120200_add-secret-rotation-mapping-secret-id-index.ts
@@ -0,0 +1,40 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const INDEX_NAME = "idx_secret_rotation_v2_secret_mappings_secret_id";
+const COLUMN = "secretId";
+const MIGRATION_TIMEOUT = 60 * 60 * 1000; // 60 minutes
+const MIGRATION_LOCK_TIMEOUT = 30 * 1000; // 30 seconds
+
+export async function up(knex: Knex): Promise<void> {
+ const stmtResult = await knex.raw("SHOW statement_timeout");
+ const originalStatementTimeout = stmtResult.rows[0].statement_timeout;
+ const lockResult = await knex.raw("SHOW lock_timeout");
+ const originalLockTimeout = lockResult.rows[0].lock_timeout;
+
+ try {
+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
+ await knex.raw(`SET lock_timeout = ${MIGRATION_LOCK_TIMEOUT}`);
+
+ if (
+ (await knex.schema.hasTable(TableName.SecretRotationV2SecretMapping)) &&
+ (await knex.schema.hasColumn(TableName.SecretRotationV2SecretMapping, COLUMN))
+ ) {
+ await knex.raw(`
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "${INDEX_NAME}"
+ ON ${TableName.SecretRotationV2SecretMapping} ("${COLUMN}")
+ `);
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalStatementTimeout}'`);
+ await knex.raw(`SET lock_timeout = '${originalLockTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS "${INDEX_NAME}"`);
+}
+
+const config = { transaction: false };
+export { config };
diff --git a/backend/src/db/migrations/20260825120300_add-secret-rotation-output-v2-secret-id-index.ts b/backend/src/db/migrations/20260825120300_add-secret-rotation-output-v2-secret-id-index.ts
new file mode 100644
index 0000000000..49480b8cc8
--- /dev/null
+++ b/backend/src/db/migrations/20260825120300_add-secret-rotation-output-v2-secret-id-index.ts
@@ -0,0 +1,40 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const INDEX_NAME = "idx_secret_rotation_output_v2_secret_id";
+const COLUMN = "secretId";
+const MIGRATION_TIMEOUT = 60 * 60 * 1000; // 60 minutes
+const MIGRATION_LOCK_TIMEOUT = 30 * 1000; // 30 seconds
+
+export async function up(knex: Knex): Promise<void> {
+ const stmtResult = await knex.raw("SHOW statement_timeout");
+ const originalStatementTimeout = stmtResult.rows[0].statement_timeout;
+ const lockResult = await knex.raw("SHOW lock_timeout");
+ const originalLockTimeout = lockResult.rows[0].lock_timeout;
+
+ try {
+ await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
+ await knex.raw(`SET lock_timeout = ${MIGRATION_LOCK_TIMEOUT}`);
+
+ if (
+ (await knex.schema.hasTable(TableName.DeprecatedSecretRotationOutputV2)) &&
+ (await knex.schema.hasColumn(TableName.DeprecatedSecretRotationOutputV2, COLUMN))
+ ) {
+ await knex.raw(`
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "${INDEX_NAME}"
+ ON ${TableName.DeprecatedSecretRotationOutputV2} ("${COLUMN}")
+ `);
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalStatementTimeout}'`);
+ await knex.raw(`SET lock_timeout = '${originalLockTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`DROP INDEX CONCURRENTLY IF EXISTS "${INDEX_NAME}"`);
+}
+
+const config = { transaction: false };
+export { config };