Skip to content

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

refactor(secret-value-tracking): one migration for the whole change

Calvineebebc7c7382
diff --git a/backend/src/db/migrations/20260923120000_add-secret-value-org-blind-index.ts b/backend/src/db/migrations/20260923120000_add-org-scoped-secret-value-tracking.ts
similarity index 56%
rename from backend/src/db/migrations/20260923120000_add-secret-value-org-blind-index.ts
rename to backend/src/db/migrations/20260923120000_add-org-scoped-secret-value-tracking.ts
index 813302a7a7..513f0ac156 100644
--- a/backend/src/db/migrations/20260923120000_add-secret-value-org-blind-index.ts
+++ b/backend/src/db/migrations/20260923120000_add-org-scoped-secret-value-tracking.ts
@@ -13,6 +13,8 @@ export async function up(knex: Knex): Promise<void> {
}
}
+ // Versions carry the digest too, because a folder rollback copies a version's columns back onto
+ // the live secret.
if (await knex.schema.hasTable(TableName.SecretVersionV2)) {
const hasColumn = await knex.schema.hasColumn(TableName.SecretVersionV2, "secretValueOrgBlindIndex");
if (!hasColumn) {
@@ -29,6 +31,20 @@ export async function up(knex: Knex): Promise<void> {
WHERE "secretValueOrgBlindIndex" IS NOT NULL
`);
}
+
+ // Whether every row in the organization carries the digest above, which is what makes searching by
+ // value trustworthy. It defaults to false rather than true, and organization creation opts a new
+ // one in explicitly: during a rolling deploy the old replicas keep serving after this runs, and
+ // every secret they write carries no digest, so an organization they create is not complete
+ // however new it is. A database default cannot tell the two apart; the application code can.
+ if (await knex.schema.hasTable(TableName.Organization)) {
+ const hasColumn = await knex.schema.hasColumn(TableName.Organization, "orgWideSecretValueTrackingEnabled");
+ if (!hasColumn) {
+ await knex.schema.alterTable(TableName.Organization, (t) => {
+ t.boolean("orgWideSecretValueTrackingEnabled").defaultTo(false).notNullable();
+ });
+ }
+ }
}
export async function down(knex: Knex): Promise<void> {
@@ -51,8 +67,18 @@ export async function down(knex: Knex): Promise<void> {
});
}
}
+
+ if (await knex.schema.hasTable(TableName.Organization)) {
+ const hasColumn = await knex.schema.hasColumn(TableName.Organization, "orgWideSecretValueTrackingEnabled");
+ if (hasColumn) {
+ await knex.schema.alterTable(TableName.Organization, (t) => {
+ t.dropColumn("orgWideSecretValueTrackingEnabled");
+ });
+ }
+ }
}
-// CONCURRENTLY requires running outside a transaction
+// CONCURRENTLY requires running outside a transaction. Every step above is guarded by a hasColumn or
+// IF NOT EXISTS check, which is what lets a partial failure be retried safely without one.
const config = { transaction: false };
export { config };
diff --git a/backend/src/db/migrations/20260924120000_add-org-wide-secret-value-tracking.ts b/backend/src/db/migrations/20260924120000_add-org-wide-secret-value-tracking.ts
deleted file mode 100644
index ff4df6e436..0000000000
--- a/backend/src/db/migrations/20260924120000_add-org-wide-secret-value-tracking.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { Knex } from "knex";
-
-import { TableName } from "../schemas";
-
-export async function up(knex: Knex): Promise<void> {
- if (await knex.schema.hasTable(TableName.Organization)) {
- const hasColumn = await knex.schema.hasColumn(TableName.Organization, "orgWideSecretValueTrackingEnabled");
- if (!hasColumn) {
- await knex.schema.alterTable(TableName.Organization, (t) => {
- t.boolean("orgWideSecretValueTrackingEnabled").defaultTo(false).notNullable();
- });
-
- // The column defaults to false rather than true, and org creation opts a new org in
- // explicitly. During a rolling deploy the old replicas keep serving after this migration runs,
- // and every secret they write carries no org digest, so an org they create is not complete
- // however new it is. A database default cannot tell the two apart; the application code can.
- }
- }
-}
-
-export async function down(knex: Knex): Promise<void> {
- if (await knex.schema.hasTable(TableName.Organization)) {
- const hasColumn = await knex.schema.hasColumn(TableName.Organization, "orgWideSecretValueTrackingEnabled");
- if (hasColumn) {
- await knex.schema.alterTable(TableName.Organization, (t) => {
- t.dropColumn("orgWideSecretValueTrackingEnabled");
- });
- }
- }
-}