Skip to content

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

Delete PKI templates on project removal to avoid blocking users from removing PKI projects

Carlos Monastyrski44e9edcccaaa
diff --git a/backend/src/db/migrations/20251106172316_delete-pki-templates-on-project-removal.ts b/backend/src/db/migrations/20251106172316_delete-pki-templates-on-project-removal.ts
new file mode 100644
index 0000000000..4d98f8af4d
--- /dev/null
+++ b/backend/src/db/migrations/20251106172316_delete-pki-templates-on-project-removal.ts
@@ -0,0 +1,21 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ if (await knex.schema.hasTable(TableName.PkiCertificateTemplateV2)) {
+ await knex.schema.alterTable(TableName.PkiCertificateTemplateV2, (t) => {
+ t.dropForeign(["projectId"]);
+ t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
+ });
+ }
+}
+
+export async function down(knex: Knex): Promise<void> {
+ if (await knex.schema.hasTable(TableName.PkiCertificateTemplateV2)) {
+ await knex.schema.alterTable(TableName.PkiCertificateTemplateV2, (t) => {
+ t.dropForeign(["projectId"]);
+ t.foreign("projectId").references("id").inTable(TableName.Project);
+ });
+ }
+}