Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Add unique constraint for public key under the same profile
Fang-Pen Lin022c3802e3a2
diff --git a/backend/src/db/migrations/20251119025017_add-unique-constraint-for-pki-acme-account-public-key-and-profile-id.ts b/backend/src/db/migrations/20251119025017_add-unique-constraint-for-pki-acme-account-public-key-and-profile-id.tsnew file mode 100644index 0000000000..5bc4601e33--- /dev/null+++ b/backend/src/db/migrations/20251119025017_add-unique-constraint-for-pki-acme-account-public-key-and-profile-id.ts@@ -0,0 +1,32 @@+import { Knex } from "knex";++import { dropConstraintIfExists } from "@app/db/migrations/utils/dropConstraintIfExists";+import { TableName } from "@app/db/schemas";++const CONSTRAINT_NAME = "unique_pki_acme_account_public_key_and_profile_id";++export async function up(knex: Knex): Promise<void> {+ if (await knex.schema.hasTable(TableName.PkiAcmeAccount)) {+ const hasProfileId = await knex.schema.hasColumn(TableName.PkiAcmeAccount, "profileId");+ const hasPublicKeyThumbprint = await knex.schema.hasColumn(TableName.PkiAcmeAccount, "publicKeyThumbprint");++ if (hasProfileId && hasPublicKeyThumbprint) {+ await knex.schema.alterTable(TableName.PkiAcmeAccount, (table) => {+ table.unique(["profileId", "publicKeyThumbprint"], { indexName: CONSTRAINT_NAME });+ });+ }+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasTable(TableName.PkiAcmeAccount)) {+ const hasProfileId = await knex.schema.hasColumn(TableName.PkiAcmeAccount, "profileId");+ const hasPublicKeyThumbprint = await knex.schema.hasColumn(TableName.PkiAcmeAccount, "publicKeyThumbprint");++ await knex.schema.alterTable(TableName.PkiAcmeAccount, async () => {+ if (hasProfileId && hasPublicKeyThumbprint) {+ await dropConstraintIfExists(TableName.PkiAcmeAccount, CONSTRAINT_NAME, knex);+ }+ });+ }+}