Skip to content

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

misc: separate migration steps for remvoing fk and orphaned identities

Sheen Capadngan71972f9ffb6e
diff --git a/backend/src/db/migrations/20251019061215_sub-org-identity-backfill.ts b/backend/src/db/migrations/20251019061215_sub-org-identity-backfill.ts
index 71e8924d49..9054a03eee 100644
--- a/backend/src/db/migrations/20251019061215_sub-org-identity-backfill.ts
+++ b/backend/src/db/migrations/20251019061215_sub-org-identity-backfill.ts
@@ -38,11 +38,6 @@ export async function up(knex: Knex): Promise<void> {
.merge();
}
}
-
- await tx(TableName.Identity).whereNull("orgId").delete();
- await tx.schema.alterTable(TableName.Identity, (t) => {
- t.uuid("orgId").notNullable().alter();
- });
}
});
}
diff --git a/backend/src/db/migrations/20251028155708_identity-access-token-remove-fk-for-identity-id.ts b/backend/src/db/migrations/20251028155708_identity-access-token-remove-fk-for-identity-id.ts
new file mode 100644
index 0000000000..0974f39c28
--- /dev/null
+++ b/backend/src/db/migrations/20251028155708_identity-access-token-remove-fk-for-identity-id.ts
@@ -0,0 +1,22 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ await knex.transaction(async (tx) => {
+ await tx.schema.alterTable(TableName.IdentityAccessToken, (table) => {
+ table.dropForeign("identityId");
+ });
+ });
+}
+
+export async function down(knex: Knex): Promise<void> {
+ await knex.transaction(async (tx) => {
+ await tx.schema.alterTable(TableName.IdentityAccessToken, (table) => {
+ table.foreign("identityId").references("id").inTable(TableName.Identity);
+ });
+ });
+}
+
+const config = { transaction: false };
+export { config };
diff --git a/backend/src/db/migrations/20251028160921_delete-no-org-identities.ts b/backend/src/db/migrations/20251028160921_delete-no-org-identities.ts
new file mode 100644
index 0000000000..bf4692cf0c
--- /dev/null
+++ b/backend/src/db/migrations/20251028160921_delete-no-org-identities.ts
@@ -0,0 +1,20 @@
+import { Knex } from "knex";
+
+import { TableName } from "../schemas";
+
+export async function up(knex: Knex): Promise<void> {
+ await knex.transaction(async (tx) => {
+ const hasIdentityOrgCol = await tx.schema.hasColumn(TableName.Identity, "orgId");
+ if (hasIdentityOrgCol) {
+ await tx(TableName.Identity).whereNull("orgId").delete();
+ await tx.schema.alterTable(TableName.Identity, (t) => {
+ t.uuid("orgId").notNullable().alter();
+ });
+ }
+ });
+}
+
+export async function down(): Promise<void> {}
+
+const config = { transaction: false };
+export { config };