Skip to content

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

misc: add mising index for secret versions

Sheen Capadnganec7d1b753396
diff --git a/backend/src/db/migrations/20260306202508_add-missing-secret-versions-v2-indexes.ts b/backend/src/db/migrations/20260306202508_add-missing-secret-versions-v2-indexes.ts
new file mode 100644
index 0000000000..17fe57b4dc
--- /dev/null
+++ b/backend/src/db/migrations/20260306202508_add-missing-secret-versions-v2-indexes.ts
@@ -0,0 +1,32 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+const INDEX_NAME = "secret_versions_v2_secretid_version_index";
+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}`);
+
+ const indexExists = await knex.raw(`SELECT 1 FROM pg_indexes WHERE indexname = ?`, [INDEX_NAME]);
+
+ if (indexExists.rows.length === 0) {
+ await knex.raw(
+ `CREATE INDEX CONCURRENTLY "${INDEX_NAME}" ON "${TableName.SecretVersionV2}" ("secretId", "version")`
+ );
+ }
+ } finally {
+ await knex.raw(`SET statement_timeout = '${originalTimeout}'`);
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.raw(`DROP INDEX IF EXISTS "${INDEX_NAME}"`);
+}
+
+const config = { transaction: false };
+export { config };