Skip to content

Commit d280deb

Browse files
committed
feat(db): add is_default column to ssh_keys with per-org uniqueness constraint
1 parent 2fe5efa commit d280deb

File tree

2 files changed

+7434
-0
lines changed

2 files changed

+7434
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE "ssh_keys" ADD COLUMN "is_default" boolean DEFAULT false NOT NULL;--> statement-breakpoint
2+
UPDATE "ssh_keys" SET "is_default" = true
3+
WHERE "id" IN (
4+
SELECT DISTINCT ON ("organization_id") "id"
5+
FROM "ssh_keys"
6+
WHERE "deleted_at" IS NULL AND "is_active" = true
7+
ORDER BY "organization_id", "created_at" DESC, "id" DESC
8+
);--> statement-breakpoint
9+
CREATE UNIQUE INDEX "ssh_keys_one_default_per_org" ON "ssh_keys" USING btree ("organization_id") WHERE is_default = true AND deleted_at IS NULL;

0 commit comments

Comments
 (0)