@igorjpimenta/winch 0.0.0-stage → 2026.11.22-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.migrations/0000_next_katie_power.sql +99 -0
- package/.migrations/0001_add-events-kind.sql +8 -0
- package/.migrations/0002_drop-session-budgets.sql +1 -0
- package/.migrations/0003_pink_siren.sql +8 -0
- package/.migrations/0004_salty_trauma.sql +1 -0
- package/.migrations/0005_classy_havok.sql +1 -0
- package/.migrations/0006_recursive_items.sql +265 -0
- package/.migrations/0007_unify_statuses.sql +35 -0
- package/.migrations/0008_core_dispatch.sql +61 -0
- package/.migrations/0009_webhooks.sql +17 -0
- package/.migrations/0010_dispatch_consumer_id.sql +1 -0
- package/.migrations/0011_dispatch_delivery_leases.sql +53 -0
- package/.migrations/0012_dispatch_fencing_audit.sql +32 -0
- package/.migrations/meta/0000_snapshot.json +658 -0
- package/.migrations/meta/0001_snapshot.json +665 -0
- package/.migrations/meta/0002_snapshot.json +604 -0
- package/.migrations/meta/0003_snapshot.json +656 -0
- package/.migrations/meta/0004_snapshot.json +664 -0
- package/.migrations/meta/0005_snapshot.json +671 -0
- package/.migrations/meta/0006_snapshot.json +1089 -0
- package/.migrations/meta/0007_unify_statuses_snapshot.json +1097 -0
- package/.migrations/meta/0008_snapshot.json +1382 -0
- package/.migrations/meta/0009_snapshot.json +1428 -0
- package/.migrations/meta/0010_snapshot.json +1435 -0
- package/.migrations/meta/0011_snapshot.json +1670 -0
- package/.migrations/meta/0012_snapshot.json +1900 -0
- package/.migrations/meta/_journal.json +97 -0
- package/README.md +480 -2
- package/bin/winch.js +4 -0
- package/package.json +36 -4
- package/plugins/README.md +304 -0
- package/plugins/openclaw/winch/README.md +71 -0
- package/plugins/openclaw/winch/dispatch.js +236 -0
- package/plugins/openclaw/winch/index.js +139 -0
- package/plugins/openclaw/winch/meta.js +35 -0
- package/plugins/openclaw/winch/openclaw.plugin.json +43 -0
- package/plugins/openclaw/winch/package.json +37 -0
- package/plugins/opencode/winch/dispatch.js +228 -0
- package/plugins/opencode/winch/hooks.js +22 -0
- package/plugins/opencode/winch/identity.js +34 -0
- package/plugins/opencode/winch/index.js +104 -0
- package/plugins/opencode/winch/package.json +26 -0
- package/src/cli.js +434 -0
- package/src/config.js +181 -0
- package/src/db.js +39 -0
- package/src/deps.js +70 -0
- package/src/dispatch-server.js +204 -0
- package/src/dispatch-webhook.js +221 -0
- package/src/dispatch.js +258 -0
- package/src/events-ws.js +269 -0
- package/src/identity.js +140 -0
- package/src/ids.js +18 -0
- package/src/mcp-http.js +208 -0
- package/src/mcp.js +107 -0
- package/src/merges.js +150 -0
- package/src/paths.js +15 -0
- package/src/ready-queue.js +77 -0
- package/src/release.js +96 -0
- package/src/reserved.js +23 -0
- package/src/schema.js +302 -0
- package/src/store/admission.js +314 -0
- package/src/store/artifacts.js +24 -0
- package/src/store/attempts.js +22 -0
- package/src/store/claims.js +182 -0
- package/src/store/core.js +225 -0
- package/src/store/delivery.js +137 -0
- package/src/store/deps.js +62 -0
- package/src/store/dispatch-events.js +38 -0
- package/src/store/epics.js +31 -0
- package/src/store/events.js +21 -0
- package/src/store/gates.js +85 -0
- package/src/store/index.js +135 -0
- package/src/store/items.js +303 -0
- package/src/store/stories.js +37 -0
- package/src/store/sweep.js +77 -0
- package/src/store/tasks.js +190 -0
- package/src/store/webhook.js +197 -0
- package/src/tools/accept-wake.js +30 -0
- package/src/tools/assign.js +75 -0
- package/src/tools/claim.js +88 -0
- package/src/tools/definitions.js +371 -0
- package/src/tools/delegate.js +147 -0
- package/src/tools/index.js +44 -0
- package/src/tools/plan.js +262 -0
- package/src/tools/read.js +103 -0
- package/src/tools/report.js +190 -0
- package/src/tools/shared.js +62 -0
- package/src/watcher.js +105 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
CREATE TABLE `deps` (
|
|
2
|
+
`from_id` text NOT NULL,
|
|
3
|
+
`from_kind` text NOT NULL,
|
|
4
|
+
`to_id` text NOT NULL,
|
|
5
|
+
`to_kind` text NOT NULL,
|
|
6
|
+
`created_at` integer NOT NULL,
|
|
7
|
+
PRIMARY KEY(`from_id`, `to_id`),
|
|
8
|
+
CONSTRAINT "deps_from_kind" CHECK("deps"."from_kind" IN ('epic', 'story', 'task')),
|
|
9
|
+
CONSTRAINT "deps_to_kind" CHECK("deps"."to_kind" IN ('epic', 'story', 'task'))
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE INDEX `idx_deps_from` ON `deps` (`from_id`);--> statement-breakpoint
|
|
13
|
+
CREATE INDEX `idx_deps_to` ON `deps` (`to_id`);--> statement-breakpoint
|
|
14
|
+
CREATE TABLE `epics` (
|
|
15
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
16
|
+
`title` text NOT NULL,
|
|
17
|
+
`description` text,
|
|
18
|
+
`acceptance` text,
|
|
19
|
+
`status` text NOT NULL,
|
|
20
|
+
`owner_team` text,
|
|
21
|
+
`priority` integer DEFAULT 50 NOT NULL,
|
|
22
|
+
`created_at` integer NOT NULL,
|
|
23
|
+
`updated_at` integer NOT NULL,
|
|
24
|
+
`closed_at` integer,
|
|
25
|
+
CONSTRAINT "epics_status" CHECK("epics"."status" IN ('idea', 'planned', 'in_progress', 'done', 'cancelled'))
|
|
26
|
+
);
|
|
27
|
+
--> statement-breakpoint
|
|
28
|
+
CREATE TABLE `events` (
|
|
29
|
+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
30
|
+
`task_id` text NOT NULL,
|
|
31
|
+
`from_status` text,
|
|
32
|
+
`to_status` text NOT NULL,
|
|
33
|
+
`actor` text,
|
|
34
|
+
`note` text,
|
|
35
|
+
`session_ref` text,
|
|
36
|
+
`at` integer NOT NULL
|
|
37
|
+
);
|
|
38
|
+
--> statement-breakpoint
|
|
39
|
+
CREATE INDEX `idx_events_task` ON `events` (`task_id`);--> statement-breakpoint
|
|
40
|
+
CREATE TABLE `session_budgets` (
|
|
41
|
+
`session_key` text PRIMARY KEY NOT NULL,
|
|
42
|
+
`agent_id` text NOT NULL,
|
|
43
|
+
`tool_calls` integer DEFAULT 0 NOT NULL,
|
|
44
|
+
`limit_calls` integer NOT NULL,
|
|
45
|
+
`exhausted_at` integer,
|
|
46
|
+
`empty_wakes` integer DEFAULT 0 NOT NULL,
|
|
47
|
+
`updated_at` integer NOT NULL
|
|
48
|
+
);
|
|
49
|
+
--> statement-breakpoint
|
|
50
|
+
CREATE TABLE `stories` (
|
|
51
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
52
|
+
`epic_id` text NOT NULL,
|
|
53
|
+
`title` text NOT NULL,
|
|
54
|
+
`description` text,
|
|
55
|
+
`acceptance` text,
|
|
56
|
+
`status` text NOT NULL,
|
|
57
|
+
`size` text,
|
|
58
|
+
`priority` integer DEFAULT 50 NOT NULL,
|
|
59
|
+
`assigned` text,
|
|
60
|
+
`capabilities` text,
|
|
61
|
+
`created_at` integer NOT NULL,
|
|
62
|
+
`updated_at` integer NOT NULL,
|
|
63
|
+
`closed_at` integer,
|
|
64
|
+
FOREIGN KEY (`epic_id`) REFERENCES `epics`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
65
|
+
CONSTRAINT "stories_status" CHECK("stories"."status" IN ('backlog', 'ready', 'in_progress', 'review', 'done', 'blocked', 'cancelled'))
|
|
66
|
+
);
|
|
67
|
+
--> statement-breakpoint
|
|
68
|
+
CREATE INDEX `idx_stories_epic` ON `stories` (`epic_id`);--> statement-breakpoint
|
|
69
|
+
CREATE INDEX `idx_stories_status_assigned` ON `stories` (`status`,`assigned`);--> statement-breakpoint
|
|
70
|
+
CREATE TABLE `tasks` (
|
|
71
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
72
|
+
`story_id` text NOT NULL,
|
|
73
|
+
`title` text NOT NULL,
|
|
74
|
+
`description` text,
|
|
75
|
+
`status` text NOT NULL,
|
|
76
|
+
`execution_kind` text NOT NULL,
|
|
77
|
+
`execution_args` text DEFAULT '{}' NOT NULL,
|
|
78
|
+
`assigned` text,
|
|
79
|
+
`capabilities` text,
|
|
80
|
+
`flow_id` text,
|
|
81
|
+
`task_run_id` text,
|
|
82
|
+
`claim_expires_at` integer,
|
|
83
|
+
`lease_seconds` integer,
|
|
84
|
+
`last_heartbeat` integer,
|
|
85
|
+
`attempt_count` integer DEFAULT 0 NOT NULL,
|
|
86
|
+
`gate_type` text,
|
|
87
|
+
`blocked_at` integer,
|
|
88
|
+
`result_summary` text,
|
|
89
|
+
`created_at` integer NOT NULL,
|
|
90
|
+
`updated_at` integer NOT NULL,
|
|
91
|
+
`claimed_at` integer,
|
|
92
|
+
`closed_at` integer,
|
|
93
|
+
FOREIGN KEY (`story_id`) REFERENCES `stories`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
94
|
+
CONSTRAINT "tasks_status" CHECK("tasks"."status" IN ('todo', 'in_progress', 'done', 'blocked', 'cancelled')),
|
|
95
|
+
CONSTRAINT "tasks_execution_kind" CHECK("tasks"."execution_kind" IN ('pipeclaw', 'subagent', 'cli', 'gate', 'manual'))
|
|
96
|
+
);
|
|
97
|
+
--> statement-breakpoint
|
|
98
|
+
CREATE INDEX `idx_tasks_story` ON `tasks` (`story_id`);--> statement-breakpoint
|
|
99
|
+
CREATE INDEX `idx_tasks_status_assigned` ON `tasks` (`status`,`assigned`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- events.kind: declared by producers at write time, read verbatim by the
|
|
2
|
+
-- emitter. Deliberately no backfill: notes are free text and can change, so
|
|
3
|
+
-- no migration rule may derive kinds from note content — a renamed note
|
|
4
|
+
-- would silently reclassify history. Pre-kind rows keep kind NULL and the
|
|
5
|
+
-- wire maps them by transition structure alone, exactly as they streamed
|
|
6
|
+
-- before this column existed. An append-only log keeps the meanings its
|
|
7
|
+
-- rows had when written.
|
|
8
|
+
ALTER TABLE `events` ADD `kind` text;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DROP TABLE `session_budgets`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `events` ADD `item_kind` text DEFAULT 'task' NOT NULL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `epics` ADD `created_by` text;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
-- One recursive item tree, lifecycle split out, attempts/sessions as
|
|
2
|
+
-- first-class rows, and a single append-only ledger. Data is copied from the
|
|
3
|
+
-- legacy tables before they are dropped, so the migration is in-place.
|
|
4
|
+
CREATE TABLE `items` (
|
|
5
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
6
|
+
`kind` text NOT NULL,
|
|
7
|
+
`parent_id` text,
|
|
8
|
+
`title` text NOT NULL,
|
|
9
|
+
`description` text,
|
|
10
|
+
`acceptance` text,
|
|
11
|
+
`priority` integer DEFAULT 50 NOT NULL,
|
|
12
|
+
`size` text,
|
|
13
|
+
`owner_team` text,
|
|
14
|
+
`created_by` text,
|
|
15
|
+
`execution_kind` text DEFAULT 'manual' NOT NULL,
|
|
16
|
+
`execution_args` text DEFAULT '{}' NOT NULL,
|
|
17
|
+
`created_at` integer NOT NULL,
|
|
18
|
+
FOREIGN KEY (`parent_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
19
|
+
CONSTRAINT "items_kind" CHECK("items"."kind" IN ('epic', 'story', 'task')),
|
|
20
|
+
CONSTRAINT "items_execution_kind" CHECK("items"."execution_kind" IN ('pipeclaw', 'subagent', 'cli', 'gate', 'manual')),
|
|
21
|
+
CONSTRAINT "items_root" CHECK(("items"."kind" = 'epic' AND "items"."parent_id" IS NULL) OR ("items"."kind" <> 'epic' AND "items"."parent_id" IS NOT NULL))
|
|
22
|
+
);
|
|
23
|
+
--> statement-breakpoint
|
|
24
|
+
CREATE INDEX `idx_items_parent` ON `items` (`parent_id`);--> statement-breakpoint
|
|
25
|
+
CREATE INDEX `idx_items_kind_created` ON `items` (`kind`,`created_at`);--> statement-breakpoint
|
|
26
|
+
CREATE TABLE `item_state` (
|
|
27
|
+
`item_id` text PRIMARY KEY NOT NULL,
|
|
28
|
+
`revision` integer DEFAULT 0 NOT NULL,
|
|
29
|
+
`status` text NOT NULL,
|
|
30
|
+
`state_json` text DEFAULT '{}' NOT NULL,
|
|
31
|
+
`wait_kind` text GENERATED ALWAYS AS (json_extract("state_json", '$.wait.kind')) VIRTUAL,
|
|
32
|
+
`assignee_harness` text,
|
|
33
|
+
`assignee_agent` text,
|
|
34
|
+
`updated_at` integer NOT NULL,
|
|
35
|
+
`closed_at` integer,
|
|
36
|
+
`deleted_at` integer,
|
|
37
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
38
|
+
CONSTRAINT "item_state_status" CHECK("item_state"."status" IN ('idea', 'planned', 'in_progress', 'done', 'cancelled', 'backlog', 'ready', 'review', 'blocked', 'todo')),
|
|
39
|
+
CONSTRAINT "item_state_assignment_pair" CHECK(("item_state"."assignee_harness" IS NULL) = ("item_state"."assignee_agent" IS NULL))
|
|
40
|
+
);
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
CREATE INDEX `idx_state_ready` ON `item_state` (`status`,`assignee_harness`,`assignee_agent`);--> statement-breakpoint
|
|
43
|
+
CREATE INDEX `idx_state_updated` ON `item_state` (`updated_at`);--> statement-breakpoint
|
|
44
|
+
CREATE INDEX `idx_state_deleted` ON `item_state` (`deleted_at`);--> statement-breakpoint
|
|
45
|
+
CREATE TABLE `item_tags` (
|
|
46
|
+
`item_id` text NOT NULL,
|
|
47
|
+
`tag` text NOT NULL,
|
|
48
|
+
`source` text,
|
|
49
|
+
`created_at` integer NOT NULL,
|
|
50
|
+
PRIMARY KEY(`item_id`, `tag`),
|
|
51
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade
|
|
52
|
+
);
|
|
53
|
+
--> statement-breakpoint
|
|
54
|
+
CREATE INDEX `idx_tags_tag` ON `item_tags` (`tag`);--> statement-breakpoint
|
|
55
|
+
CREATE TABLE `work_sessions` (
|
|
56
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
57
|
+
`item_id` text NOT NULL,
|
|
58
|
+
`harness` text NOT NULL,
|
|
59
|
+
`agent_id` text NOT NULL,
|
|
60
|
+
`external_session_id` text NOT NULL,
|
|
61
|
+
`session_key` text GENERATED ALWAYS AS ("harness" || ':' || "agent_id" || ':' || "external_session_id") VIRTUAL,
|
|
62
|
+
`kind` text DEFAULT 'claim' NOT NULL,
|
|
63
|
+
`created_at` integer NOT NULL,
|
|
64
|
+
`ended_at` integer,
|
|
65
|
+
`deleted_at` integer,
|
|
66
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
67
|
+
CONSTRAINT "work_sessions_kind" CHECK("work_sessions"."kind" IN ('claim', 'review', 'system'))
|
|
68
|
+
);
|
|
69
|
+
--> statement-breakpoint
|
|
70
|
+
CREATE UNIQUE INDEX `uq_sessions_identity` ON `work_sessions` (`harness`,`agent_id`,`external_session_id`);--> statement-breakpoint
|
|
71
|
+
CREATE INDEX `idx_sessions_item` ON `work_sessions` (`item_id`);--> statement-breakpoint
|
|
72
|
+
CREATE TABLE `attempts` (
|
|
73
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
74
|
+
`item_id` text NOT NULL,
|
|
75
|
+
`attempt_no` integer NOT NULL,
|
|
76
|
+
`session_id` text NOT NULL,
|
|
77
|
+
`status` text NOT NULL,
|
|
78
|
+
`claimed_at` integer NOT NULL,
|
|
79
|
+
`heartbeat_at` integer,
|
|
80
|
+
`lease_seconds` integer NOT NULL,
|
|
81
|
+
`expires_at` integer GENERATED ALWAYS AS (COALESCE("heartbeat_at", "claimed_at") + "lease_seconds" * 1000) VIRTUAL,
|
|
82
|
+
`ended_at` integer,
|
|
83
|
+
`result_json` text,
|
|
84
|
+
`result_summary` text GENERATED ALWAYS AS (json_extract("result_json", '$.summary')) VIRTUAL,
|
|
85
|
+
`error_type` text,
|
|
86
|
+
`gate_record_json` text,
|
|
87
|
+
`gate_type` text GENERATED ALWAYS AS (json_extract("gate_record_json", '$.type')) VIRTUAL,
|
|
88
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
89
|
+
FOREIGN KEY (`session_id`) REFERENCES `work_sessions`(`id`) ON UPDATE no action ON DELETE restrict,
|
|
90
|
+
CONSTRAINT "attempts_status" CHECK("attempts"."status" IN ('claimed', 'running', 'gated', 'done', 'failed', 'released', 'cancelled'))
|
|
91
|
+
);
|
|
92
|
+
--> statement-breakpoint
|
|
93
|
+
CREATE UNIQUE INDEX `uq_attempt_item_no` ON `attempts` (`item_id`,`attempt_no`);--> statement-breakpoint
|
|
94
|
+
CREATE INDEX `idx_attempt_session` ON `attempts` (`session_id`);--> statement-breakpoint
|
|
95
|
+
CREATE UNIQUE INDEX `uq_attempt_live` ON `attempts` (`item_id`) WHERE "attempts"."ended_at" IS NULL;--> statement-breakpoint
|
|
96
|
+
CREATE INDEX `idx_attempts_expiry` ON `attempts` (`status`,`expires_at`);--> statement-breakpoint
|
|
97
|
+
CREATE TABLE `artifacts` (
|
|
98
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
99
|
+
`item_id` text NOT NULL,
|
|
100
|
+
`attempt_id` text,
|
|
101
|
+
`kind` text NOT NULL,
|
|
102
|
+
`uri` text NOT NULL,
|
|
103
|
+
`sha256` text,
|
|
104
|
+
`label` text,
|
|
105
|
+
`created_at` integer NOT NULL,
|
|
106
|
+
`deleted_at` integer,
|
|
107
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
108
|
+
FOREIGN KEY (`attempt_id`) REFERENCES `attempts`(`id`) ON UPDATE no action ON DELETE set null
|
|
109
|
+
);
|
|
110
|
+
--> statement-breakpoint
|
|
111
|
+
CREATE UNIQUE INDEX `uq_artifacts_uri` ON `artifacts` (`uri`);--> statement-breakpoint
|
|
112
|
+
CREATE INDEX `idx_artifacts_item` ON `artifacts` (`item_id`);--> statement-breakpoint
|
|
113
|
+
CREATE INDEX `idx_artifacts_attempt` ON `artifacts` (`attempt_id`);--> statement-breakpoint
|
|
114
|
+
CREATE TABLE `item_events` (
|
|
115
|
+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
116
|
+
`item_id` text NOT NULL,
|
|
117
|
+
`attempt_id` text,
|
|
118
|
+
`session_id` text,
|
|
119
|
+
`from_status` text,
|
|
120
|
+
`to_status` text NOT NULL,
|
|
121
|
+
`kind` text,
|
|
122
|
+
`actor` text,
|
|
123
|
+
`note` text,
|
|
124
|
+
`payload_json` text,
|
|
125
|
+
`created_at` integer NOT NULL,
|
|
126
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE restrict,
|
|
127
|
+
FOREIGN KEY (`attempt_id`) REFERENCES `attempts`(`id`) ON UPDATE no action ON DELETE set null,
|
|
128
|
+
FOREIGN KEY (`session_id`) REFERENCES `work_sessions`(`id`) ON UPDATE no action ON DELETE set null
|
|
129
|
+
);
|
|
130
|
+
--> statement-breakpoint
|
|
131
|
+
CREATE INDEX `idx_item_events_item` ON `item_events` (`item_id`);--> statement-breakpoint
|
|
132
|
+
CREATE INDEX `idx_item_events_created` ON `item_events` (`created_at`);--> statement-breakpoint
|
|
133
|
+
CREATE TABLE `item_edges` (
|
|
134
|
+
`from_item_id` text NOT NULL,
|
|
135
|
+
`to_item_id` text NOT NULL,
|
|
136
|
+
`kind` text DEFAULT 'depends_on' NOT NULL,
|
|
137
|
+
`created_at` integer NOT NULL,
|
|
138
|
+
PRIMARY KEY(`from_item_id`, `to_item_id`, `kind`),
|
|
139
|
+
FOREIGN KEY (`from_item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
140
|
+
FOREIGN KEY (`to_item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
141
|
+
CONSTRAINT "item_edges_kind" CHECK("item_edges"."kind" IN ('depends_on'))
|
|
142
|
+
);
|
|
143
|
+
--> statement-breakpoint
|
|
144
|
+
CREATE INDEX `idx_edges_from` ON `item_edges` (`from_item_id`);--> statement-breakpoint
|
|
145
|
+
CREATE INDEX `idx_edges_to` ON `item_edges` (`to_item_id`);--> statement-breakpoint
|
|
146
|
+
CREATE TABLE `harness_webhooks` (
|
|
147
|
+
`harness` text PRIMARY KEY NOT NULL,
|
|
148
|
+
`url` text NOT NULL,
|
|
149
|
+
`bearer` text,
|
|
150
|
+
`timeout_ms` integer,
|
|
151
|
+
`created_at` integer NOT NULL,
|
|
152
|
+
`updated_at` integer NOT NULL
|
|
153
|
+
);
|
|
154
|
+
--> statement-breakpoint
|
|
155
|
+
-- ── copy legacy rows into the recursive tree ─────────────────────────────
|
|
156
|
+
INSERT INTO items (id, kind, parent_id, title, description, acceptance,
|
|
157
|
+
priority, size, owner_team, created_by, execution_kind, execution_args, created_at)
|
|
158
|
+
SELECT id, 'epic', NULL, title, description, acceptance,
|
|
159
|
+
priority, NULL, owner_team, created_by, 'manual', '{}', created_at
|
|
160
|
+
FROM epics;
|
|
161
|
+
--> statement-breakpoint
|
|
162
|
+
INSERT INTO items (id, kind, parent_id, title, description, acceptance,
|
|
163
|
+
priority, size, owner_team, created_by, execution_kind, execution_args, created_at)
|
|
164
|
+
SELECT id, 'story', epic_id, title, description, acceptance,
|
|
165
|
+
priority, size, NULL, NULL, 'manual', '{}', created_at
|
|
166
|
+
FROM stories;
|
|
167
|
+
--> statement-breakpoint
|
|
168
|
+
INSERT INTO items (id, kind, parent_id, title, description, acceptance,
|
|
169
|
+
priority, size, owner_team, created_by, execution_kind, execution_args, created_at)
|
|
170
|
+
SELECT id, 'task', story_id, title, description, NULL,
|
|
171
|
+
50, NULL, NULL, NULL, execution_kind, COALESCE(execution_args, '{}'), created_at
|
|
172
|
+
FROM tasks;
|
|
173
|
+
--> statement-breakpoint
|
|
174
|
+
INSERT INTO item_state (item_id, revision, status, state_json, assignee_harness, assignee_agent, updated_at, closed_at)
|
|
175
|
+
SELECT id, 0, status, '{}', NULL, NULL, updated_at, closed_at FROM epics;
|
|
176
|
+
--> statement-breakpoint
|
|
177
|
+
INSERT INTO item_state (item_id, revision, status, state_json, assignee_harness, assignee_agent, updated_at, closed_at)
|
|
178
|
+
SELECT id, 0, status, '{}',
|
|
179
|
+
CASE WHEN assigned IS NULL THEN NULL ELSE 'legacy' END,
|
|
180
|
+
assigned, updated_at, closed_at
|
|
181
|
+
FROM stories;
|
|
182
|
+
--> statement-breakpoint
|
|
183
|
+
INSERT INTO item_state (item_id, revision, status, state_json, assignee_harness, assignee_agent, updated_at, closed_at)
|
|
184
|
+
SELECT id, 0, status, '{}',
|
|
185
|
+
CASE WHEN assigned IS NULL THEN NULL ELSE 'legacy' END,
|
|
186
|
+
assigned, updated_at, closed_at
|
|
187
|
+
FROM tasks;
|
|
188
|
+
--> statement-breakpoint
|
|
189
|
+
INSERT OR IGNORE INTO item_tags (item_id, tag, source, created_at)
|
|
190
|
+
SELECT s.id, j.value, 'legacy', s.created_at
|
|
191
|
+
FROM stories s, json_each(s.capabilities) j
|
|
192
|
+
WHERE s.capabilities IS NOT NULL AND json_valid(s.capabilities);
|
|
193
|
+
--> statement-breakpoint
|
|
194
|
+
INSERT OR IGNORE INTO item_tags (item_id, tag, source, created_at)
|
|
195
|
+
SELECT t.id, j.value, 'legacy', t.created_at
|
|
196
|
+
FROM tasks t, json_each(t.capabilities) j
|
|
197
|
+
WHERE t.capabilities IS NOT NULL AND json_valid(t.capabilities);
|
|
198
|
+
--> statement-breakpoint
|
|
199
|
+
INSERT INTO item_edges (from_item_id, to_item_id, kind, created_at)
|
|
200
|
+
SELECT d.from_id, d.to_id, 'depends_on', d.created_at
|
|
201
|
+
FROM deps d
|
|
202
|
+
WHERE EXISTS (SELECT 1 FROM items i WHERE i.id = d.from_id)
|
|
203
|
+
AND EXISTS (SELECT 1 FROM items i WHERE i.id = d.to_id);
|
|
204
|
+
--> statement-breakpoint
|
|
205
|
+
INSERT INTO work_sessions (id, item_id, harness, agent_id, external_session_id, kind, created_at)
|
|
206
|
+
SELECT 'SES-legacy-' || id, id, 'legacy',
|
|
207
|
+
COALESCE(assigned, 'system'), 'legacy-' || id, 'system', COALESCE(claimed_at, created_at)
|
|
208
|
+
FROM tasks
|
|
209
|
+
WHERE claimed_at IS NOT NULL OR attempt_count > 0
|
|
210
|
+
OR status IN ('in_progress', 'blocked', 'done', 'cancelled');
|
|
211
|
+
--> statement-breakpoint
|
|
212
|
+
INSERT INTO attempts (id, item_id, attempt_no, session_id, status, claimed_at, heartbeat_at,
|
|
213
|
+
lease_seconds, ended_at, result_json, error_type, gate_record_json)
|
|
214
|
+
SELECT 'ATT-legacy-' || t.id, t.id, MAX(COALESCE(t.attempt_count, 1), 1),
|
|
215
|
+
'SES-legacy-' || t.id,
|
|
216
|
+
CASE
|
|
217
|
+
WHEN t.status = 'in_progress' THEN 'running'
|
|
218
|
+
WHEN t.status = 'blocked' AND t.gate_type IS NOT NULL THEN 'gated'
|
|
219
|
+
WHEN t.status = 'done' THEN 'done'
|
|
220
|
+
WHEN t.status = 'cancelled' THEN 'cancelled'
|
|
221
|
+
ELSE 'released'
|
|
222
|
+
END,
|
|
223
|
+
COALESCE(t.claimed_at, t.created_at), t.last_heartbeat,
|
|
224
|
+
COALESCE(t.lease_seconds, 1800),
|
|
225
|
+
CASE WHEN t.status = 'in_progress' THEN NULL ELSE COALESCE(t.closed_at, t.updated_at, t.claimed_at) END,
|
|
226
|
+
CASE WHEN t.result_summary IS NOT NULL THEN json_object('summary', t.result_summary) END,
|
|
227
|
+
NULL,
|
|
228
|
+
CASE WHEN t.gate_type IS NOT NULL
|
|
229
|
+
THEN json_object('type', t.gate_type, 'openedAt', COALESCE(t.blocked_at, t.updated_at)) END
|
|
230
|
+
FROM tasks t
|
|
231
|
+
WHERE t.claimed_at IS NOT NULL OR t.attempt_count > 0
|
|
232
|
+
OR t.status IN ('in_progress', 'blocked', 'done', 'cancelled');
|
|
233
|
+
--> statement-breakpoint
|
|
234
|
+
-- Event ids are preserved: the WebSocket cursor is an id, and a reopen must
|
|
235
|
+
-- not replay or skip history.
|
|
236
|
+
INSERT INTO item_events (id, item_id, attempt_id, session_id, from_status, to_status, kind, actor, note, payload_json, created_at)
|
|
237
|
+
SELECT e.id, e.task_id,
|
|
238
|
+
(SELECT a.id FROM attempts a WHERE a.item_id = e.task_id LIMIT 1),
|
|
239
|
+
(SELECT a.session_id FROM attempts a WHERE a.item_id = e.task_id LIMIT 1),
|
|
240
|
+
e.from_status, e.to_status, e.kind, e.actor, e.note, NULL, e.at
|
|
241
|
+
FROM events e
|
|
242
|
+
WHERE EXISTS (SELECT 1 FROM items i WHERE i.id = e.task_id);
|
|
243
|
+
--> statement-breakpoint
|
|
244
|
+
INSERT OR IGNORE INTO artifacts (id, item_id, attempt_id, kind, uri, label, created_at)
|
|
245
|
+
SELECT 'ART-legacy-' || e.id, e.task_id,
|
|
246
|
+
(SELECT a.id FROM attempts a WHERE a.item_id = e.task_id LIMIT 1),
|
|
247
|
+
'link', trim(substr(e.note, 11)), 'legacy', e.at
|
|
248
|
+
FROM events e
|
|
249
|
+
WHERE e.note LIKE 'artifact: %'
|
|
250
|
+
AND EXISTS (SELECT 1 FROM items i WHERE i.id = e.task_id);
|
|
251
|
+
--> statement-breakpoint
|
|
252
|
+
INSERT INTO harness_webhooks (harness, url, bearer, timeout_ms, created_at, updated_at)
|
|
253
|
+
SELECT harness, url, bearer, timeout_ms, created_at, updated_at FROM webhook_targets;
|
|
254
|
+
--> statement-breakpoint
|
|
255
|
+
DROP TABLE `webhook_targets`;
|
|
256
|
+
--> statement-breakpoint
|
|
257
|
+
DROP TABLE `deps`;
|
|
258
|
+
--> statement-breakpoint
|
|
259
|
+
DROP TABLE `events`;
|
|
260
|
+
--> statement-breakpoint
|
|
261
|
+
DROP TABLE `tasks`;
|
|
262
|
+
--> statement-breakpoint
|
|
263
|
+
DROP TABLE `stories`;
|
|
264
|
+
--> statement-breakpoint
|
|
265
|
+
DROP TABLE `epics`;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
2
|
+
CREATE TABLE `__new_item_state` (
|
|
3
|
+
`item_id` text PRIMARY KEY NOT NULL,
|
|
4
|
+
`revision` integer DEFAULT 0 NOT NULL,
|
|
5
|
+
`status` text NOT NULL,
|
|
6
|
+
`state_json` text DEFAULT '{}' NOT NULL,
|
|
7
|
+
`wait_kind` text GENERATED ALWAYS AS (json_extract("state_json", '$.wait.kind')) VIRTUAL,
|
|
8
|
+
`assignee_harness` text,
|
|
9
|
+
`assignee_agent` text,
|
|
10
|
+
`updated_at` integer NOT NULL,
|
|
11
|
+
`closed_at` integer,
|
|
12
|
+
`deleted_at` integer,
|
|
13
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
14
|
+
CONSTRAINT "item_state_status" CHECK("__new_item_state"."status" IN ('backlog', 'ready', 'in_progress', 'blocked', 'review', 'done', 'cancelled')),
|
|
15
|
+
CONSTRAINT "item_state_assignment_pair" CHECK(("__new_item_state"."assignee_harness" IS NULL) = ("__new_item_state"."assignee_agent" IS NULL)),
|
|
16
|
+
CONSTRAINT "item_state_human_pair" CHECK(("__new_item_state"."assignee_agent" IS 'human') = ("__new_item_state"."assignee_harness" IS 'human_in_the_loop')),
|
|
17
|
+
CONSTRAINT "item_state_ready_assigned" CHECK("__new_item_state"."status" <> 'ready' OR ("__new_item_state"."assignee_harness" IS NOT NULL AND "__new_item_state"."assignee_agent" IS NOT NULL))
|
|
18
|
+
);
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
INSERT INTO `__new_item_state`("item_id", "revision", "status", "state_json", "assignee_harness", "assignee_agent", "updated_at", "closed_at", "deleted_at") SELECT "item_id", "revision", CASE
|
|
21
|
+
WHEN "assignee_harness" = 'legacy' THEN CASE WHEN "status" IN ('done', 'cancelled') THEN "status" ELSE 'backlog' END
|
|
22
|
+
WHEN "assignee_harness" IS NULL AND "status" NOT IN ('backlog', 'done', 'cancelled') THEN 'backlog'
|
|
23
|
+
WHEN "status" IN ('todo', 'planned') AND "assignee_harness" IS NOT NULL AND "assignee_agent" IS NOT NULL THEN 'ready'
|
|
24
|
+
WHEN "status" IN ('todo', 'planned', 'idea') THEN 'backlog'
|
|
25
|
+
WHEN "status" = 'ready' AND ("assignee_harness" IS NULL OR "assignee_agent" IS NULL) THEN 'backlog'
|
|
26
|
+
ELSE "status" END, "state_json",
|
|
27
|
+
CASE WHEN "assignee_harness" = 'legacy' THEN NULL ELSE "assignee_harness" END,
|
|
28
|
+
CASE WHEN "assignee_harness" = 'legacy' THEN NULL ELSE "assignee_agent" END,
|
|
29
|
+
"updated_at", "closed_at", "deleted_at" FROM `item_state`;--> statement-breakpoint
|
|
30
|
+
DROP TABLE `item_state`;--> statement-breakpoint
|
|
31
|
+
ALTER TABLE `__new_item_state` RENAME TO `item_state`;--> statement-breakpoint
|
|
32
|
+
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
33
|
+
CREATE INDEX `idx_state_ready` ON `item_state` (`status`,`assignee_harness`,`assignee_agent`);--> statement-breakpoint
|
|
34
|
+
CREATE INDEX `idx_state_updated` ON `item_state` (`updated_at`);--> statement-breakpoint
|
|
35
|
+
CREATE INDEX `idx_state_deleted` ON `item_state` (`deleted_at`);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
2
|
+
CREATE TABLE `admission_queue` (
|
|
3
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
4
|
+
`kind` text NOT NULL,
|
|
5
|
+
`item_id` text NOT NULL,
|
|
6
|
+
`harness` text NOT NULL,
|
|
7
|
+
`agent_id` text NOT NULL,
|
|
8
|
+
`status` text DEFAULT 'queued' NOT NULL,
|
|
9
|
+
`event_id` integer,
|
|
10
|
+
`created_at` integer NOT NULL,
|
|
11
|
+
`ended_at` integer,
|
|
12
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
13
|
+
CONSTRAINT "admission_kind" CHECK("admission_queue"."kind" IN ('task', 'story', 'append', 'review', 'unblocked')),
|
|
14
|
+
CONSTRAINT "admission_status" CHECK("admission_queue"."status" IN ('queued', 'offered', 'accepted', 'active', 'done', 'cancelled', 'expired'))
|
|
15
|
+
);
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
CREATE UNIQUE INDEX `uq_admission_live` ON `admission_queue` (`item_id`,`harness`) WHERE "admission_queue"."ended_at" IS NULL;--> statement-breakpoint
|
|
18
|
+
CREATE INDEX `idx_admission_harness` ON `admission_queue` (`status`,`harness`,`created_at`);--> statement-breakpoint
|
|
19
|
+
CREATE INDEX `idx_admission_global` ON `admission_queue` (`status`,`created_at`);--> statement-breakpoint
|
|
20
|
+
CREATE INDEX `idx_admission_item` ON `admission_queue` (`item_id`);--> statement-breakpoint
|
|
21
|
+
CREATE TABLE `admission_attempts` (
|
|
22
|
+
`admission_id` text NOT NULL,
|
|
23
|
+
`attempt_no` integer NOT NULL,
|
|
24
|
+
`executor_id` text,
|
|
25
|
+
`offered_at` integer NOT NULL,
|
|
26
|
+
`accepted_at` integer,
|
|
27
|
+
`ended_at` integer,
|
|
28
|
+
PRIMARY KEY(`admission_id`, `attempt_no`),
|
|
29
|
+
FOREIGN KEY (`admission_id`) REFERENCES `admission_queue`(`id`) ON UPDATE no action ON DELETE cascade
|
|
30
|
+
);
|
|
31
|
+
--> statement-breakpoint
|
|
32
|
+
CREATE UNIQUE INDEX `uq_admission_attempt_live` ON `admission_attempts` (`admission_id`) WHERE "admission_attempts"."ended_at" IS NULL;--> statement-breakpoint
|
|
33
|
+
CREATE INDEX `idx_admission_attempts_executor` ON `admission_attempts` (`executor_id`,`ended_at`);--> statement-breakpoint
|
|
34
|
+
CREATE TABLE `__new_work_sessions` (
|
|
35
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
36
|
+
`item_id` text NOT NULL,
|
|
37
|
+
`harness` text NOT NULL,
|
|
38
|
+
`agent_id` text NOT NULL,
|
|
39
|
+
`external_session_id` text NOT NULL,
|
|
40
|
+
`session_key` text GENERATED ALWAYS AS ("harness" || ':' || "agent_id" || ':' || "external_session_id") VIRTUAL,
|
|
41
|
+
`kind` text DEFAULT 'claim' NOT NULL,
|
|
42
|
+
`parent_session_id` text,
|
|
43
|
+
`created_at` integer NOT NULL,
|
|
44
|
+
`ended_at` integer,
|
|
45
|
+
`deleted_at` integer,
|
|
46
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
47
|
+
FOREIGN KEY (`parent_session_id`) REFERENCES `work_sessions`(`id`) ON UPDATE no action ON DELETE set null,
|
|
48
|
+
CONSTRAINT "work_sessions_kind" CHECK("__new_work_sessions"."kind" IN ('claim', 'review', 'system', 'fanout'))
|
|
49
|
+
);
|
|
50
|
+
--> statement-breakpoint
|
|
51
|
+
INSERT INTO `__new_work_sessions`("id", "item_id", "harness", "agent_id", "external_session_id", "kind", "parent_session_id", "created_at", "ended_at", "deleted_at") SELECT "id", "item_id", "harness", "agent_id", "external_session_id", "kind", NULL, "created_at", "ended_at", "deleted_at" FROM `work_sessions`;--> statement-breakpoint
|
|
52
|
+
DROP TABLE `work_sessions`;--> statement-breakpoint
|
|
53
|
+
ALTER TABLE `__new_work_sessions` RENAME TO `work_sessions`;--> statement-breakpoint
|
|
54
|
+
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
55
|
+
CREATE UNIQUE INDEX `uq_sessions_identity` ON `work_sessions` (`harness`,`agent_id`,`external_session_id`);--> statement-breakpoint
|
|
56
|
+
CREATE INDEX `idx_sessions_item` ON `work_sessions` (`item_id`);--> statement-breakpoint
|
|
57
|
+
CREATE INDEX `idx_sessions_parent` ON `work_sessions` (`parent_session_id`);--> statement-breakpoint
|
|
58
|
+
ALTER TABLE `item_state` ADD `current_child_key` text GENERATED ALWAYS AS (json_extract("state_json", '$.currentChildKey')) VIRTUAL;--> statement-breakpoint
|
|
59
|
+
ALTER TABLE `items` ADD `child_key` text;--> statement-breakpoint
|
|
60
|
+
ALTER TABLE `items` ADD `visit_seq` integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
61
|
+
CREATE UNIQUE INDEX `uq_items_child` ON `items` (`parent_id`,`child_key`,`visit_seq`) WHERE "items"."child_key" IS NOT NULL;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
CREATE TABLE `webhooks` (
|
|
2
|
+
`topic` text NOT NULL,
|
|
3
|
+
`id` text NOT NULL,
|
|
4
|
+
`harness` text,
|
|
5
|
+
`executor_id` text,
|
|
6
|
+
`url` text NOT NULL,
|
|
7
|
+
`bearer` text NOT NULL,
|
|
8
|
+
`timeout_ms` integer,
|
|
9
|
+
`created_at` integer NOT NULL,
|
|
10
|
+
`updated_at` integer NOT NULL,
|
|
11
|
+
`last_seen_at` integer NOT NULL,
|
|
12
|
+
PRIMARY KEY(`topic`, `id`)
|
|
13
|
+
);
|
|
14
|
+
--> statement-breakpoint
|
|
15
|
+
CREATE INDEX `idx_webhooks_topic_harness` ON `webhooks` (`topic`,`harness`,`last_seen_at`);--> statement-breakpoint
|
|
16
|
+
DROP TABLE `harness_webhooks`;--> statement-breakpoint
|
|
17
|
+
DROP TABLE IF EXISTS `dispatch_webhooks`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `admission_attempts` ADD `consumer_id` text;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
CREATE TABLE `dispatch_deliveries` (
|
|
2
|
+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
3
|
+
`admission_id` text NOT NULL,
|
|
4
|
+
`attempt_no` integer NOT NULL,
|
|
5
|
+
`consumer_id` text NOT NULL,
|
|
6
|
+
`status` text DEFAULT 'pending' NOT NULL,
|
|
7
|
+
`attempts` integer DEFAULT 0 NOT NULL,
|
|
8
|
+
`next_at` integer NOT NULL,
|
|
9
|
+
`last_status` integer,
|
|
10
|
+
`last_error` text,
|
|
11
|
+
`delivered_at` integer,
|
|
12
|
+
`dead_at` integer,
|
|
13
|
+
`created_at` integer NOT NULL,
|
|
14
|
+
`updated_at` integer NOT NULL,
|
|
15
|
+
FOREIGN KEY (`admission_id`) REFERENCES `admission_queue`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
16
|
+
CONSTRAINT "delivery_status" CHECK("dispatch_deliveries"."status" IN ('pending', 'delivering', 'delivered', 'dead', 'cancelled'))
|
|
17
|
+
);
|
|
18
|
+
--> statement-breakpoint
|
|
19
|
+
CREATE UNIQUE INDEX `uq_delivery_grain` ON `dispatch_deliveries` (`admission_id`,`attempt_no`,`consumer_id`);--> statement-breakpoint
|
|
20
|
+
CREATE INDEX `idx_delivery_due` ON `dispatch_deliveries` (`status`,`next_at`);--> statement-breakpoint
|
|
21
|
+
CREATE INDEX `idx_delivery_attempt` ON `dispatch_deliveries` (`admission_id`,`attempt_no`);--> statement-breakpoint
|
|
22
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
23
|
+
CREATE TABLE `__new_webhooks` (
|
|
24
|
+
`topic` text NOT NULL,
|
|
25
|
+
`id` text NOT NULL,
|
|
26
|
+
`harness` text,
|
|
27
|
+
`executor_id` text,
|
|
28
|
+
`url` text NOT NULL,
|
|
29
|
+
`bearer` text NOT NULL,
|
|
30
|
+
`timeout_ms` integer,
|
|
31
|
+
`created_at` integer NOT NULL,
|
|
32
|
+
`updated_at` integer NOT NULL,
|
|
33
|
+
`last_seen_at` integer NOT NULL,
|
|
34
|
+
`instance_id` text,
|
|
35
|
+
`generation` integer DEFAULT 0 NOT NULL,
|
|
36
|
+
`state` text DEFAULT 'active' NOT NULL,
|
|
37
|
+
`failure_count` integer DEFAULT 0 NOT NULL,
|
|
38
|
+
`last_error` text,
|
|
39
|
+
`disabled_at` integer,
|
|
40
|
+
`lease_until` integer,
|
|
41
|
+
PRIMARY KEY(`topic`, `id`),
|
|
42
|
+
CONSTRAINT "webhooks_state" CHECK("__new_webhooks"."state" IN ('active', 'suspect', 'disabled'))
|
|
43
|
+
);
|
|
44
|
+
--> statement-breakpoint
|
|
45
|
+
INSERT INTO `__new_webhooks`("topic", "id", "harness", "executor_id", "url", "bearer", "timeout_ms", "created_at", "updated_at", "last_seen_at", "instance_id", "generation", "state", "failure_count", "last_error", "disabled_at", "lease_until") SELECT "topic", "id", "harness", "executor_id", "url", "bearer", "timeout_ms", "created_at", "updated_at", "last_seen_at", NULL, 0, 'active', 0, NULL, NULL, NULL FROM `webhooks`;--> statement-breakpoint
|
|
46
|
+
DROP TABLE `webhooks`;--> statement-breakpoint
|
|
47
|
+
ALTER TABLE `__new_webhooks` RENAME TO `webhooks`;--> statement-breakpoint
|
|
48
|
+
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
49
|
+
CREATE INDEX `idx_webhooks_topic_harness` ON `webhooks` (`topic`,`harness`,`state`,`last_seen_at`);--> statement-breakpoint
|
|
50
|
+
ALTER TABLE `admission_attempts` ADD `active_consumer_id` text;--> statement-breakpoint
|
|
51
|
+
ALTER TABLE `admission_attempts` ADD `lease_epoch` integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
52
|
+
ALTER TABLE `admission_attempts` ADD `lease_until` integer;--> statement-breakpoint
|
|
53
|
+
ALTER TABLE `attempts` ADD `consumer_id` text;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
CREATE TABLE `dispatch_delivery_attempts` (
|
|
2
|
+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
3
|
+
`delivery_id` integer NOT NULL,
|
|
4
|
+
`attempt_no` integer NOT NULL,
|
|
5
|
+
`status` text NOT NULL,
|
|
6
|
+
`response_status` integer,
|
|
7
|
+
`error` text,
|
|
8
|
+
`created_at` integer NOT NULL,
|
|
9
|
+
FOREIGN KEY (`delivery_id`) REFERENCES `dispatch_deliveries`(`id`) ON UPDATE no action ON DELETE cascade
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE INDEX `idx_delivery_attempts_delivery` ON `dispatch_delivery_attempts` (`delivery_id`,`attempt_no`);--> statement-breakpoint
|
|
13
|
+
CREATE TABLE `dispatch_events` (
|
|
14
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
15
|
+
`admission_id` text NOT NULL,
|
|
16
|
+
`attempt_no` integer NOT NULL,
|
|
17
|
+
`item_id` text NOT NULL,
|
|
18
|
+
`source_event_id` integer,
|
|
19
|
+
`payload_json` text DEFAULT '{}' NOT NULL,
|
|
20
|
+
`created_at` integer NOT NULL,
|
|
21
|
+
`published_at` integer,
|
|
22
|
+
FOREIGN KEY (`admission_id`) REFERENCES `admission_queue`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
23
|
+
FOREIGN KEY (`item_id`) REFERENCES `items`(`id`) ON UPDATE no action ON DELETE cascade
|
|
24
|
+
);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
CREATE UNIQUE INDEX `uq_dispatch_event_attempt` ON `dispatch_events` (`admission_id`,`attempt_no`);--> statement-breakpoint
|
|
27
|
+
CREATE INDEX `idx_dispatch_events_created` ON `dispatch_events` (`created_at`);--> statement-breakpoint
|
|
28
|
+
ALTER TABLE `attempts` ADD `owner_instance` text;--> statement-breakpoint
|
|
29
|
+
ALTER TABLE `attempts` ADD `lease_epoch` integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
30
|
+
ALTER TABLE `dispatch_deliveries` ADD `event_id` text;--> statement-breakpoint
|
|
31
|
+
CREATE INDEX `idx_delivery_event` ON `dispatch_deliveries` (`event_id`,`consumer_id`);--> statement-breakpoint
|
|
32
|
+
ALTER TABLE `webhooks` ADD `managed` integer DEFAULT 0 NOT NULL;
|