@sentry/junior 0.292.0 → 0.294.0
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/{adapter-Cigb1MTr.js → adapter-DxLhJEnO.js} +1 -1
- package/dist/{admin-BO9V7vnn.js → admin-vt8aSiCD.js} +2 -2
- package/dist/{agent-runner-BuH7EHrX.js → agent-runner-DJu7w6mI.js} +318 -162
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +5 -5
- package/dist/api.d.ts +1 -1
- package/dist/api.js +65 -40
- package/dist/{app-C47PT68y.d.ts → app--a5RLOrr.d.ts} +4 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +454 -435
- package/dist/{assistant-reply-ZjLRGHm2.js → assistant-reply-iTtEdDyc.js} +1 -1
- package/dist/{automation-CrsYnvdV.js → automation-BM-OBsKW.js} +72 -23
- package/dist/{background-compaction-queue-CqZBPe9g.js → background-compaction-queue-D2j-0XkH.js} +4 -4
- package/dist/{briefs-DZrhXJss.js → briefs-JOAoCb6d.js} +3 -3
- package/dist/{catalog-runtime-Cj9I0dco.js → catalog-runtime-CLMA9AXd.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +7 -74
- package/dist/{config-BerMjSVL.js → config-mIZeGEWv.js} +17 -7
- package/dist/{connections-BWmTOVPB.js → connections-XhdVg7OR.js} +6 -6
- package/dist/{conversation-CtjR1Zcx.js → conversation-CDWejM4R.js} +1 -0
- package/dist/{conversation-pending-messages-Cd7ShwBs.js → conversation-pending-messages-Dh2tfbaw.js} +5 -2
- package/dist/{conversation-privacy-BMfbOUCo.js → conversation-privacy-C6h-X2cZ.js} +1 -1
- package/dist/{credential-sync-DZDij2CU.js → credential-sync-zigBlXS3.js} +13 -13
- package/dist/{db-BlfjuqzW.js → db--xuNV7g6.js} +99 -6
- package/dist/{db-7glZCI18.d.ts → db-DV5AbcGM.d.ts} +8 -6
- package/dist/{executor-ikZvFaMD.js → executor-BItuRqAR.js} +87 -21
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-CTCH5jOy.js → logging-Cb6MGvdt.js} +1 -1
- package/dist/{message-C1ID1tKi.js → message-BTGgSmaH.js} +9 -9
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-CStBgDU7.js → oauth-callback-server-Dvh1aOIi.js} +2 -2
- package/dist/{projection-DY93nCfX.js → projection-DLQgfO5N.js} +61 -52
- package/dist/{prompt-exicBZeb.js → prompt-qp_LdxLX.js} +5 -6
- package/dist/{registry-X_xdFY9L.js → registry-MtwokaqW.js} +1 -1
- package/dist/{resolve-B9dYN-nS.js → resolve-BnJA0UNE.js} +3 -3
- package/dist/{result-CC8bV8Fl.js → result-ChL-1KyW.js} +8 -8
- package/dist/{runner-D44qp4rc.js → runner-BONN7Dp2.js} +8 -8
- package/dist/{sandbox-egress-signals-BrH6DWkt.js → sandbox-egress-signals-nmlmI5Ab.js} +1 -1
- package/dist/{schema-CC2RxDAV.d.ts → schema-DgvcyJ1y.d.ts} +283 -45
- package/dist/{schema-CVV5r-qP.js → schema-yr0ccDni.js} +29 -4
- package/dist/{service-account-DoNZuJb-.js → service-account-Bd0lBaGr.js} +3 -3
- package/dist/{service-account-89JZHWCE.js → service-account-kio5nXSD.js} +3 -3
- package/dist/{session-stop-DNucbmPf.js → session-stop-CeCXL3j9.js} +20 -41
- package/dist/{skills-BeUfmYXL.js → skills-e3DDNlKO.js} +10 -9
- package/dist/{spawn-CIAcfcvZ.js → spawn--cRxITWQ.js} +5 -5
- package/dist/{stop-Ckd3735h.js → stop-Iai5N2PU.js} +34 -29
- package/dist/{store-CS0xoqXW.js → store-C8LsaJwS.js} +3 -3
- package/dist/{task-runner-DjjHCX_m.js → task-runner-Dw7exu0-.js} +65 -90
- package/dist/{turn-failure-response-D0bwI462.js → turn-failure-response-BqTTx3XG.js} +8 -8
- package/dist/{validation-Cvx_AupF.js → validation-BrGahtnv.js} +1 -1
- package/dist/{version-BrDx4Fzc.js → version-Bdqhx8Qh.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-4CxdwLLQ.js → viewer-CjRFHR5U.js} +3 -3
- package/dist/{warmup-B62hd4lD.js → warmup-DuxCtzKC.js} +104 -26
- package/dist/{work-Cu315oJl.js → work-BWBG1EGV.js} +11 -11
- package/dist/{worker-4ClZu6ry.js → worker-DAnBIVMs.js} +6 -6
- package/migrations/0062_plugin_report_index.sql +1 -20
- package/migrations/0078_plugin_conversation_index.sql +1 -20
- package/migrations/0079_conversation_event_author_index.sql +1 -20
- package/migrations/0080_conversation_event_latest_message_indexes.sql +2 -27
- package/migrations/0090_guardian_review_time_index.sql +1 -20
- package/migrations/0091_conversation_participant_unsubscribed_index.sql +1 -20
- package/migrations/0096_automation_task_kind.sql +75 -0
- package/migrations/0097_conversation_kind_automation.sql +6 -0
- package/migrations/meta/0096_snapshot.json +4490 -0
- package/migrations/meta/0097_snapshot.json +4490 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +5 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { At as isInvalidConversationRecordError, Dt as hasConversationStop, St as countPendingConversationMessages, kt as isFinalAttempt } from "./projection-
|
|
3
|
-
import {
|
|
4
|
-
import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-
|
|
5
|
-
import { Ht as selectAttemptMessages, Vt as isAttemptInterrupt } from "./agent-runner-
|
|
6
|
-
import { k as getTurnRequestDeadline, y as ConversationQueueMessageRejectedError } from "./background-compaction-queue-
|
|
7
|
-
import { C as startConversationWork, b as releaseConversationWork, c as clearConsumedConversationWake, d as completeConversationWork, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, t as ackMessages, u as completeConversationStop, v as recordAttemptFailure, x as requestAnotherSlice, y as recordConversationRetry } from "./store-
|
|
2
|
+
import { At as isInvalidConversationRecordError, Dt as hasConversationStop, St as countPendingConversationMessages, kt as isFinalAttempt } from "./projection-DLQgfO5N.js";
|
|
3
|
+
import { K as isProviderRetryError, i as getChatConfig } from "./config-mIZeGEWv.js";
|
|
4
|
+
import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-Cb6MGvdt.js";
|
|
5
|
+
import { Ht as selectAttemptMessages, Vt as isAttemptInterrupt } from "./agent-runner-DJu7w6mI.js";
|
|
6
|
+
import { k as getTurnRequestDeadline, y as ConversationQueueMessageRejectedError } from "./background-compaction-queue-D2j-0XkH.js";
|
|
7
|
+
import { C as startConversationWork, b as releaseConversationWork, c as clearConsumedConversationWake, d as completeConversationWork, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, t as ackMessages, u as completeConversationStop, v as recordAttemptFailure, x as requestAnotherSlice, y as recordConversationRetry } from "./store-C8LsaJwS.js";
|
|
8
8
|
// src/chat/task-execution/worker.ts
|
|
9
9
|
var worker_exports = /* @__PURE__ */ __exportAll({
|
|
10
10
|
CONVERSATION_WORK_DEFER_DELAY_MS: () => CONVERSATION_WORK_DEFER_DELAY_MS,
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
-- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_events_plugin_report_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_events_plugin_report_idx" ON "junior_conversation_events" USING btree (("payload"->>'namespace'),("payload"->>'name'),"created_at") WHERE "junior_conversation_events"."type" = 'structured_event';
|
|
9
|
-
END IF;
|
|
10
|
-
|
|
11
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
12
|
-
IF NOT EXISTS (
|
|
13
|
-
SELECT 1 FROM pg_index
|
|
14
|
-
WHERE indexrelid = 'junior_conversation_events_plugin_report_idx'::regclass
|
|
15
|
-
AND indrelid = 'junior_conversation_events'::regclass
|
|
16
|
-
AND indisvalid AND indisready
|
|
17
|
-
) THEN
|
|
18
|
-
RAISE EXCEPTION 'The plugin report index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
19
|
-
END IF;
|
|
20
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_plugin_report_idx" ON "junior_conversation_events" USING btree (("payload"->>'namespace'),("payload"->>'name'),"created_at") WHERE "junior_conversation_events"."type" = 'structured_event';
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
-- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_events_plugin_conversation_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_events_plugin_conversation_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'namespace'),("payload"->>'name'),"seq") WHERE "junior_conversation_events"."type" = 'structured_event';
|
|
9
|
-
END IF;
|
|
10
|
-
|
|
11
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
12
|
-
IF NOT EXISTS (
|
|
13
|
-
SELECT 1 FROM pg_index
|
|
14
|
-
WHERE indexrelid = 'junior_conversation_events_plugin_conversation_idx'::regclass
|
|
15
|
-
AND indrelid = 'junior_conversation_events'::regclass
|
|
16
|
-
AND indisvalid AND indisready
|
|
17
|
-
) THEN
|
|
18
|
-
RAISE EXCEPTION 'The plugin conversation index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
19
|
-
END IF;
|
|
20
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_plugin_conversation_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'namespace'),("payload"->>'name'),"seq") WHERE "junior_conversation_events"."type" = 'structured_event';
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
-- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_events_author_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_events_author_idx" ON "junior_conversation_events" USING btree ("conversation_id","actor_identity_id","seq") WHERE "junior_conversation_events"."actor_identity_id" is not null;
|
|
9
|
-
END IF;
|
|
10
|
-
|
|
11
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
12
|
-
IF NOT EXISTS (
|
|
13
|
-
SELECT 1 FROM pg_index
|
|
14
|
-
WHERE indexrelid = 'junior_conversation_events_author_idx'::regclass
|
|
15
|
-
AND indrelid = 'junior_conversation_events'::regclass
|
|
16
|
-
AND indisvalid AND indisready
|
|
17
|
-
) THEN
|
|
18
|
-
RAISE EXCEPTION 'The conversation event author index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
19
|
-
END IF;
|
|
20
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_author_idx" ON "junior_conversation_events" USING btree ("conversation_id","actor_identity_id","seq") WHERE "junior_conversation_events"."actor_identity_id" is not null;
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_events_message_role_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_events_message_role_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'role'),"created_at","seq") WHERE "junior_conversation_events"."type" = 'message';
|
|
9
|
-
END IF;
|
|
10
|
-
IF to_regclass('junior_conversation_events_user_message_time_idx') IS NULL THEN
|
|
11
|
-
-- junior:concurrent-index
|
|
12
|
-
CREATE INDEX "junior_conversation_events_user_message_time_idx" ON "junior_conversation_events" USING btree ("conversation_id","created_at","seq") WHERE "junior_conversation_events"."type" = 'user_message' and ("junior_conversation_events"."payload"->'provenance'->>'authority') = 'instruction' and ("junior_conversation_events"."payload"->'provenance'->'actor'->>'platform') in ('slack', 'local', 'web');
|
|
13
|
-
END IF;
|
|
14
|
-
|
|
15
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
16
|
-
IF (
|
|
17
|
-
SELECT count(*) FROM pg_index
|
|
18
|
-
WHERE indexrelid IN (
|
|
19
|
-
'junior_conversation_events_message_role_idx'::regclass,
|
|
20
|
-
'junior_conversation_events_user_message_time_idx'::regclass
|
|
21
|
-
)
|
|
22
|
-
AND indrelid = 'junior_conversation_events'::regclass
|
|
23
|
-
AND indisvalid AND indisready
|
|
24
|
-
) <> 2 THEN
|
|
25
|
-
RAISE EXCEPTION 'The conversation event latest message indexes are not valid and ready. Repair the concurrent builds before running junior upgrade.';
|
|
26
|
-
END IF;
|
|
27
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_message_role_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'role'),"created_at","seq") WHERE "junior_conversation_events"."type" = 'message';--> statement-breakpoint
|
|
2
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_user_message_time_idx" ON "junior_conversation_events" USING btree ("conversation_id","created_at","seq") WHERE "junior_conversation_events"."type" = 'user_message' and ("junior_conversation_events"."payload"->'provenance'->>'authority') = 'instruction' and ("junior_conversation_events"."payload"->'provenance'->'actor'->>'platform') in ('slack', 'local', 'web');
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
-- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_events_guardian_review_time_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_events_guardian_review_time_idx" ON "junior_conversation_events" USING btree ("created_at") WHERE "junior_conversation_events"."type" = 'guardian_action_reviewed';
|
|
9
|
-
END IF;
|
|
10
|
-
|
|
11
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
12
|
-
IF NOT EXISTS (
|
|
13
|
-
SELECT 1 FROM pg_index
|
|
14
|
-
WHERE indexrelid = 'junior_conversation_events_guardian_review_time_idx'::regclass
|
|
15
|
-
AND indrelid = 'junior_conversation_events'::regclass
|
|
16
|
-
AND indisvalid AND indisready
|
|
17
|
-
) THEN
|
|
18
|
-
RAISE EXCEPTION 'The Guardian review time index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
19
|
-
END IF;
|
|
20
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_guardian_review_time_idx" ON "junior_conversation_events" USING btree ("created_at") WHERE "junior_conversation_events"."type" = 'guardian_action_reviewed';
|
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
-- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
|
|
3
|
-
DO $$
|
|
4
|
-
BEGIN
|
|
5
|
-
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
6
|
-
IF to_regclass('junior_conversation_participants_unsubscribed_idx') IS NULL THEN
|
|
7
|
-
-- junior:concurrent-index
|
|
8
|
-
CREATE INDEX "junior_conversation_participants_unsubscribed_idx" ON "junior_conversation_participants" USING btree ("user_id","root_conversation_id") WHERE "junior_conversation_participants"."unsubscribed_at" is not null;
|
|
9
|
-
END IF;
|
|
10
|
-
|
|
11
|
-
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
12
|
-
IF NOT EXISTS (
|
|
13
|
-
SELECT 1 FROM pg_index
|
|
14
|
-
WHERE indexrelid = 'junior_conversation_participants_unsubscribed_idx'::regclass
|
|
15
|
-
AND indrelid = 'junior_conversation_participants'::regclass
|
|
16
|
-
AND indisvalid AND indisready
|
|
17
|
-
) THEN
|
|
18
|
-
RAISE EXCEPTION 'The conversation participant unsubscribed index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
19
|
-
END IF;
|
|
20
|
-
END $$;
|
|
1
|
+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_participants_unsubscribed_idx" ON "junior_conversation_participants" USING btree ("user_id","root_conversation_id") WHERE "junior_conversation_participants"."unsubscribed_at" is not null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
-- An Automation task is an instruction or a skill. The `instruction` column
|
|
2
|
+
-- holds only an instruction, and the new `skill` column holds only a skill.
|
|
3
|
+
ALTER TABLE "junior_automations" ALTER COLUMN "instruction" DROP NOT NULL;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "junior_automations" ADD COLUMN "skill" text;--> statement-breakpoint
|
|
5
|
+
-- An Automation with a blank instruction could not run. Block it until its
|
|
6
|
+
-- creator writes an instruction or chooses a skill.
|
|
7
|
+
-- junior:bounded-backfill: changes only active or paused Automations with a blank instruction, which cannot run, so few rows match.
|
|
8
|
+
UPDATE "junior_automations"
|
|
9
|
+
SET
|
|
10
|
+
"status" = 'blocked',
|
|
11
|
+
"status_reason" = 'This automation has no instruction. Write one or choose a skill, then resume it.'
|
|
12
|
+
WHERE "record"->'task' ? 'text'
|
|
13
|
+
AND btrim("record"->'task'->>'text', E' \t\r\n') = ''
|
|
14
|
+
AND "status" IN ('active', 'paused');--> statement-breakpoint
|
|
15
|
+
-- Rewrite the old `{ text }` task as an instruction task. A blank
|
|
16
|
+
-- instruction gets a placeholder, because an instruction cannot be empty.
|
|
17
|
+
-- junior:bounded-backfill: runs once over the Automations of one install, which are few, and each row changes once.
|
|
18
|
+
WITH "old" AS (
|
|
19
|
+
SELECT
|
|
20
|
+
"id",
|
|
21
|
+
coalesce(
|
|
22
|
+
nullif(btrim("record"->'task'->>'text', E' \t\r\n'), ''),
|
|
23
|
+
'No instruction was saved.'
|
|
24
|
+
) AS "instruction"
|
|
25
|
+
FROM "junior_automations"
|
|
26
|
+
WHERE "record"->'task' ? 'text'
|
|
27
|
+
)
|
|
28
|
+
UPDATE "junior_automations"
|
|
29
|
+
SET
|
|
30
|
+
"instruction" = "old"."instruction",
|
|
31
|
+
"record" = jsonb_set(
|
|
32
|
+
"record",
|
|
33
|
+
'{task}',
|
|
34
|
+
jsonb_build_object('kind', 'instruction', 'instruction', "old"."instruction")
|
|
35
|
+
)
|
|
36
|
+
FROM "old"
|
|
37
|
+
WHERE "junior_automations"."id" = "old"."id";--> statement-breakpoint
|
|
38
|
+
-- Saved versions use the same `task` object, so history and diffs have one shape.
|
|
39
|
+
-- junior:bounded-backfill: runs once over the saved versions of one install, which are few, and each row changes once.
|
|
40
|
+
UPDATE "junior_automation_versions"
|
|
41
|
+
SET "definition" = ("definition" - 'instruction') || jsonb_build_object(
|
|
42
|
+
'task',
|
|
43
|
+
jsonb_build_object(
|
|
44
|
+
'kind', 'instruction',
|
|
45
|
+
'instruction', coalesce(
|
|
46
|
+
nullif(btrim("definition"->>'instruction', E' \t\r\n'), ''),
|
|
47
|
+
'No instruction was saved.'
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
WHERE "definition" ? 'instruction';--> statement-breakpoint
|
|
52
|
+
-- Finds the Automations that run a skill. Before this migration runs,
|
|
53
|
+
-- junior upgrade builds the marked index with CREATE INDEX CONCURRENTLY, so
|
|
54
|
+
-- the build below does not block writes.
|
|
55
|
+
DO $$
|
|
56
|
+
BEGIN
|
|
57
|
+
-- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
|
|
58
|
+
IF to_regclass('junior_automations_skill_idx') IS NULL THEN
|
|
59
|
+
-- junior:concurrent-index
|
|
60
|
+
CREATE INDEX "junior_automations_skill_idx" ON "junior_automations" USING btree ("skill","created_at_ms","id") WHERE "junior_automations"."status" <> 'deleted' AND "junior_automations"."skill" IS NOT NULL;
|
|
61
|
+
END IF;
|
|
62
|
+
|
|
63
|
+
-- A failed concurrent build can leave an index that exists but cannot be used.
|
|
64
|
+
IF NOT EXISTS (
|
|
65
|
+
SELECT 1 FROM pg_index
|
|
66
|
+
WHERE indexrelid = 'junior_automations_skill_idx'::regclass
|
|
67
|
+
AND indrelid = 'junior_automations'::regclass
|
|
68
|
+
AND indisvalid AND indisready
|
|
69
|
+
) THEN
|
|
70
|
+
RAISE EXCEPTION 'The Automation skill index is not valid and ready. Repair the concurrent build before running junior upgrade.';
|
|
71
|
+
END IF;
|
|
72
|
+
END $$;--> statement-breakpoint
|
|
73
|
+
-- The backfill above makes every row pass. NOT VALID skips the scan under
|
|
74
|
+
-- lock and still checks every new write. A later migration validates it.
|
|
75
|
+
ALTER TABLE "junior_automations" ADD CONSTRAINT "junior_automations_task_check" CHECK (("junior_automations"."instruction" is null) <> ("junior_automations"."skill" is null)) NOT VALID;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- NOT VALID: the widened checks accept every existing row, so they skip the
|
|
2
|
+
-- scan and still hold for every new write.
|
|
3
|
+
ALTER TABLE "junior_conversations" DROP CONSTRAINT "junior_conversations_kind_check";--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "junior_conversations" DROP CONSTRAINT "junior_conversations_kind_parent_check";--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "junior_conversations" ADD CONSTRAINT "junior_conversations_kind_check" CHECK ("junior_conversations"."kind" in ('root', 'automation', 'thread', 'task')) NOT VALID;--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "junior_conversations" ADD CONSTRAINT "junior_conversations_kind_parent_check" CHECK ("junior_conversations"."kind" is null or (("junior_conversations"."kind" in ('root', 'automation')) = ("junior_conversations"."parent_conversation_id" is null))) NOT VALID;
|