Skip to content

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

feat: added concurrent index over secret key with folder id

=1908499231a0
diff --git a/backend/src/db/migrations/20260305133310_secret-key-index.ts b/backend/src/db/migrations/20260305133310_secret-key-index.ts
new file mode 100644
index 0000000000..5b430655bf
--- /dev/null
+++ b/backend/src/db/migrations/20260305133310_secret-key-index.ts
@@ -0,0 +1,36 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const MIGRATION_TIMEOUT = 5 * 60 * 1000; // 5 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}`);
+
+ if (
+ (await knex.schema.hasTable(TableName.SecretV2)) &&
+ (await knex.schema.hasColumn(TableName.SecretV2, "folderId")) &&
+ (await knex.schema.hasColumn(TableName.SecretV2, "key"))
+ ) {
+ await knex.raw(`
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_secrets_v2_folder_id_key
+ ON ${TableName.SecretV2} ("folderId", "key")
+ `);
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`
+ DROP INDEX IF EXISTS idx_secrets_v2_folder_id_key
+ `);
+}
+
+const config = { transaction: false };
+export { config };