Skip to content

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

fix: make pam-revamp migration idempotent and fold in credential-configured migration

bernie-gce1935ffb055
diff --git a/backend/src/db/migrations/20260612142201_pam-revamp.ts b/backend/src/db/migrations/20260612142201_pam-revamp.ts
index 9d886e2b95..4148afb716 100644
--- a/backend/src/db/migrations/20260612142201_pam-revamp.ts
+++ b/backend/src/db/migrations/20260612142201_pam-revamp.ts
@@ -71,6 +71,12 @@ const backfillPamProjectsForAllOrgs = async (knex: Knex) => {
};
export async function up(knex: Knex): Promise<void> {
+ // The migration commits atomically, so this table existing means it already ran fully.
+ // Guarding the whole run: a partial re-run would null folderIds and delete migrated accounts.
+ if (await knex.schema.hasTable(TableName.PamAccountTemplate)) {
+ return;
+ }
+
await knex.schema.createTable(TableName.PamAccountTemplate, (t) => {
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
@@ -524,6 +530,13 @@ export async function up(knex: Knex): Promise<void> {
t.renameColumn("resourceType", "accountType");
t.string("resourceName").nullable().alter();
});
+
+ // Accounts existing at migration time were created with credentials supplied upfront
+ await knex.schema.alterTable(TableName.PamAccount, (t) => {
+ t.boolean("credentialConfigured").notNullable().defaultTo(false);
+ });
+
+ await knex(TableName.PamAccount).update({ credentialConfigured: true });
}
export async function down(): Promise<void> {
diff --git a/backend/src/db/migrations/20260619013459_pam-account-credential-configured.ts b/backend/src/db/migrations/20260619013459_pam-account-credential-configured.ts
deleted file mode 100644
index a9208aa7f2..0000000000
--- a/backend/src/db/migrations/20260619013459_pam-account-credential-configured.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Knex } from "knex";
-
-import { TableName } from "../schemas";
-
-export async function up(knex: Knex): Promise<void> {
- if (!(await knex.schema.hasColumn(TableName.PamAccount, "credentialConfigured"))) {
- await knex.schema.alterTable(TableName.PamAccount, (t) => {
- t.boolean("credentialConfigured").notNullable().defaultTo(false);
- });
-
- await knex(TableName.PamAccount).update({ credentialConfigured: true });
- }
-}
-
-export async function down(knex: Knex): Promise<void> {
- if (await knex.schema.hasColumn(TableName.PamAccount, "credentialConfigured")) {
- await knex.schema.alterTable(TableName.PamAccount, (t) => {
- t.dropColumn("credentialConfigured");
- });
- }
-}