@rudderhq/db 0.7.23 → 0.7.24-canary.1
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/dist/client.test.js +164 -0
- package/dist/client.test.js.map +1 -1
- package/dist/migrations/0164_native_chat_runtime_binding.sql +394 -0
- package/dist/migrations/0165_heartbeat_attempt_owner_fencing.sql +10 -0
- package/dist/migrations/0166_runtime_binding_targets.sql +38 -0
- package/dist/migrations/0167_delegation_run_scene.sql +4 -0
- package/dist/migrations/meta/_journal.json +28 -0
- package/dist/native-chat-runtime-binding-schema.test.d.ts +2 -0
- package/dist/native-chat-runtime-binding-schema.test.d.ts.map +1 -0
- package/dist/native-chat-runtime-binding-schema.test.js +107 -0
- package/dist/native-chat-runtime-binding-schema.test.js.map +1 -0
- package/dist/schema/chat_conversations.d.ts.map +1 -1
- package/dist/schema/chat_conversations.js +1 -0
- package/dist/schema/chat_conversations.js.map +1 -1
- package/dist/schema/heartbeat_run_attempts.d.ts +34 -0
- package/dist/schema/heartbeat_run_attempts.d.ts.map +1 -1
- package/dist/schema/heartbeat_run_attempts.js +12 -1
- package/dist/schema/heartbeat_run_attempts.js.map +1 -1
- package/dist/schema/heartbeat_runs.d.ts +87 -0
- package/dist/schema/heartbeat_runs.d.ts.map +1 -1
- package/dist/schema/heartbeat_runs.js +77 -0
- package/dist/schema/heartbeat_runs.js.map +1 -1
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +2 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/runtime_bindings.d.ts +1052 -0
- package/dist/schema/runtime_bindings.d.ts.map +1 -0
- package/dist/schema/runtime_bindings.js +227 -0
- package/dist/schema/runtime_bindings.js.map +1 -0
- package/dist/schema/runtime_retention.d.ts +589 -0
- package/dist/schema/runtime_retention.d.ts.map +1 -0
- package/dist/schema/runtime_retention.js +111 -0
- package/dist/schema/runtime_retention.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "scene" text;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "target_type" text;
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "target_id" text;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "idempotency_key" text;
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "heartbeat_runs" ADD COLUMN "session_intent_json" jsonb;
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_common_run_identity_check"
|
|
12
|
+
CHECK (
|
|
13
|
+
("scene" IS NULL AND "target_type" IS NULL AND "target_id" IS NULL
|
|
14
|
+
AND "idempotency_key" IS NULL AND "session_intent_json" IS NULL)
|
|
15
|
+
OR
|
|
16
|
+
("scene" IS NOT NULL AND "target_type" IS NOT NULL AND "target_id" IS NOT NULL
|
|
17
|
+
AND "idempotency_key" IS NOT NULL AND "session_intent_json" IS NOT NULL)
|
|
18
|
+
);
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_scene_check"
|
|
21
|
+
CHECK ("scene" IS NULL OR "scene" IN ('chat', 'side_chat', 'issue', 'review', 'automation', 'heartbeat'));
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_target_check"
|
|
24
|
+
CHECK (
|
|
25
|
+
("target_type" IS NULL AND "target_id" IS NULL)
|
|
26
|
+
OR
|
|
27
|
+
("target_type" IS NOT NULL AND "target_type" IN ('issue', 'chat_conversation', 'chat_message', 'automation_run', 'wakeup_request', 'manual', 'review')
|
|
28
|
+
AND "target_id" IS NOT NULL AND "target_id" = btrim("target_id") AND btrim("target_id") <> '')
|
|
29
|
+
);
|
|
30
|
+
--> statement-breakpoint
|
|
31
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_idempotency_key_check"
|
|
32
|
+
CHECK ("idempotency_key" IS NULL OR ("idempotency_key" = btrim("idempotency_key") AND octet_length("idempotency_key") BETWEEN 1 AND 512));
|
|
33
|
+
--> statement-breakpoint
|
|
34
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_session_intent_shape_check"
|
|
35
|
+
CHECK (
|
|
36
|
+
"session_intent_json" IS NULL
|
|
37
|
+
OR (
|
|
38
|
+
jsonb_typeof("session_intent_json") = 'object'
|
|
39
|
+
AND "session_intent_json" ?& ARRAY['kind', 'reuseScope', 'sourceRunId', 'sessionId', 'sessionParams']
|
|
40
|
+
AND jsonb_typeof("session_intent_json"->'kind') = 'string'
|
|
41
|
+
AND jsonb_typeof("session_intent_json"->'reuseScope') = 'string'
|
|
42
|
+
AND "session_intent_json"->>'kind' IN ('fresh', 'resume', 'fork')
|
|
43
|
+
AND (
|
|
44
|
+
(
|
|
45
|
+
"session_intent_json"->>'kind' = 'fresh'
|
|
46
|
+
AND "session_intent_json"->>'reuseScope' = 'none'
|
|
47
|
+
AND jsonb_typeof("session_intent_json"->'sourceRunId') = 'null'
|
|
48
|
+
AND jsonb_typeof("session_intent_json"->'sessionId') = 'null'
|
|
49
|
+
AND jsonb_typeof("session_intent_json"->'sessionParams') = 'null'
|
|
50
|
+
AND NOT ("session_intent_json" ? 'sourceBoundaryRef')
|
|
51
|
+
)
|
|
52
|
+
OR
|
|
53
|
+
(
|
|
54
|
+
"session_intent_json"->>'kind' = 'resume'
|
|
55
|
+
AND "session_intent_json"->>'reuseScope' IN ('explicit', 'task')
|
|
56
|
+
AND (
|
|
57
|
+
jsonb_typeof("session_intent_json"->'sourceRunId') = 'null'
|
|
58
|
+
OR (jsonb_typeof("session_intent_json"->'sourceRunId') = 'string' AND "session_intent_json"->>'sourceRunId' = btrim("session_intent_json"->>'sourceRunId') AND btrim("session_intent_json"->>'sourceRunId') <> '')
|
|
59
|
+
)
|
|
60
|
+
AND (
|
|
61
|
+
jsonb_typeof("session_intent_json"->'sessionId') = 'null'
|
|
62
|
+
OR (jsonb_typeof("session_intent_json"->'sessionId') = 'string' AND "session_intent_json"->>'sessionId' = btrim("session_intent_json"->>'sessionId') AND btrim("session_intent_json"->>'sessionId') <> '')
|
|
63
|
+
)
|
|
64
|
+
AND jsonb_typeof("session_intent_json"->'sessionParams') IN ('null', 'object')
|
|
65
|
+
AND NOT ("session_intent_json" ? 'sourceBoundaryRef')
|
|
66
|
+
)
|
|
67
|
+
OR
|
|
68
|
+
(
|
|
69
|
+
"session_intent_json"->>'kind' = 'fork'
|
|
70
|
+
AND "session_intent_json"->>'reuseScope' = 'explicit'
|
|
71
|
+
AND jsonb_typeof("session_intent_json"->'sourceRunId') = 'string'
|
|
72
|
+
AND "session_intent_json"->>'sourceRunId' = btrim("session_intent_json"->>'sourceRunId')
|
|
73
|
+
AND btrim("session_intent_json"->>'sourceRunId') <> ''
|
|
74
|
+
AND "session_intent_json" ? 'sourceBoundaryRef'
|
|
75
|
+
AND jsonb_typeof("session_intent_json"->'sourceBoundaryRef') = 'string'
|
|
76
|
+
AND "session_intent_json"->>'sourceBoundaryRef' = btrim("session_intent_json"->>'sourceBoundaryRef')
|
|
77
|
+
AND btrim("session_intent_json"->>'sourceBoundaryRef') <> ''
|
|
78
|
+
AND (
|
|
79
|
+
jsonb_typeof("session_intent_json"->'sessionId') = 'null'
|
|
80
|
+
OR (jsonb_typeof("session_intent_json"->'sessionId') = 'string' AND "session_intent_json"->>'sessionId' = btrim("session_intent_json"->>'sessionId') AND btrim("session_intent_json"->>'sessionId') <> '')
|
|
81
|
+
)
|
|
82
|
+
AND jsonb_typeof("session_intent_json"->'sessionParams') IN ('null', 'object')
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
--> statement-breakpoint
|
|
88
|
+
CREATE UNIQUE INDEX "heartbeat_runs_org_idempotency_key_uq" ON "heartbeat_runs" USING btree ("org_id","idempotency_key") WHERE "idempotency_key" IS NOT NULL;
|
|
89
|
+
--> statement-breakpoint
|
|
90
|
+
CREATE TABLE "runtime_bindings" (
|
|
91
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
92
|
+
"org_id" uuid NOT NULL,
|
|
93
|
+
"conversation_id" uuid NOT NULL,
|
|
94
|
+
"principal_scope_ref" text NOT NULL,
|
|
95
|
+
"agent_id" uuid NOT NULL,
|
|
96
|
+
"runtime_type" text NOT NULL,
|
|
97
|
+
"host_id" text DEFAULT 'local' NOT NULL,
|
|
98
|
+
"profile_id" text DEFAULT 'default' NOT NULL,
|
|
99
|
+
"workspace_binding_id" text,
|
|
100
|
+
"instructions_revision" text DEFAULT 'unknown' NOT NULL,
|
|
101
|
+
"capability_revision" text DEFAULT 'unknown' NOT NULL,
|
|
102
|
+
"continuity" text DEFAULT 'native' NOT NULL,
|
|
103
|
+
"parent_binding_id" uuid,
|
|
104
|
+
"source_boundary_ref" text,
|
|
105
|
+
"binding_epoch" integer DEFAULT 0 NOT NULL,
|
|
106
|
+
"current_segment_id" uuid,
|
|
107
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
108
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
109
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
110
|
+
CONSTRAINT "runtime_bindings_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action,
|
|
111
|
+
CONSTRAINT "runtime_bindings_conversation_id_chat_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."chat_conversations"("id") ON DELETE cascade ON UPDATE no action,
|
|
112
|
+
CONSTRAINT "runtime_bindings_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE restrict ON UPDATE no action,
|
|
113
|
+
CONSTRAINT "runtime_bindings_parent_binding_id_fk" FOREIGN KEY ("parent_binding_id") REFERENCES "public"."runtime_bindings"("id") ON DELETE set null ON UPDATE no action,
|
|
114
|
+
CONSTRAINT "runtime_bindings_continuity_check" CHECK ("continuity" in ('native', 'context_handoff', 'legacy')),
|
|
115
|
+
CONSTRAINT "runtime_bindings_status_check" CHECK ("status" in ('active', 'closed', 'superseded'))
|
|
116
|
+
);
|
|
117
|
+
--> statement-breakpoint
|
|
118
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_conversation_uq" ON "runtime_bindings" USING btree ("org_id","conversation_id") WHERE "status" = 'active';
|
|
119
|
+
--> statement-breakpoint
|
|
120
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_conversation_epoch_uq" ON "runtime_bindings" USING btree ("org_id","conversation_id","binding_epoch");
|
|
121
|
+
--> statement-breakpoint
|
|
122
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_id_uq" ON "runtime_bindings" USING btree ("org_id","id");
|
|
123
|
+
--> statement-breakpoint
|
|
124
|
+
CREATE INDEX "runtime_bindings_org_agent_updated_idx" ON "runtime_bindings" USING btree ("org_id","agent_id","updated_at");
|
|
125
|
+
--> statement-breakpoint
|
|
126
|
+
CREATE INDEX "runtime_bindings_org_current_segment_idx" ON "runtime_bindings" USING btree ("org_id","current_segment_id");
|
|
127
|
+
--> statement-breakpoint
|
|
128
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_binding_epoch_check"
|
|
129
|
+
CHECK ("binding_epoch" >= 0);
|
|
130
|
+
--> statement-breakpoint
|
|
131
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_parent_binding_not_self_check"
|
|
132
|
+
CHECK ("parent_binding_id" IS NULL OR "parent_binding_id" <> "id");
|
|
133
|
+
--> statement-breakpoint
|
|
134
|
+
CREATE TABLE "native_segments" (
|
|
135
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
136
|
+
"org_id" uuid NOT NULL,
|
|
137
|
+
"binding_id" uuid NOT NULL,
|
|
138
|
+
"runtime_type" text NOT NULL,
|
|
139
|
+
"segment_ordinal" integer DEFAULT 0 NOT NULL,
|
|
140
|
+
"native_session_id" text,
|
|
141
|
+
"root_session_id" text,
|
|
142
|
+
"parent_segment_id" uuid,
|
|
143
|
+
"leaf_id" text,
|
|
144
|
+
"provider_state_json" jsonb,
|
|
145
|
+
"source_boundary_ref" text,
|
|
146
|
+
"state" text DEFAULT 'pending' NOT NULL,
|
|
147
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
148
|
+
"sealed_at" timestamp with time zone,
|
|
149
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
150
|
+
CONSTRAINT "native_segments_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action,
|
|
151
|
+
CONSTRAINT "native_segments_binding_id_runtime_bindings_id_fk" FOREIGN KEY ("binding_id") REFERENCES "public"."runtime_bindings"("id") ON DELETE cascade ON UPDATE no action,
|
|
152
|
+
CONSTRAINT "native_segments_parent_segment_id_fk" FOREIGN KEY ("parent_segment_id") REFERENCES "public"."native_segments"("id") ON DELETE set null ON UPDATE no action,
|
|
153
|
+
CONSTRAINT "native_segments_state_check" CHECK ("state" in ('pending', 'open', 'sealed', 'superseded'))
|
|
154
|
+
);
|
|
155
|
+
--> statement-breakpoint
|
|
156
|
+
CREATE INDEX "native_segments_binding_created_idx" ON "native_segments" USING btree ("binding_id","created_at");
|
|
157
|
+
--> statement-breakpoint
|
|
158
|
+
CREATE UNIQUE INDEX "native_segments_binding_ordinal_uq" ON "native_segments" USING btree ("binding_id","segment_ordinal");
|
|
159
|
+
--> statement-breakpoint
|
|
160
|
+
CREATE UNIQUE INDEX "native_segments_org_id_uq" ON "native_segments" USING btree ("org_id","id");
|
|
161
|
+
--> statement-breakpoint
|
|
162
|
+
CREATE UNIQUE INDEX "native_segments_org_binding_id_uq" ON "native_segments" USING btree ("org_id","binding_id","id");
|
|
163
|
+
--> statement-breakpoint
|
|
164
|
+
CREATE INDEX "native_segments_org_native_session_idx" ON "native_segments" USING btree ("org_id","native_session_id");
|
|
165
|
+
--> statement-breakpoint
|
|
166
|
+
CREATE INDEX "native_segments_binding_leaf_idx" ON "native_segments" USING btree ("binding_id","leaf_id");
|
|
167
|
+
--> statement-breakpoint
|
|
168
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_segment_ordinal_check"
|
|
169
|
+
CHECK ("segment_ordinal" >= 0);
|
|
170
|
+
--> statement-breakpoint
|
|
171
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_parent_segment_not_self_check"
|
|
172
|
+
CHECK ("parent_segment_id" IS NULL OR "parent_segment_id" <> "id");
|
|
173
|
+
--> statement-breakpoint
|
|
174
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_sealed_lifecycle_check"
|
|
175
|
+
CHECK (
|
|
176
|
+
("state" IN ('pending', 'open') AND "sealed_at" IS NULL)
|
|
177
|
+
OR ("state" IN ('sealed', 'superseded') AND "sealed_at" IS NOT NULL)
|
|
178
|
+
);
|
|
179
|
+
--> statement-breakpoint
|
|
180
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_sealed_after_create_check"
|
|
181
|
+
CHECK ("sealed_at" IS NULL OR "sealed_at" >= "created_at");
|
|
182
|
+
--> statement-breakpoint
|
|
183
|
+
CREATE TABLE "run_runtime_spans" (
|
|
184
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
185
|
+
"org_id" uuid NOT NULL,
|
|
186
|
+
"run_id" uuid NOT NULL,
|
|
187
|
+
"binding_id" uuid NOT NULL,
|
|
188
|
+
"segment_id" uuid NOT NULL,
|
|
189
|
+
"attempt_id" uuid,
|
|
190
|
+
"attempt_ref" text NOT NULL,
|
|
191
|
+
"attempt_epoch" integer DEFAULT 1 NOT NULL,
|
|
192
|
+
"owner_token" text NOT NULL,
|
|
193
|
+
"ordinal" integer DEFAULT 0 NOT NULL,
|
|
194
|
+
"relation" text DEFAULT 'primary' NOT NULL,
|
|
195
|
+
"native_execution_ref" text,
|
|
196
|
+
"input_correlation_ref" text,
|
|
197
|
+
"selector_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
198
|
+
"source_revision" text,
|
|
199
|
+
"state" text DEFAULT 'open' NOT NULL,
|
|
200
|
+
"completeness" text DEFAULT 'unknown' NOT NULL,
|
|
201
|
+
"visibility_cutoff_ref" text,
|
|
202
|
+
"supplemental_object_ref" text,
|
|
203
|
+
"opened_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
204
|
+
"closed_at" timestamp with time zone,
|
|
205
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
206
|
+
CONSTRAINT "run_runtime_spans_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action,
|
|
207
|
+
CONSTRAINT "run_runtime_spans_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE cascade ON UPDATE no action,
|
|
208
|
+
CONSTRAINT "run_runtime_spans_binding_id_runtime_bindings_id_fk" FOREIGN KEY ("binding_id") REFERENCES "public"."runtime_bindings"("id") ON DELETE cascade ON UPDATE no action,
|
|
209
|
+
CONSTRAINT "run_runtime_spans_segment_id_native_segments_id_fk" FOREIGN KEY ("segment_id") REFERENCES "public"."native_segments"("id") ON DELETE restrict ON UPDATE no action,
|
|
210
|
+
CONSTRAINT "run_runtime_spans_attempt_id_heartbeat_run_attempts_id_fk" FOREIGN KEY ("attempt_id") REFERENCES "public"."heartbeat_run_attempts"("id") ON DELETE set null ON UPDATE no action,
|
|
211
|
+
CONSTRAINT "run_runtime_spans_state_check" CHECK ("state" in ('open', 'sealed', 'unresolved')),
|
|
212
|
+
CONSTRAINT "run_runtime_spans_completeness_check" CHECK ("completeness" in ('complete', 'partial', 'terminal_only', 'unknown'))
|
|
213
|
+
);
|
|
214
|
+
--> statement-breakpoint
|
|
215
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_attempt_epoch_check"
|
|
216
|
+
CHECK ("attempt_epoch" > 0);
|
|
217
|
+
--> statement-breakpoint
|
|
218
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_ordinal_check"
|
|
219
|
+
CHECK ("ordinal" >= 0);
|
|
220
|
+
--> statement-breakpoint
|
|
221
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_relation_check"
|
|
222
|
+
CHECK ("relation" IN ('primary', 'continuation', 'native_subagent'));
|
|
223
|
+
--> statement-breakpoint
|
|
224
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_closed_lifecycle_check"
|
|
225
|
+
CHECK (
|
|
226
|
+
("state" = 'open' AND "closed_at" IS NULL)
|
|
227
|
+
OR ("state" IN ('sealed', 'unresolved') AND "closed_at" IS NOT NULL)
|
|
228
|
+
);
|
|
229
|
+
--> statement-breakpoint
|
|
230
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_closed_after_open_check"
|
|
231
|
+
CHECK ("closed_at" IS NULL OR "closed_at" >= "opened_at");
|
|
232
|
+
--> statement-breakpoint
|
|
233
|
+
CREATE UNIQUE INDEX "run_runtime_spans_org_run_ordinal_uq" ON "run_runtime_spans" USING btree ("org_id","run_id","ordinal");
|
|
234
|
+
--> statement-breakpoint
|
|
235
|
+
CREATE INDEX "run_runtime_spans_org_run_idx" ON "run_runtime_spans" USING btree ("org_id","run_id","opened_at");
|
|
236
|
+
--> statement-breakpoint
|
|
237
|
+
CREATE INDEX "run_runtime_spans_binding_segment_idx" ON "run_runtime_spans" USING btree ("binding_id","segment_id","opened_at");
|
|
238
|
+
--> statement-breakpoint
|
|
239
|
+
CREATE INDEX "run_runtime_spans_open_idx" ON "run_runtime_spans" USING btree ("state","updated_at");
|
|
240
|
+
--> statement-breakpoint
|
|
241
|
+
CREATE UNIQUE INDEX "chat_conversations_org_id_uq" ON "chat_conversations" USING btree ("org_id","id");
|
|
242
|
+
--> statement-breakpoint
|
|
243
|
+
CREATE UNIQUE INDEX "heartbeat_runs_org_id_uq" ON "heartbeat_runs" USING btree ("org_id","id");
|
|
244
|
+
--> statement-breakpoint
|
|
245
|
+
CREATE UNIQUE INDEX "heartbeat_run_attempts_org_id_uq" ON "heartbeat_run_attempts" USING btree ("org_id","id");
|
|
246
|
+
--> statement-breakpoint
|
|
247
|
+
CREATE UNIQUE INDEX "heartbeat_run_attempts_org_run_id_uq" ON "heartbeat_run_attempts" USING btree ("org_id","run_id","id");
|
|
248
|
+
--> statement-breakpoint
|
|
249
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_org_conversation_fk"
|
|
250
|
+
FOREIGN KEY ("org_id", "conversation_id") REFERENCES "public"."chat_conversations"("org_id", "id") ON DELETE cascade ON UPDATE no action;
|
|
251
|
+
--> statement-breakpoint
|
|
252
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_org_agent_fk"
|
|
253
|
+
FOREIGN KEY ("org_id", "agent_id") REFERENCES "public"."agents"("org_id", "id") ON DELETE restrict ON UPDATE no action;
|
|
254
|
+
--> statement-breakpoint
|
|
255
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_parent_binding_org_fk"
|
|
256
|
+
FOREIGN KEY ("org_id", "parent_binding_id") REFERENCES "public"."runtime_bindings"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
257
|
+
--> statement-breakpoint
|
|
258
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_current_segment_fk"
|
|
259
|
+
FOREIGN KEY ("current_segment_id") REFERENCES "public"."native_segments"("id") ON DELETE set null ON UPDATE no action;
|
|
260
|
+
--> statement-breakpoint
|
|
261
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_current_segment_binding_fk"
|
|
262
|
+
FOREIGN KEY ("org_id", "id", "current_segment_id") REFERENCES "public"."native_segments"("org_id", "binding_id", "id") ON DELETE no action ON UPDATE no action;
|
|
263
|
+
--> statement-breakpoint
|
|
264
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_org_binding_fk"
|
|
265
|
+
FOREIGN KEY ("org_id", "binding_id") REFERENCES "public"."runtime_bindings"("org_id", "id") ON DELETE cascade ON UPDATE no action;
|
|
266
|
+
--> statement-breakpoint
|
|
267
|
+
ALTER TABLE "native_segments" ADD CONSTRAINT "native_segments_parent_segment_binding_fk"
|
|
268
|
+
FOREIGN KEY ("org_id", "binding_id", "parent_segment_id") REFERENCES "public"."native_segments"("org_id", "binding_id", "id") ON DELETE no action ON UPDATE no action;
|
|
269
|
+
--> statement-breakpoint
|
|
270
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_org_run_fk"
|
|
271
|
+
FOREIGN KEY ("org_id", "run_id") REFERENCES "public"."heartbeat_runs"("org_id", "id") ON DELETE cascade ON UPDATE no action;
|
|
272
|
+
--> statement-breakpoint
|
|
273
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_org_binding_fk"
|
|
274
|
+
FOREIGN KEY ("org_id", "binding_id") REFERENCES "public"."runtime_bindings"("org_id", "id") ON DELETE cascade ON UPDATE no action;
|
|
275
|
+
--> statement-breakpoint
|
|
276
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_org_segment_fk"
|
|
277
|
+
FOREIGN KEY ("org_id", "segment_id") REFERENCES "public"."native_segments"("org_id", "id") ON DELETE restrict ON UPDATE no action;
|
|
278
|
+
--> statement-breakpoint
|
|
279
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_org_attempt_fk"
|
|
280
|
+
FOREIGN KEY ("org_id", "attempt_id") REFERENCES "public"."heartbeat_run_attempts"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
281
|
+
--> statement-breakpoint
|
|
282
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_binding_segment_fk"
|
|
283
|
+
FOREIGN KEY ("org_id", "binding_id", "segment_id") REFERENCES "public"."native_segments"("org_id", "binding_id", "id") ON DELETE no action ON UPDATE no action;
|
|
284
|
+
--> statement-breakpoint
|
|
285
|
+
ALTER TABLE "run_runtime_spans" ADD CONSTRAINT "run_runtime_spans_run_attempt_fk"
|
|
286
|
+
FOREIGN KEY ("org_id", "run_id", "attempt_id") REFERENCES "public"."heartbeat_run_attempts"("org_id", "run_id", "id") ON DELETE no action ON UPDATE no action;
|
|
287
|
+
--> statement-breakpoint
|
|
288
|
+
CREATE TABLE "runtime_retention_claims" (
|
|
289
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
290
|
+
"org_id" uuid NOT NULL,
|
|
291
|
+
"binding_id" uuid,
|
|
292
|
+
"segment_id" uuid,
|
|
293
|
+
"resource_ref" text NOT NULL,
|
|
294
|
+
"purpose" text NOT NULL,
|
|
295
|
+
"principal_scope_ref" text NOT NULL,
|
|
296
|
+
"read_only" boolean DEFAULT true NOT NULL,
|
|
297
|
+
"lifecycle_version" integer DEFAULT 1 NOT NULL,
|
|
298
|
+
"cleanup_epoch" integer DEFAULT 0 NOT NULL,
|
|
299
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
300
|
+
"expires_at" timestamp with time zone,
|
|
301
|
+
"released_at" timestamp with time zone,
|
|
302
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
303
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
304
|
+
CONSTRAINT "runtime_retention_claims_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action,
|
|
305
|
+
CONSTRAINT "runtime_retention_claims_binding_id_runtime_bindings_id_fk" FOREIGN KEY ("binding_id") REFERENCES "public"."runtime_bindings"("id") ON DELETE no action ON UPDATE no action,
|
|
306
|
+
CONSTRAINT "runtime_retention_claims_segment_id_native_segments_id_fk" FOREIGN KEY ("segment_id") REFERENCES "public"."native_segments"("id") ON DELETE no action ON UPDATE no action,
|
|
307
|
+
CONSTRAINT "runtime_retention_claims_status_check" CHECK ("status" in ('active', 'released', 'expired'))
|
|
308
|
+
);
|
|
309
|
+
--> statement-breakpoint
|
|
310
|
+
CREATE UNIQUE INDEX "runtime_retention_claims_org_resource_purpose_uq" ON "runtime_retention_claims" USING btree ("org_id","resource_ref","purpose") WHERE "status" = 'active';
|
|
311
|
+
--> statement-breakpoint
|
|
312
|
+
CREATE INDEX "runtime_retention_claims_org_resource_idx" ON "runtime_retention_claims" USING btree ("org_id","resource_ref");
|
|
313
|
+
--> statement-breakpoint
|
|
314
|
+
CREATE INDEX "runtime_retention_claims_expiry_idx" ON "runtime_retention_claims" USING btree ("status","expires_at","cleanup_epoch");
|
|
315
|
+
--> statement-breakpoint
|
|
316
|
+
ALTER TABLE "runtime_retention_claims" ADD CONSTRAINT "runtime_retention_claims_lifecycle_version_check"
|
|
317
|
+
CHECK ("lifecycle_version" > 0 AND "cleanup_epoch" >= 0);
|
|
318
|
+
--> statement-breakpoint
|
|
319
|
+
ALTER TABLE "runtime_retention_claims" ADD CONSTRAINT "runtime_retention_claims_lifecycle_check"
|
|
320
|
+
CHECK (
|
|
321
|
+
("status" = 'active' AND "released_at" IS NULL)
|
|
322
|
+
OR ("status" = 'released' AND "released_at" IS NOT NULL)
|
|
323
|
+
OR ("status" = 'expired' AND "expires_at" IS NOT NULL AND "released_at" IS NULL)
|
|
324
|
+
);
|
|
325
|
+
--> statement-breakpoint
|
|
326
|
+
ALTER TABLE "runtime_retention_claims" ADD CONSTRAINT "runtime_retention_claims_timestamp_order_check"
|
|
327
|
+
CHECK (
|
|
328
|
+
("expires_at" IS NULL OR "expires_at" >= "created_at")
|
|
329
|
+
AND ("released_at" IS NULL OR "released_at" >= "created_at")
|
|
330
|
+
);
|
|
331
|
+
--> statement-breakpoint
|
|
332
|
+
ALTER TABLE "runtime_retention_claims" ADD CONSTRAINT "runtime_retention_claims_org_binding_fk"
|
|
333
|
+
FOREIGN KEY ("org_id", "binding_id") REFERENCES "public"."runtime_bindings"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
334
|
+
--> statement-breakpoint
|
|
335
|
+
ALTER TABLE "runtime_retention_claims" ADD CONSTRAINT "runtime_retention_claims_org_segment_fk"
|
|
336
|
+
FOREIGN KEY ("org_id", "segment_id") REFERENCES "public"."native_segments"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
337
|
+
--> statement-breakpoint
|
|
338
|
+
CREATE TABLE "runtime_source_aliases" (
|
|
339
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
340
|
+
"org_id" uuid NOT NULL,
|
|
341
|
+
"conversation_id" uuid,
|
|
342
|
+
"run_id" uuid,
|
|
343
|
+
"binding_id" uuid,
|
|
344
|
+
"segment_id" uuid,
|
|
345
|
+
"source_kind" text NOT NULL,
|
|
346
|
+
"source_ref" text NOT NULL,
|
|
347
|
+
"source_range_json" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
348
|
+
"content_sha256" text,
|
|
349
|
+
"principal_scope_ref" text NOT NULL,
|
|
350
|
+
"read_only" boolean DEFAULT true NOT NULL,
|
|
351
|
+
"lifecycle_version" integer DEFAULT 1 NOT NULL,
|
|
352
|
+
"cleanup_epoch" integer DEFAULT 0 NOT NULL,
|
|
353
|
+
"expires_at" timestamp with time zone,
|
|
354
|
+
"released_at" timestamp with time zone,
|
|
355
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
356
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
357
|
+
CONSTRAINT "runtime_source_aliases_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action,
|
|
358
|
+
CONSTRAINT "runtime_source_aliases_conversation_id_chat_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."chat_conversations"("id") ON DELETE no action ON UPDATE no action,
|
|
359
|
+
CONSTRAINT "runtime_source_aliases_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE no action ON UPDATE no action,
|
|
360
|
+
CONSTRAINT "runtime_source_aliases_binding_id_runtime_bindings_id_fk" FOREIGN KEY ("binding_id") REFERENCES "public"."runtime_bindings"("id") ON DELETE no action ON UPDATE no action,
|
|
361
|
+
CONSTRAINT "runtime_source_aliases_segment_id_native_segments_id_fk" FOREIGN KEY ("segment_id") REFERENCES "public"."native_segments"("id") ON DELETE no action ON UPDATE no action
|
|
362
|
+
);
|
|
363
|
+
--> statement-breakpoint
|
|
364
|
+
CREATE INDEX "runtime_source_aliases_org_source_idx" ON "runtime_source_aliases" USING btree ("org_id","source_kind","source_ref");
|
|
365
|
+
--> statement-breakpoint
|
|
366
|
+
CREATE INDEX "runtime_source_aliases_org_conversation_idx" ON "runtime_source_aliases" USING btree ("org_id","conversation_id");
|
|
367
|
+
--> statement-breakpoint
|
|
368
|
+
CREATE INDEX "runtime_source_aliases_org_run_idx" ON "runtime_source_aliases" USING btree ("org_id","run_id");
|
|
369
|
+
--> statement-breakpoint
|
|
370
|
+
CREATE INDEX "runtime_source_aliases_cleanup_idx" ON "runtime_source_aliases" USING btree ("org_id","cleanup_epoch","released_at");
|
|
371
|
+
--> statement-breakpoint
|
|
372
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_lifecycle_version_check"
|
|
373
|
+
CHECK ("lifecycle_version" > 0 AND "cleanup_epoch" >= 0);
|
|
374
|
+
--> statement-breakpoint
|
|
375
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_timestamp_order_check"
|
|
376
|
+
CHECK (
|
|
377
|
+
("expires_at" IS NULL OR "expires_at" >= "created_at")
|
|
378
|
+
AND ("released_at" IS NULL OR "released_at" >= "created_at")
|
|
379
|
+
);
|
|
380
|
+
--> statement-breakpoint
|
|
381
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_read_only_check"
|
|
382
|
+
CHECK ("read_only" = true);
|
|
383
|
+
--> statement-breakpoint
|
|
384
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_org_conversation_fk"
|
|
385
|
+
FOREIGN KEY ("org_id", "conversation_id") REFERENCES "public"."chat_conversations"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
386
|
+
--> statement-breakpoint
|
|
387
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_org_run_fk"
|
|
388
|
+
FOREIGN KEY ("org_id", "run_id") REFERENCES "public"."heartbeat_runs"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
389
|
+
--> statement-breakpoint
|
|
390
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_org_binding_fk"
|
|
391
|
+
FOREIGN KEY ("org_id", "binding_id") REFERENCES "public"."runtime_bindings"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
392
|
+
--> statement-breakpoint
|
|
393
|
+
ALTER TABLE "runtime_source_aliases" ADD CONSTRAINT "runtime_source_aliases_org_segment_fk"
|
|
394
|
+
FOREIGN KEY ("org_id", "segment_id") REFERENCES "public"."native_segments"("org_id", "id") ON DELETE no action ON UPDATE no action;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ALTER TABLE "heartbeat_run_attempts" ADD COLUMN "owner_token" text;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "heartbeat_run_attempts" ADD COLUMN "attempt_epoch" integer;
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "heartbeat_run_attempts" ADD CONSTRAINT "heartbeat_run_attempts_owner_fence_shape_check"
|
|
6
|
+
CHECK (
|
|
7
|
+
("owner_token" IS NULL AND "attempt_epoch" IS NULL)
|
|
8
|
+
OR
|
|
9
|
+
("owner_token" IS NOT NULL AND btrim("owner_token") <> '' AND "attempt_epoch" IS NOT NULL AND "attempt_epoch" > 0)
|
|
10
|
+
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
ALTER TABLE "runtime_bindings" ALTER COLUMN "conversation_id" DROP NOT NULL;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "runtime_bindings" ADD COLUMN "target_type" text;
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "runtime_bindings" ADD COLUMN "target_id" text;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
UPDATE "runtime_bindings"
|
|
8
|
+
SET "target_type" = 'chat_conversation', "target_id" = "conversation_id"::text
|
|
9
|
+
WHERE "conversation_id" IS NOT NULL AND "target_type" IS NULL;
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_target_type_check"
|
|
12
|
+
CHECK ("target_type" IS NULL OR "target_type" IN ('issue', 'chat_conversation', 'chat_message', 'automation_run', 'wakeup_request', 'manual', 'review'));
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
ALTER TABLE "runtime_bindings" ADD CONSTRAINT "runtime_bindings_target_shape_check"
|
|
15
|
+
CHECK (
|
|
16
|
+
("target_type" IS NULL AND "target_id" IS NULL AND "conversation_id" IS NOT NULL)
|
|
17
|
+
OR
|
|
18
|
+
("target_type" IS NOT NULL AND "target_type" = 'chat_conversation'
|
|
19
|
+
AND "target_id" IS NOT NULL AND btrim("target_id") <> ''
|
|
20
|
+
AND "conversation_id" IS NOT NULL AND "target_id" = "conversation_id"::text)
|
|
21
|
+
OR
|
|
22
|
+
("target_type" IS NOT NULL AND "target_type" IN ('issue', 'chat_message', 'automation_run', 'wakeup_request', 'manual', 'review')
|
|
23
|
+
AND "target_id" IS NOT NULL AND btrim("target_id") <> ''
|
|
24
|
+
AND "conversation_id" IS NULL)
|
|
25
|
+
);
|
|
26
|
+
--> statement-breakpoint
|
|
27
|
+
DROP INDEX "runtime_bindings_org_conversation_uq";
|
|
28
|
+
--> statement-breakpoint
|
|
29
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_conversation_uq" ON "runtime_bindings" USING btree ("org_id", "conversation_id")
|
|
30
|
+
WHERE "status" = 'active' AND "conversation_id" IS NOT NULL;
|
|
31
|
+
--> statement-breakpoint
|
|
32
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_target_uq" ON "runtime_bindings" USING btree ("org_id", "target_type", "target_id")
|
|
33
|
+
WHERE "status" = 'active' AND "target_type" IS NOT NULL AND "target_id" IS NOT NULL;
|
|
34
|
+
--> statement-breakpoint
|
|
35
|
+
CREATE UNIQUE INDEX "runtime_bindings_org_target_epoch_uq" ON "runtime_bindings" USING btree ("org_id", "target_type", "target_id", "binding_epoch")
|
|
36
|
+
WHERE "target_type" IS NOT NULL AND "target_id" IS NOT NULL;
|
|
37
|
+
--> statement-breakpoint
|
|
38
|
+
CREATE INDEX "runtime_bindings_org_target_idx" ON "runtime_bindings" USING btree ("org_id", "target_type", "target_id", "status");
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
ALTER TABLE "heartbeat_runs" DROP CONSTRAINT "heartbeat_runs_scene_check";
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "heartbeat_runs" ADD CONSTRAINT "heartbeat_runs_scene_check"
|
|
4
|
+
CHECK ("scene" IS NULL OR "scene" IN ('chat', 'side_chat', 'issue', 'review', 'automation', 'heartbeat', 'delegation'));
|
|
@@ -1149,6 +1149,34 @@
|
|
|
1149
1149
|
"when": 1789562246660,
|
|
1150
1150
|
"tag": "0163_organization_mutations",
|
|
1151
1151
|
"breakpoints": true
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
"idx": 164,
|
|
1155
|
+
"version": "7",
|
|
1156
|
+
"when": 1790020000000,
|
|
1157
|
+
"tag": "0164_native_chat_runtime_binding",
|
|
1158
|
+
"breakpoints": true
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
"idx": 165,
|
|
1162
|
+
"version": "7",
|
|
1163
|
+
"when": 1790026475000,
|
|
1164
|
+
"tag": "0165_heartbeat_attempt_owner_fencing",
|
|
1165
|
+
"breakpoints": true
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
"idx": 166,
|
|
1169
|
+
"version": "7",
|
|
1170
|
+
"when": 1790030000000,
|
|
1171
|
+
"tag": "0166_runtime_binding_targets",
|
|
1172
|
+
"breakpoints": true
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
"idx": 167,
|
|
1176
|
+
"version": "7",
|
|
1177
|
+
"when": 1790073483029,
|
|
1178
|
+
"tag": "0167_delegation_run_scene",
|
|
1179
|
+
"breakpoints": true
|
|
1152
1180
|
}
|
|
1153
1181
|
]
|
|
1154
1182
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-chat-runtime-binding-schema.test.d.ts","sourceRoot":"","sources":["../src/native-chat-runtime-binding-schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getTableConfig } from "drizzle-orm/pg-core";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { heartbeatRunAttempts } from "./schema/heartbeat_run_attempts.js";
|
|
6
|
+
import { heartbeatRuns } from "./schema/heartbeat_runs.js";
|
|
7
|
+
import * as schema from "./schema/index.js";
|
|
8
|
+
import { nativeSegments, runRuntimeSpans, runtimeBindings, } from "./schema/runtime_bindings.js";
|
|
9
|
+
function columnsOf(table) {
|
|
10
|
+
return getTableConfig(table).columns.map((column) => column.name);
|
|
11
|
+
}
|
|
12
|
+
function foreignKeyOf(table, name) {
|
|
13
|
+
const foreignKey = getTableConfig(table).foreignKeys.find((candidate) => candidate.getName() === name);
|
|
14
|
+
expect(foreignKey, `${name} must be declared`).toBeDefined();
|
|
15
|
+
if (!foreignKey)
|
|
16
|
+
throw new Error(`Missing foreign key ${name}`);
|
|
17
|
+
const reference = foreignKey.reference();
|
|
18
|
+
return {
|
|
19
|
+
name: foreignKey.getName(),
|
|
20
|
+
columns: reference.columns.map((column) => column.name),
|
|
21
|
+
foreignTable: getTableConfig(reference.foreignTable).name,
|
|
22
|
+
foreignColumns: reference.foreignColumns.map((column) => column.name),
|
|
23
|
+
onDelete: foreignKey.onDelete,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const migrationSql = readFileSync(fileURLToPath(new URL("./migrations/0164_native_chat_runtime_binding.sql", import.meta.url)), "utf8");
|
|
27
|
+
describe("native chat runtime binding schema", () => {
|
|
28
|
+
it("exports lineage tables and durable common-run admission columns", () => {
|
|
29
|
+
expect(schema.runtimeBindings).toBe(runtimeBindings);
|
|
30
|
+
expect(schema.nativeSegments).toBe(nativeSegments);
|
|
31
|
+
expect(schema.runRuntimeSpans).toBe(runRuntimeSpans);
|
|
32
|
+
expect(columnsOf(heartbeatRuns)).toEqual(expect.arrayContaining([
|
|
33
|
+
"scene",
|
|
34
|
+
"target_type",
|
|
35
|
+
"target_id",
|
|
36
|
+
"idempotency_key",
|
|
37
|
+
"session_intent_json",
|
|
38
|
+
]));
|
|
39
|
+
const runConfig = getTableConfig(heartbeatRuns);
|
|
40
|
+
expect(runConfig.indexes.map((index) => index.config.name)).toContain("heartbeat_runs_org_idempotency_key_uq");
|
|
41
|
+
expect(runConfig.checks.map((check) => check.name)).toEqual(expect.arrayContaining([
|
|
42
|
+
"heartbeat_runs_common_run_identity_check",
|
|
43
|
+
"heartbeat_runs_scene_check",
|
|
44
|
+
"heartbeat_runs_target_check",
|
|
45
|
+
"heartbeat_runs_idempotency_key_check",
|
|
46
|
+
"heartbeat_runs_session_intent_shape_check",
|
|
47
|
+
]));
|
|
48
|
+
expect(getTableConfig(heartbeatRunAttempts).indexes.map((index) => index.config.name)).toContain("heartbeat_run_attempts_org_run_id_uq");
|
|
49
|
+
});
|
|
50
|
+
it("uses exact organization and lineage keys for parent/current and span relationships", () => {
|
|
51
|
+
expect(foreignKeyOf(runtimeBindings, "runtime_bindings_parent_binding_org_fk")).toMatchObject({
|
|
52
|
+
columns: ["org_id", "parent_binding_id"],
|
|
53
|
+
foreignTable: "runtime_bindings",
|
|
54
|
+
foreignColumns: ["org_id", "id"],
|
|
55
|
+
onDelete: "no action",
|
|
56
|
+
});
|
|
57
|
+
expect(foreignKeyOf(runtimeBindings, "runtime_bindings_current_segment_binding_fk")).toMatchObject({
|
|
58
|
+
columns: ["org_id", "id", "current_segment_id"],
|
|
59
|
+
foreignTable: "native_segments",
|
|
60
|
+
foreignColumns: ["org_id", "binding_id", "id"],
|
|
61
|
+
onDelete: "no action",
|
|
62
|
+
});
|
|
63
|
+
expect(foreignKeyOf(nativeSegments, "native_segments_parent_segment_binding_fk")).toMatchObject({
|
|
64
|
+
columns: ["org_id", "binding_id", "parent_segment_id"],
|
|
65
|
+
foreignTable: "native_segments",
|
|
66
|
+
foreignColumns: ["org_id", "binding_id", "id"],
|
|
67
|
+
onDelete: "no action",
|
|
68
|
+
});
|
|
69
|
+
expect(foreignKeyOf(runRuntimeSpans, "run_runtime_spans_binding_segment_fk")).toMatchObject({
|
|
70
|
+
columns: ["org_id", "binding_id", "segment_id"],
|
|
71
|
+
foreignTable: "native_segments",
|
|
72
|
+
foreignColumns: ["org_id", "binding_id", "id"],
|
|
73
|
+
onDelete: "no action",
|
|
74
|
+
});
|
|
75
|
+
expect(foreignKeyOf(runRuntimeSpans, "run_runtime_spans_run_attempt_fk")).toMatchObject({
|
|
76
|
+
columns: ["org_id", "run_id", "attempt_id"],
|
|
77
|
+
foreignTable: "heartbeat_run_attempts",
|
|
78
|
+
foreignColumns: ["org_id", "run_id", "id"],
|
|
79
|
+
onDelete: "no action",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it("keeps the manual 0164 migration aligned without relying on snapshots", () => {
|
|
83
|
+
expect(migrationSql).toContain('ALTER TABLE "heartbeat_runs" ADD COLUMN "scene" text;');
|
|
84
|
+
expect(migrationSql).toContain('CREATE UNIQUE INDEX "heartbeat_runs_org_idempotency_key_uq" ON "heartbeat_runs" USING btree ("org_id","idempotency_key") WHERE "idempotency_key" IS NOT NULL;');
|
|
85
|
+
expect(migrationSql).toContain('CREATE UNIQUE INDEX "runtime_bindings_org_conversation_uq" ON "runtime_bindings" USING btree ("org_id","conversation_id") WHERE "status" = \'active\';');
|
|
86
|
+
expect(migrationSql).toContain('CREATE UNIQUE INDEX "runtime_bindings_org_conversation_epoch_uq" ON "runtime_bindings" USING btree ("org_id","conversation_id","binding_epoch");');
|
|
87
|
+
expect(migrationSql).toContain('CREATE UNIQUE INDEX "heartbeat_run_attempts_org_run_id_uq" ON "heartbeat_run_attempts" USING btree ("org_id","run_id","id");');
|
|
88
|
+
for (const constraint of [
|
|
89
|
+
"runtime_bindings_parent_binding_org_fk",
|
|
90
|
+
"runtime_bindings_current_segment_binding_fk",
|
|
91
|
+
"native_segments_parent_segment_binding_fk",
|
|
92
|
+
"run_runtime_spans_binding_segment_fk",
|
|
93
|
+
"run_runtime_spans_run_attempt_fk",
|
|
94
|
+
"heartbeat_runs_common_run_identity_check",
|
|
95
|
+
"heartbeat_runs_session_intent_shape_check",
|
|
96
|
+
"native_segments_sealed_lifecycle_check",
|
|
97
|
+
"run_runtime_spans_closed_lifecycle_check",
|
|
98
|
+
"runtime_retention_claims_lifecycle_check",
|
|
99
|
+
"runtime_source_aliases_read_only_check",
|
|
100
|
+
]) {
|
|
101
|
+
expect(migrationSql).toContain(`"${constraint}"`);
|
|
102
|
+
}
|
|
103
|
+
expect(migrationSql).toContain('FOREIGN KEY ("org_id", "run_id", "attempt_id") REFERENCES "public"."heartbeat_run_attempts"("org_id", "run_id", "id") ON DELETE no action');
|
|
104
|
+
expect(migrationSql).toContain('FOREIGN KEY ("org_id", "binding_id", "segment_id") REFERENCES "public"."native_segments"("org_id", "binding_id", "id") ON DELETE no action');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=native-chat-runtime-binding-schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-chat-runtime-binding-schema.test.js","sourceRoot":"","sources":["../src/native-chat-runtime-binding-schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,GAChB,MAAM,8BAA8B,CAAC;AAUtC,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,IAAY;IAChD,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS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