fix: serialize profile reset operations

This commit is contained in:
2026-07-31 13:19:27 +00:00
parent d959c9b06d
commit 26fbba39b4
17 changed files with 1715 additions and 378 deletions
@@ -0,0 +1,6 @@
-- A profile database can have only one destructive/runtime operation in flight.
-- Existing duplicates intentionally make this migration fail so an operator can
-- inspect and resolve them instead of silently discarding an operation.
CREATE UNIQUE INDEX "gateway_operation_one_active_per_profile_idx"
ON "gateway_operation" ("profile_name")
WHERE "status" IN ('QUEUED', 'RUNNING');
@@ -0,0 +1,8 @@
ALTER TABLE "gateway_operation"
ADD COLUMN "lease_owner" TEXT,
ADD COLUMN "lease_until" TIMESTAMPTZ,
ADD COLUMN "heartbeat_at" TIMESTAMPTZ,
ADD COLUMN "attempts" INTEGER NOT NULL DEFAULT 0;
CREATE INDEX "gateway_operation_status_lease_until_created_at_idx"
ON "gateway_operation" ("status", "lease_until", "created_at");