fix: serialize profile reset operations
This commit is contained in:
+6
@@ -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');
|
||||
+8
@@ -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");
|
||||
@@ -174,6 +174,8 @@ model GatewayRuntimeAction {
|
||||
}
|
||||
|
||||
model GatewayOperation {
|
||||
/// A partial unique index in the gateway migration chain permits only one
|
||||
/// QUEUED or RUNNING operation per profile.
|
||||
id String @id @default(uuid())
|
||||
profileName String @map("profile_name")
|
||||
profile GatewayProfile @relation(fields: [profileName], references: [profileName], onDelete: Cascade)
|
||||
@@ -189,10 +191,15 @@ model GatewayOperation {
|
||||
startedAt DateTime? @map("started_at")
|
||||
completedAt DateTime? @map("completed_at")
|
||||
error String?
|
||||
leaseOwner String? @map("lease_owner")
|
||||
leaseUntil DateTime? @map("lease_until")
|
||||
heartbeatAt DateTime? @map("heartbeat_at")
|
||||
attempts Int @default(0)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([status, scheduledAt, createdAt])
|
||||
@@index([status, leaseUntil, createdAt])
|
||||
@@index([profileName, createdAt])
|
||||
@@map("gateway_operation")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user