Add Mosaic's own backlog-of-record on the existing Postgres storage layer, replacing the former Hermes adapter (no Hermes dependency) and the earlier sqlite idea (no sqlite, no new client). - packages/db: `backlog` table (drizzle) + enum + migration 0011; BacklogService taking a Db handle so it runs on both createDb (server PG) and createPgliteDb (embedded). Atomic claim via SELECT ... FOR UPDATE SKIP LOCKED inside one tx, TTL claims + reclaim of expired, deps DAG gate, idempotency-key dedup, stats. - packages/mosaic: `mosaic fleet backlog <sub> --json` (create/list/claim/ reclaim/link/stats/block/complete). Embedded PGlite default at <mosaicHome>/fleet/backlog; full Postgres via DATABASE_URL — same code. Migrations run on first use. - install.sh: preserve fleet/backlog across `mosaic update`. - docs/fleet/backlog-conventions.md: schema, phase convention, atomic-claim + TTL semantics, PGlite-default/Postgres-by-config, Mosaic-native (no Hermes). - Tests (in-memory PGlite, real PG semantics): create/list, exactly-one-winner concurrency (and N-card no-double-claim), deps gate, reclaim of expired, stats. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
22 lines
1023 B
SQL
22 lines
1023 B
SQL
CREATE TYPE "public"."backlog_status" AS ENUM('ready', 'claimed', 'blocked', 'done');--> statement-breakpoint
|
|
CREATE TABLE "backlog" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"title" text NOT NULL,
|
|
"body" text,
|
|
"phase" text,
|
|
"priority" integer DEFAULT 0 NOT NULL,
|
|
"status" "backlog_status" DEFAULT 'ready' NOT NULL,
|
|
"depends_on" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
"claim_owner" text,
|
|
"claim_ttl_seconds" integer,
|
|
"claimed_at" timestamp with time zone,
|
|
"attempts" integer DEFAULT 0 NOT NULL,
|
|
"idempotency_key" text,
|
|
"acceptance" jsonb,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX "backlog_status_priority_idx" ON "backlog" USING btree ("status","priority");--> statement-breakpoint
|
|
CREATE INDEX "backlog_status_claimed_at_idx" ON "backlog" USING btree ("status","claimed_at");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "backlog_idempotency_key_idx" ON "backlog" USING btree ("idempotency_key"); |