Skip to content

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

fix(migration): guard webauthn down() trigger drop with hasTable check

Jaydeep Pipaliya7c7f31356413
diff --git a/backend/src/db/migrations/20251118190904_add-webauthn-support.ts b/backend/src/db/migrations/20251118190904_add-webauthn-support.ts
index 419a6fc4e6..b0a0303d08 100644
--- a/backend/src/db/migrations/20251118190904_add-webauthn-support.ts
+++ b/backend/src/db/migrations/20251118190904_add-webauthn-support.ts
@@ -25,6 +25,14 @@ export async function up(knex: Knex): Promise<void> {
}
export async function down(knex: Knex): Promise<void> {
- await dropOnUpdateTrigger(knex, TableName.WebAuthnCredential);
- await knex.schema.dropTableIfExists(TableName.WebAuthnCredential);
+ // Mirror the conditional in up(): only drop the trigger when the table
+ // exists. dropOnUpdateTrigger emits `DROP TRIGGER IF EXISTS x ON table`
+ // — the `IF EXISTS` only swallows missing-trigger errors; Postgres still
+ // refuses to parse the `ON table` clause when the relation is gone, so
+ // rolling back on a DB that never ran up() (or that already dropped the
+ // table by another path) errors out.
+ if (await knex.schema.hasTable(TableName.WebAuthnCredential)) {
+ await dropOnUpdateTrigger(knex, TableName.WebAuthnCredential);
+ await knex.schema.dropTable(TableName.WebAuthnCredential);
+ }
}