Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/dashboard/drizzle/0031_proxmox_vmid_seq.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE SEQUENCE "public"."proxmox_vmid_seq" INCREMENT BY 1 MINVALUE 1000 MAXVALUE 999999999 START WITH 1000 CACHE 1;--> statement-breakpoint
SELECT setval('proxmox_vmid_seq', GREATEST(COALESCE((SELECT MAX("proxmox_id") FROM "vms"), 0) + 1, 1000), false);
7 changes: 7 additions & 0 deletions apps/dashboard/drizzle/0032_unique_active_proxmox_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPDATE "vms" SET "proxmox_id" = NULL WHERE "id" IN (
SELECT "id" FROM (
SELECT "id", row_number() OVER (PARTITION BY "proxmox_id" ORDER BY "created_at" DESC) AS "rank"
FROM "vms" WHERE "active" AND "proxmox_id" IS NOT NULL
) "ranked" WHERE "rank" > 1
);--> statement-breakpoint
CREATE UNIQUE INDEX "vms_active_proxmox_id_unique" ON "vms" USING btree ("proxmox_id") WHERE "vms"."active";
Loading
Loading