@sentry/junior 0.316.0 → 0.317.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/{admin-QYiDMnsu.js → admin-CAugg87B.js} +1 -1
- package/dist/{agent-runner-Cr5Fhjf-.js → agent-runner-AjrEV6Qe.js} +13438 -13149
- package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
- package/dist/{agent-update-delivery-BY13DPSD.js → agent-update-delivery-B_YIZcgf.js} +5 -5
- package/dist/api/schema.d.ts +558 -102
- package/dist/api/schema.js +6 -6
- package/dist/api.js +230 -213
- package/dist/{app-BhvzRD__.d.ts → app-MoNAsVV5.d.ts} +34 -14
- package/dist/app.d.ts +1 -1
- package/dist/app.js +167 -122
- package/dist/catalog-runtime-DfSpJZdY.js +6 -0
- package/dist/{change-record-Bqsa5ZXE.d.ts → change-record-BzJgLsv7.d.ts} +60 -1
- package/dist/{adapter-context-Bref7aPI.js → channel-access-j-YAVYK4.js} +2 -42
- package/dist/{chat-core-engine-3dtlMku3.js → chat-core-engine-aH85nEHv.js} +4 -3
- package/dist/{child-message--2G3Ft26.js → child-message-DHjQLEd1.js} +1 -1
- package/dist/cli/chat.js +23 -23
- package/dist/cli/check.js +5 -5
- package/dist/cli/main.js +2 -2
- package/dist/cli/plugins.js +5 -4
- package/dist/cli/snapshot-create.js +5 -2
- package/dist/cli/upgrade.js +5 -3
- package/dist/config-CHQ8X251.js +2422 -0
- package/dist/{continue-in-slack-DbQUFe_F.js → continue-in-slack-D-FZ8Fin.js} +2 -3
- package/dist/{conversation-feed-B84pMjHo.js → conversation-feed--9S0_PXL.js} +3 -3
- package/dist/{proxy-path-BTmXDjfx.js → conversation-privacy-B1uXn5sf.js} +2 -16
- package/dist/{conversation-turn-DzEpTIaf.js → conversation-turn-BUE_7xaN.js} +99 -76
- package/dist/{create-DUJBXr6E.js → create-DoDIYgtZ.js} +12 -9
- package/dist/{credential-sync-JH_K9Adg.js → credential-sync-BJOqGnjV.js} +17 -12
- package/dist/{db-DhzvUY23.js → db-BFmyYZtJ.js} +20265 -27551
- package/dist/{deployment-BhvrhQeh.js → deployment-DXq9ZLU4.js} +17 -15
- package/dist/{engine-context-C9Nal48K.js → engine-context-CgQ7mlHt.js} +264 -47
- package/dist/{html-B_12WjKT.js → html-B3VKTGbJ.js} +6 -2
- package/dist/instrumentation.js +15 -7
- package/dist/{job-runner-DO8nslyY.js → job-runner-A1lCkybD.js} +391 -24
- package/dist/{lineage-D3AZAJVe.js → lineage-Bktb0UcV.js} +1 -1
- package/dist/{list-B0zsb5Cp.js → list-Bxvg5wXf.js} +224 -544
- package/dist/{logging-B8KEJegM.js → logging--smS7XRK.js} +2 -2
- package/dist/{session-stop-DponjDUZ.js → mailbox-turn-uSXhUFc9.js} +4747 -7039
- package/dist/{message-B5fKDYzz.js → message-BNenhsmB.js} +12 -22
- package/dist/{model-input-CuMWy37l.js → model-input-BReSnwHp.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +20 -6
- package/dist/{oauth-callback-server-B3Vvlydo.js → oauth-callback-server-CE4soEIY.js} +2 -2
- package/dist/{oauth-relay-6ERrGPbA.js → oauth-relay-C36gX1gH.js} +2 -2
- package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
- package/dist/{list-mkB_GU8R.js → parent-result-Ck1rFYRQ.js} +107 -92
- package/dist/{plugins-BXMdNdyA.js → plugins-D_Ru4CWc.js} +1 -1
- package/dist/profile-BQ-iBDsZ.js +4657 -0
- package/dist/{transcript-CCi7323k.js → prompt-Dv7gkpD6.js} +97 -103
- package/dist/proxy-path-BHYoKZdq.js +15 -0
- package/dist/registry-iXMT5Jmh.js +3279 -0
- package/dist/reports-WKHfGTsU.js +195 -0
- package/dist/{resolve-D5JVvv6A.js → resolve-tony4ibz.js} +9 -29
- package/dist/{result-CS_7mo8a.js → result-Bta_dlWa.js} +25 -116
- package/dist/run-conversation-DL6ru7iW.js +336 -0
- package/dist/{runner-BzAES5W3.js → runner-BstDRbD9.js} +7 -7
- package/dist/{sandbox-egress-signals-Dwhk2Q5F.js → sandbox-egress-signals-oSJMJOnn.js} +1 -1
- package/dist/{schema-z5-wA6N4.js → schema-DfqrHACA.js} +48 -86
- package/dist/sender-actors-CPglLd5R.js +83 -0
- package/dist/{service-account-D6AsAtc1.js → service-account-CTV_jaNu.js} +3 -1
- package/dist/{skills-DgJ9GBPR.js → skills-BCEU41zM.js} +4 -4
- package/dist/{slack-conversation-unfurl-Dq71EkhM.js → slack-conversation-unfurl-DxVmhbGP.js} +7 -6
- package/dist/{spawn-BJWpdwhQ.js → spawn-frczVPIr.js} +11 -8
- package/dist/{system-prompt-table-iIgpmslr.js → system-prompt-table-CiXy0eNR.js} +88 -69
- package/dist/{task-runner-BJae4JwE.js → task-runner-C9Yc2_ae.js} +20 -46
- package/dist/{thread-context-fiMNylbg.js → thread-context-CqZDKErp.js} +6 -6
- package/dist/topics-SRN7IVX-.js +24 -0
- package/dist/turn-membership-CENFf3kI.js +856 -0
- package/dist/{turn-wake-BjDW7x-5.js → turn-wake-BhloiI2h.js} +4 -5
- package/dist/{media-BebquhET.js → types-C4iC-IMC.js} +801 -771
- package/dist/user-customization-CvfuY9Eo.js +93 -0
- package/dist/users-ByG5RCEJ.js +181 -0
- package/dist/{validation-D5WmmmhX.js → validation-8gjfR91V.js} +1 -1
- package/dist/{version-CBQoanXb.js → version-BeZhWWBE.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{worker-Cyb4kF17.js → worker-BqMQQNRk.js} +5 -4
- package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
- package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
- package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
- package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
- package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
- package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
- package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
- package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
- package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
- package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
- package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
- package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
- package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
- package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
- package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
- package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
- package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
- package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
- package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
- package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
- package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
- package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
- package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
- package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
- package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
- package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
- package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
- package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
- package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
- package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
- package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
- package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
- package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
- package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
- package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
- package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
- package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
- package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
- package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
- package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
- package/package.json +5 -5
- package/dist/people-CUtFApfL.js +0 -81
- package/dist/start-conversation-B-LIqqNi.js +0 -162
- package/dist/turn-session-routing-D15orfwy.js +0 -1309
- package/dist/user-customization-B27StpVQ.js +0 -9
- package/dist/web-message-id-C6P83ans.js +0 -10
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
-- A question now holds its own content, and its Inbox item points at it
|
|
2
|
+
-- with the subject `{ kind: "question", id }`. Each existing question item
|
|
3
|
+
-- gets a question with the item's id, and its content moves there. The
|
|
4
|
+
-- request's `evidence` links are now its `related` links.
|
|
5
|
+
CREATE TABLE "junior_questions" (
|
|
6
|
+
"id" text PRIMARY KEY,
|
|
7
|
+
"conversation_id" text NOT NULL,
|
|
8
|
+
"turn_id" text,
|
|
9
|
+
"title" text NOT NULL,
|
|
10
|
+
"body" text NOT NULL,
|
|
11
|
+
"request" jsonb,
|
|
12
|
+
"answer" jsonb,
|
|
13
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
14
|
+
"updated_at" timestamp with time zone NOT NULL
|
|
15
|
+
);
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
ALTER TABLE "junior_questions" ADD CONSTRAINT "junior_questions_HSrO9i8pUj0G_fkey" FOREIGN KEY ("conversation_id") REFERENCES "junior_conversations"("conversation_id") ON DELETE CASCADE;--> statement-breakpoint
|
|
18
|
+
CREATE INDEX "junior_questions_conversation_idx" ON "junior_questions" ("conversation_id");--> statement-breakpoint
|
|
19
|
+
CREATE INDEX "junior_questions_search_idx" ON "junior_questions" USING gin ((setweight(to_tsvector('simple', "title"), 'A') || setweight(to_tsvector('simple', "body"), 'B')));--> statement-breakpoint
|
|
20
|
+
CREATE INDEX "junior_questions_title_trgm_idx" ON "junior_questions" USING gin (lower("title") gin_trgm_ops);--> statement-breakpoint
|
|
21
|
+
-- Old workers still write a question item's content on the item while this
|
|
22
|
+
-- release rolls out: its title, body, and request when they add or change
|
|
23
|
+
-- it, and its answer when they close it. This trigger copies that content
|
|
24
|
+
-- to the item's question, so new code reads it there. A new item's question
|
|
25
|
+
-- takes the item's id, and the request's `evidence` key becomes `related`.
|
|
26
|
+
-- A notice keeps its link in `subject_url`, which becomes its one related
|
|
27
|
+
-- link. The item keeps its own copy, because the old columns and checks
|
|
28
|
+
-- stay for the release before this one. The trigger copies only content
|
|
29
|
+
-- that changed, so a write of new code, which leaves the item's copy as it
|
|
30
|
+
-- is, never copies an old copy over the question. The backfill below fires
|
|
31
|
+
-- the same trigger. Its name sorts after `junior_inbox_items_legacy_subject`,
|
|
32
|
+
-- which gives an old worker's new item its subject kind first.
|
|
33
|
+
CREATE OR REPLACE FUNCTION "junior_inbox_items_legacy_question"()
|
|
34
|
+
RETURNS trigger
|
|
35
|
+
LANGUAGE plpgsql
|
|
36
|
+
AS $function$
|
|
37
|
+
DECLARE
|
|
38
|
+
question_request jsonb := NEW."request";
|
|
39
|
+
BEGIN
|
|
40
|
+
IF TG_OP = 'UPDATE'
|
|
41
|
+
AND NEW."subject_id" IS NOT DISTINCT FROM OLD."subject_id"
|
|
42
|
+
AND NEW."title" IS NOT DISTINCT FROM OLD."title"
|
|
43
|
+
AND NEW."body" IS NOT DISTINCT FROM OLD."body"
|
|
44
|
+
AND NEW."request" IS NOT DISTINCT FROM OLD."request"
|
|
45
|
+
AND NEW."answer" IS NOT DISTINCT FROM OLD."answer"
|
|
46
|
+
THEN
|
|
47
|
+
RETURN NEW;
|
|
48
|
+
END IF;
|
|
49
|
+
IF TG_OP = 'INSERT' THEN
|
|
50
|
+
NEW."subject_id" := NEW."id";
|
|
51
|
+
END IF;
|
|
52
|
+
IF question_request ? 'evidence' THEN
|
|
53
|
+
question_request := (question_request - 'evidence') || jsonb_build_object('related', question_request -> 'evidence');
|
|
54
|
+
END IF;
|
|
55
|
+
IF question_request IS NULL AND NEW."kind" = 'notice' AND NEW."subject_url" ~* '^https?://' THEN
|
|
56
|
+
question_request := jsonb_build_object('related', jsonb_build_array(jsonb_build_object('label', left(coalesce(nullif(NEW."subject_title", ''), NEW."subject_url"), 120), 'url', "junior_inbox_items_web_link"(NEW."subject_url"))));
|
|
57
|
+
END IF;
|
|
58
|
+
INSERT INTO "junior_questions" ("id", "conversation_id", "turn_id", "title", "body", "request", "answer", "created_at", "updated_at")
|
|
59
|
+
VALUES (NEW."subject_id", NEW."owner_id", NEW."added_by_turn_id", coalesce(NEW."title", ''), coalesce(NEW."body", ''), question_request, NEW."answer", NEW."created_at", NEW."updated_at")
|
|
60
|
+
ON CONFLICT ("id") DO UPDATE SET
|
|
61
|
+
"title" = coalesce(NEW."title", "junior_questions"."title"),
|
|
62
|
+
"body" = coalesce(NEW."body", "junior_questions"."body"),
|
|
63
|
+
"request" = coalesce(question_request, "junior_questions"."request"),
|
|
64
|
+
"answer" = coalesce(NEW."answer", "junior_questions"."answer"),
|
|
65
|
+
"updated_at" = NEW."updated_at";
|
|
66
|
+
RETURN NEW;
|
|
67
|
+
END;
|
|
68
|
+
$function$;--> statement-breakpoint
|
|
69
|
+
CREATE TRIGGER "junior_inbox_items_legacy_subject_question" BEFORE INSERT OR UPDATE ON "junior_inbox_items" FOR EACH ROW WHEN (NEW."subject_kind" = 'question' AND (NEW."title" IS NOT NULL OR NEW."body" IS NOT NULL OR NEW."request" IS NOT NULL OR NEW."answer" IS NOT NULL)) EXECUTE FUNCTION "junior_inbox_items_legacy_question"();--> statement-breakpoint
|
|
70
|
+
-- A question belongs to its Conversation. A question item whose owner
|
|
71
|
+
-- Conversation is gone has no place for its question, and nobody can see
|
|
72
|
+
-- it, so the migration deletes it. Its snoozes and other rows go with it.
|
|
73
|
+
-- junior:bounded-backfill: it deletes only the question items whose owner Conversation row is gone, which Junior does not expect to find, once.
|
|
74
|
+
DELETE FROM "junior_inbox_items" WHERE "subject_kind" = 'question' AND NOT EXISTS (SELECT 1 FROM "junior_conversations" WHERE "junior_conversations"."conversation_id" = "junior_inbox_items"."owner_id");--> statement-breakpoint
|
|
75
|
+
-- junior:bounded-backfill: each question item moves its content to a new question once, through the trigger above, and the question takes the item's id. It reads only the question items, which are asks and notices for people, and writes each row once.
|
|
76
|
+
UPDATE "junior_inbox_items" SET "subject_id" = "id" WHERE "subject_kind" = 'question';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- This migration does not change the database. The two migrations before
|
|
2
|
+
-- it add `junior_questions` and change `junior_inbox_items` by hand,
|
|
3
|
+
-- because data moves between their statements. This snapshot records the
|
|
4
|
+
-- schema that they leave, so `drizzle-kit generate` does not write their
|
|
5
|
+
-- changes again.
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "diff",
|
|
3
|
+
"version": "10",
|
|
4
|
+
"dialect": "postgres",
|
|
5
|
+
"id": "e9774788-9b7a-4fba-a7ac-beba0fd9ee30",
|
|
6
|
+
"prevIds": ["a0694ee7-a7bb-4440-8283-3cb5add2ee08"],
|
|
7
|
+
"footprints": [
|
|
8
|
+
{
|
|
9
|
+
"statementType": "create_table",
|
|
10
|
+
"statementTarget": ["table", "public", "junior_questions"],
|
|
11
|
+
"writes": [
|
|
12
|
+
"s|tbl|public.junior_questions",
|
|
13
|
+
"n|tbl|public.junior_questions",
|
|
14
|
+
"e|tbl|public.junior_questions",
|
|
15
|
+
"n|rel|public.junior_questions",
|
|
16
|
+
"n|type|public.junior_questions",
|
|
17
|
+
"n|rel|public.junior_questions_pkey"
|
|
18
|
+
],
|
|
19
|
+
"reads": ["n|sch|public"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"statementType": "alter_column",
|
|
23
|
+
"statementTarget": ["column", "public", "junior_inbox_items", "title"],
|
|
24
|
+
"writes": ["s|colprop|public.junior_inbox_items.title.notNull"],
|
|
25
|
+
"reads": [
|
|
26
|
+
"n|tbl|public.junior_inbox_items",
|
|
27
|
+
"n|sch|public",
|
|
28
|
+
"n|col|public.junior_inbox_items.title"
|
|
29
|
+
],
|
|
30
|
+
"sqlHash": "833d74c3bcd16cec"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"statementType": "alter_column",
|
|
34
|
+
"statementTarget": ["column", "public", "junior_inbox_items", "body"],
|
|
35
|
+
"writes": ["s|colprop|public.junior_inbox_items.body.notNull"],
|
|
36
|
+
"reads": [
|
|
37
|
+
"n|tbl|public.junior_inbox_items",
|
|
38
|
+
"n|sch|public",
|
|
39
|
+
"n|col|public.junior_inbox_items.body"
|
|
40
|
+
],
|
|
41
|
+
"sqlHash": "568abfd4e22e842a"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"statementType": "create_index",
|
|
45
|
+
"statementTarget": [
|
|
46
|
+
"index",
|
|
47
|
+
"public",
|
|
48
|
+
"junior_questions",
|
|
49
|
+
"junior_questions_conversation_idx"
|
|
50
|
+
],
|
|
51
|
+
"writes": [
|
|
52
|
+
"s|idx|public.junior_questions_conversation_idx",
|
|
53
|
+
"n|idx|public.junior_questions_conversation_idx",
|
|
54
|
+
"e|idx|public.junior_questions_conversation_idx",
|
|
55
|
+
"n|rel|public.junior_questions_conversation_idx"
|
|
56
|
+
],
|
|
57
|
+
"reads": [
|
|
58
|
+
"n|tbl|public.junior_questions",
|
|
59
|
+
"n|sch|public",
|
|
60
|
+
"n|col|public.junior_questions.conversation_id"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"statementType": "create_index",
|
|
65
|
+
"statementTarget": [
|
|
66
|
+
"index",
|
|
67
|
+
"public",
|
|
68
|
+
"junior_questions",
|
|
69
|
+
"junior_questions_search_idx"
|
|
70
|
+
],
|
|
71
|
+
"writes": [
|
|
72
|
+
"s|idx|public.junior_questions_search_idx",
|
|
73
|
+
"n|idx|public.junior_questions_search_idx",
|
|
74
|
+
"e|idx|public.junior_questions_search_idx",
|
|
75
|
+
"n|rel|public.junior_questions_search_idx"
|
|
76
|
+
],
|
|
77
|
+
"reads": ["n|tbl|public.junior_questions", "n|sch|public"]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"statementType": "create_index",
|
|
81
|
+
"statementTarget": [
|
|
82
|
+
"index",
|
|
83
|
+
"public",
|
|
84
|
+
"junior_questions",
|
|
85
|
+
"junior_questions_title_trgm_idx"
|
|
86
|
+
],
|
|
87
|
+
"writes": [
|
|
88
|
+
"s|idx|public.junior_questions_title_trgm_idx",
|
|
89
|
+
"n|idx|public.junior_questions_title_trgm_idx",
|
|
90
|
+
"e|idx|public.junior_questions_title_trgm_idx",
|
|
91
|
+
"n|rel|public.junior_questions_title_trgm_idx"
|
|
92
|
+
],
|
|
93
|
+
"reads": ["n|tbl|public.junior_questions", "n|sch|public"]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"statementType": "create_fk",
|
|
97
|
+
"statementTarget": ["table", "public", "junior_questions"],
|
|
98
|
+
"writes": [
|
|
99
|
+
"s|fk|public.junior_questions.junior_questions_HSrO9i8pUj0G_fkey",
|
|
100
|
+
"n|fk|public.junior_questions.junior_questions_HSrO9i8pUj0G_fkey",
|
|
101
|
+
"e|fk|public.junior_questions.junior_questions_HSrO9i8pUj0G_fkey",
|
|
102
|
+
"n|con|public.junior_questions.junior_questions_HSrO9i8pUj0G_fkey"
|
|
103
|
+
],
|
|
104
|
+
"reads": [
|
|
105
|
+
"n|tbl|public.junior_questions",
|
|
106
|
+
"n|sch|public",
|
|
107
|
+
"n|tbl|public.junior_conversations",
|
|
108
|
+
"n|sch|public",
|
|
109
|
+
"n|col|public.junior_questions.conversation_id",
|
|
110
|
+
"n|col|public.junior_conversations.conversation_id",
|
|
111
|
+
"e|uniqueness|public.junior_conversations.conversation_id"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"statementType": "alter_check",
|
|
116
|
+
"statementTarget": ["table", "public", "junior_inbox_items"],
|
|
117
|
+
"writes": [
|
|
118
|
+
"s|ck|public.junior_inbox_items.junior_inbox_items_kind_check"
|
|
119
|
+
],
|
|
120
|
+
"reads": [
|
|
121
|
+
"n|tbl|public.junior_inbox_items",
|
|
122
|
+
"n|sch|public",
|
|
123
|
+
"n|col|public.junior_inbox_items.kind",
|
|
124
|
+
"n|col|public.junior_inbox_items.request",
|
|
125
|
+
"n|col|public.junior_inbox_items.answer",
|
|
126
|
+
"n|col|public.junior_inbox_items.subject_kind",
|
|
127
|
+
"e|col|public.junior_inbox_items.kind",
|
|
128
|
+
"e|col|public.junior_inbox_items.request",
|
|
129
|
+
"e|col|public.junior_inbox_items.answer",
|
|
130
|
+
"e|col|public.junior_inbox_items.subject_kind"
|
|
131
|
+
],
|
|
132
|
+
"sqlHash": "e3747a4d3b5f2f77"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"deltas": [
|
|
136
|
+
{
|
|
137
|
+
"op": "create",
|
|
138
|
+
"row": {
|
|
139
|
+
"schema": "public",
|
|
140
|
+
"name": "junior_questions",
|
|
141
|
+
"isRlsEnabled": false,
|
|
142
|
+
"entityType": "tables"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"op": "create",
|
|
147
|
+
"row": {
|
|
148
|
+
"schema": "public",
|
|
149
|
+
"table": "junior_questions",
|
|
150
|
+
"name": "id",
|
|
151
|
+
"type": "text",
|
|
152
|
+
"typeSchema": null,
|
|
153
|
+
"notNull": true,
|
|
154
|
+
"dimensions": 0,
|
|
155
|
+
"default": null,
|
|
156
|
+
"generated": null,
|
|
157
|
+
"identity": null,
|
|
158
|
+
"entityType": "columns"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"op": "create",
|
|
163
|
+
"row": {
|
|
164
|
+
"schema": "public",
|
|
165
|
+
"table": "junior_questions",
|
|
166
|
+
"name": "conversation_id",
|
|
167
|
+
"type": "text",
|
|
168
|
+
"typeSchema": null,
|
|
169
|
+
"notNull": true,
|
|
170
|
+
"dimensions": 0,
|
|
171
|
+
"default": null,
|
|
172
|
+
"generated": null,
|
|
173
|
+
"identity": null,
|
|
174
|
+
"entityType": "columns"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"op": "create",
|
|
179
|
+
"row": {
|
|
180
|
+
"schema": "public",
|
|
181
|
+
"table": "junior_questions",
|
|
182
|
+
"name": "turn_id",
|
|
183
|
+
"type": "text",
|
|
184
|
+
"typeSchema": null,
|
|
185
|
+
"notNull": false,
|
|
186
|
+
"dimensions": 0,
|
|
187
|
+
"default": null,
|
|
188
|
+
"generated": null,
|
|
189
|
+
"identity": null,
|
|
190
|
+
"entityType": "columns"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"op": "create",
|
|
195
|
+
"row": {
|
|
196
|
+
"schema": "public",
|
|
197
|
+
"table": "junior_questions",
|
|
198
|
+
"name": "title",
|
|
199
|
+
"type": "text",
|
|
200
|
+
"typeSchema": null,
|
|
201
|
+
"notNull": true,
|
|
202
|
+
"dimensions": 0,
|
|
203
|
+
"default": null,
|
|
204
|
+
"generated": null,
|
|
205
|
+
"identity": null,
|
|
206
|
+
"entityType": "columns"
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"op": "create",
|
|
211
|
+
"row": {
|
|
212
|
+
"schema": "public",
|
|
213
|
+
"table": "junior_questions",
|
|
214
|
+
"name": "body",
|
|
215
|
+
"type": "text",
|
|
216
|
+
"typeSchema": null,
|
|
217
|
+
"notNull": true,
|
|
218
|
+
"dimensions": 0,
|
|
219
|
+
"default": null,
|
|
220
|
+
"generated": null,
|
|
221
|
+
"identity": null,
|
|
222
|
+
"entityType": "columns"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"op": "create",
|
|
227
|
+
"row": {
|
|
228
|
+
"schema": "public",
|
|
229
|
+
"table": "junior_questions",
|
|
230
|
+
"name": "request",
|
|
231
|
+
"type": "jsonb",
|
|
232
|
+
"typeSchema": null,
|
|
233
|
+
"notNull": false,
|
|
234
|
+
"dimensions": 0,
|
|
235
|
+
"default": null,
|
|
236
|
+
"generated": null,
|
|
237
|
+
"identity": null,
|
|
238
|
+
"entityType": "columns"
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"op": "create",
|
|
243
|
+
"row": {
|
|
244
|
+
"schema": "public",
|
|
245
|
+
"table": "junior_questions",
|
|
246
|
+
"name": "answer",
|
|
247
|
+
"type": "jsonb",
|
|
248
|
+
"typeSchema": null,
|
|
249
|
+
"notNull": false,
|
|
250
|
+
"dimensions": 0,
|
|
251
|
+
"default": null,
|
|
252
|
+
"generated": null,
|
|
253
|
+
"identity": null,
|
|
254
|
+
"entityType": "columns"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"op": "create",
|
|
259
|
+
"row": {
|
|
260
|
+
"schema": "public",
|
|
261
|
+
"table": "junior_questions",
|
|
262
|
+
"name": "created_at",
|
|
263
|
+
"type": "timestamp with time zone",
|
|
264
|
+
"typeSchema": null,
|
|
265
|
+
"notNull": true,
|
|
266
|
+
"dimensions": 0,
|
|
267
|
+
"default": null,
|
|
268
|
+
"generated": null,
|
|
269
|
+
"identity": null,
|
|
270
|
+
"entityType": "columns"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"op": "create",
|
|
275
|
+
"row": {
|
|
276
|
+
"schema": "public",
|
|
277
|
+
"table": "junior_questions",
|
|
278
|
+
"name": "updated_at",
|
|
279
|
+
"type": "timestamp with time zone",
|
|
280
|
+
"typeSchema": null,
|
|
281
|
+
"notNull": true,
|
|
282
|
+
"dimensions": 0,
|
|
283
|
+
"default": null,
|
|
284
|
+
"generated": null,
|
|
285
|
+
"identity": null,
|
|
286
|
+
"entityType": "columns"
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"op": "create",
|
|
291
|
+
"row": {
|
|
292
|
+
"schema": "public",
|
|
293
|
+
"table": "junior_questions",
|
|
294
|
+
"name": "junior_questions_conversation_idx",
|
|
295
|
+
"nameExplicit": true,
|
|
296
|
+
"columns": [
|
|
297
|
+
{
|
|
298
|
+
"value": "conversation_id",
|
|
299
|
+
"isExpression": false,
|
|
300
|
+
"asc": true,
|
|
301
|
+
"nullsFirst": false,
|
|
302
|
+
"opclass": null
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"isUnique": false,
|
|
306
|
+
"where": null,
|
|
307
|
+
"with": "",
|
|
308
|
+
"method": "btree",
|
|
309
|
+
"entityType": "indexes"
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"op": "create",
|
|
314
|
+
"row": {
|
|
315
|
+
"schema": "public",
|
|
316
|
+
"table": "junior_questions",
|
|
317
|
+
"name": "junior_questions_search_idx",
|
|
318
|
+
"nameExplicit": true,
|
|
319
|
+
"columns": [
|
|
320
|
+
{
|
|
321
|
+
"value": "(setweight(to_tsvector('simple', \"title\"), 'A') || setweight(to_tsvector('simple', \"body\"), 'B'))",
|
|
322
|
+
"isExpression": true,
|
|
323
|
+
"asc": true,
|
|
324
|
+
"nullsFirst": false,
|
|
325
|
+
"opclass": null
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
"isUnique": false,
|
|
329
|
+
"where": null,
|
|
330
|
+
"with": "",
|
|
331
|
+
"method": "gin",
|
|
332
|
+
"entityType": "indexes"
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"op": "create",
|
|
337
|
+
"row": {
|
|
338
|
+
"schema": "public",
|
|
339
|
+
"table": "junior_questions",
|
|
340
|
+
"name": "junior_questions_title_trgm_idx",
|
|
341
|
+
"nameExplicit": true,
|
|
342
|
+
"columns": [
|
|
343
|
+
{
|
|
344
|
+
"value": "lower(\"title\") gin_trgm_ops",
|
|
345
|
+
"isExpression": true,
|
|
346
|
+
"asc": true,
|
|
347
|
+
"nullsFirst": false,
|
|
348
|
+
"opclass": null
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
"isUnique": false,
|
|
352
|
+
"where": null,
|
|
353
|
+
"with": "",
|
|
354
|
+
"method": "gin",
|
|
355
|
+
"entityType": "indexes"
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"op": "create",
|
|
360
|
+
"row": {
|
|
361
|
+
"schema": "public",
|
|
362
|
+
"table": "junior_questions",
|
|
363
|
+
"name": "junior_questions_HSrO9i8pUj0G_fkey",
|
|
364
|
+
"nameExplicit": false,
|
|
365
|
+
"columns": ["conversation_id"],
|
|
366
|
+
"schemaTo": "public",
|
|
367
|
+
"tableTo": "junior_conversations",
|
|
368
|
+
"columnsTo": ["conversation_id"],
|
|
369
|
+
"onUpdate": "NO ACTION",
|
|
370
|
+
"onDelete": "CASCADE",
|
|
371
|
+
"entityType": "fks"
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"op": "create",
|
|
376
|
+
"row": {
|
|
377
|
+
"schema": "public",
|
|
378
|
+
"table": "junior_questions",
|
|
379
|
+
"name": "junior_questions_pkey",
|
|
380
|
+
"columns": ["id"],
|
|
381
|
+
"nameExplicit": false,
|
|
382
|
+
"entityType": "pks"
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
"op": "alter",
|
|
387
|
+
"key": "columns\u0000[\"public\",\"junior_inbox_items\",\"title\"]",
|
|
388
|
+
"set": {
|
|
389
|
+
"notNull": false
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
"op": "alter",
|
|
394
|
+
"key": "columns\u0000[\"public\",\"junior_inbox_items\",\"body\"]",
|
|
395
|
+
"set": {
|
|
396
|
+
"notNull": false
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"op": "alter",
|
|
401
|
+
"key": "checks\u0000[\"public\",\"junior_inbox_items\",\"junior_inbox_items_kind_check\"]",
|
|
402
|
+
"set": {
|
|
403
|
+
"value": "(\"kind\" = 'notice' and \"request\" -> 'question' is null and \"answer\" is null) or (\"kind\" = 'action' and (\"request\" -> 'question' is not null or (\"subject_kind\" <> 'reply' and \"answer\" is null)))"
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
-- New code reads the owner, visibility, and provider tenant of an Inbox item
|
|
2
|
+
-- from its subject (`chat/inbox-items/owner.ts`), and its schema no longer
|
|
3
|
+
-- names `dedupe_key`, `owner_kind`, `owner_id`, or `visibility`. They keep
|
|
4
|
+
-- their NOT NULL and their checks for one release, so the release before
|
|
5
|
+
-- this one can still read and write every row after a rollback. This
|
|
6
|
+
-- trigger writes them for new code: the owner that the code adding the item
|
|
7
|
+
-- names (`junior.inbox_item_owner_kind` and `junior.inbox_item_owner_id`,
|
|
8
|
+
-- set for its transaction), a dedupe key in the old form of its subject
|
|
9
|
+
-- kind, and the owner's visibility: its Destination's, but private while
|
|
10
|
+
-- an owner Conversation is private. A question item gets a copy of its
|
|
11
|
+
-- question's title and body, and an action also gets a copy of its
|
|
12
|
+
-- request, which the old kind check needs. An old worker writes all
|
|
13
|
+
-- of them itself, so the trigger leaves its rows alone. A later release
|
|
14
|
+
-- drops the trigger with the old columns and checks. Its name sorts after
|
|
15
|
+
-- `junior_inbox_items_legacy_subject_question`, so an old worker's question
|
|
16
|
+
-- item has its content before it runs.
|
|
17
|
+
CREATE OR REPLACE FUNCTION "junior_inbox_items_legacy_write"()
|
|
18
|
+
RETURNS trigger
|
|
19
|
+
LANGUAGE plpgsql
|
|
20
|
+
AS $function$
|
|
21
|
+
DECLARE
|
|
22
|
+
question record;
|
|
23
|
+
BEGIN
|
|
24
|
+
IF TG_OP = 'INSERT' AND NEW."dedupe_key" IS NULL THEN
|
|
25
|
+
NEW."owner_kind" := nullif(current_setting('junior.inbox_item_owner_kind', true), '');
|
|
26
|
+
NEW."owner_id" := nullif(current_setting('junior.inbox_item_owner_id', true), '');
|
|
27
|
+
IF NEW."owner_kind" IS NULL OR NEW."owner_id" IS NULL THEN
|
|
28
|
+
RAISE EXCEPTION 'Inbox item % has no owner to write', NEW."id";
|
|
29
|
+
END IF;
|
|
30
|
+
NEW."dedupe_key" := CASE
|
|
31
|
+
WHEN NEW."subject_kind" IN ('automation', 'reply', 'todo') THEN NEW."subject_kind" || ':' || NEW."subject_id"
|
|
32
|
+
WHEN NEW."subject_kind" = 'question' THEN NEW."subject_id"
|
|
33
|
+
ELSE 'plugin:' || NEW."subject_kind" || ':' || NEW."subject_id"
|
|
34
|
+
END;
|
|
35
|
+
NEW."visibility" := CASE
|
|
36
|
+
WHEN NEW."subject_kind" = 'todo' THEN 'private'
|
|
37
|
+
WHEN NEW."owner_kind" = 'automation' THEN (SELECT d."visibility" FROM "junior_automations" a JOIN "junior_destinations" d ON d."provider" = 'slack' AND d."provider_tenant_id" = a."team_id" AND d."provider_destination_id" = a."channel_id" WHERE a."id" = NEW."owner_id")
|
|
38
|
+
ELSE (SELECT CASE WHEN r."visibility" = 'public' THEN d."visibility" END FROM "junior_conversations" o JOIN "junior_conversations" r ON r."conversation_id" = o."root_conversation_id" JOIN "junior_destinations" d ON d."id" = r."destination_id" WHERE o."conversation_id" = NEW."owner_id")
|
|
39
|
+
END;
|
|
40
|
+
IF NEW."visibility" IS DISTINCT FROM 'public' THEN
|
|
41
|
+
NEW."visibility" := 'private';
|
|
42
|
+
END IF;
|
|
43
|
+
END IF;
|
|
44
|
+
IF NEW."subject_kind" = 'question'
|
|
45
|
+
AND (NEW."title" IS NULL OR NEW."body" IS NULL OR (NEW."kind" = 'action' AND NEW."request" IS NULL))
|
|
46
|
+
THEN
|
|
47
|
+
SELECT q."title", q."body", q."request" INTO question FROM "junior_questions" q WHERE q."id" = NEW."subject_id";
|
|
48
|
+
NEW."title" := coalesce(NEW."title", question."title", '');
|
|
49
|
+
NEW."body" := coalesce(NEW."body", question."body", '');
|
|
50
|
+
IF NEW."kind" = 'action' AND NEW."request" IS NULL THEN
|
|
51
|
+
-- The release before this one reads `evidence`, not `related`.
|
|
52
|
+
NEW."request" := CASE
|
|
53
|
+
WHEN question."request" ? 'related' THEN (question."request" - 'related') || jsonb_build_object('evidence', question."request" -> 'related')
|
|
54
|
+
ELSE coalesce(question."request", '{}'::jsonb)
|
|
55
|
+
END;
|
|
56
|
+
END IF;
|
|
57
|
+
END IF;
|
|
58
|
+
RETURN NEW;
|
|
59
|
+
END;
|
|
60
|
+
$function$;--> statement-breakpoint
|
|
61
|
+
CREATE OR REPLACE TRIGGER "junior_inbox_items_legacy_write" BEFORE INSERT OR UPDATE ON "junior_inbox_items" FOR EACH ROW EXECUTE FUNCTION "junior_inbox_items_legacy_write"();--> statement-breakpoint
|
|
62
|
+
-- A subject now has one open item in all provider tenants, not one in each.
|
|
63
|
+
-- Before the next migration makes that unique, the newest open item of a
|
|
64
|
+
-- subject stays open and the others close. Two tenants seldom share a
|
|
65
|
+
-- subject, because each subject id names one Conversation, Automation, or
|
|
66
|
+
-- plugin object.
|
|
67
|
+
-- junior:bounded-backfill: only open items whose subject has a newer open item in another provider tenant change.
|
|
68
|
+
UPDATE "junior_inbox_items" AS "item" SET "status" = 'dismissed', "closed_at" = now(), "close_reason" = 'A newer item asks about the same subject.', "updated_at" = now() WHERE "item"."status" = 'open' AND EXISTS (SELECT 1 FROM "junior_inbox_items" AS "newer" WHERE "newer"."status" = 'open' AND "newer"."subject_kind" = "item"."subject_kind" AND "newer"."subject_id" = "item"."subject_id" AND ("newer"."updated_at", "newer"."id") > ("item"."updated_at", "item"."id"));--> statement-breakpoint
|
|
69
|
+
-- junior:bounded-backfill: a snooze of a closed duplicate moves to the item that stays open in any provider tenant, as in `20261126153100_inbox_item_subjects`. It reads only the snoozes of the few duplicates.
|
|
70
|
+
UPDATE "junior_inbox_snoozes" AS "snooze" SET "inbox_item_id" = "move"."open_id" FROM (SELECT DISTINCT ON ("snooze"."user_id", "open"."id") "snooze"."id", "open"."id" AS "open_id" FROM "junior_inbox_snoozes" AS "snooze" JOIN "junior_inbox_items" AS "item" ON "item"."id" = "snooze"."inbox_item_id" JOIN "junior_inbox_items" AS "open" ON "open"."status" = 'open' AND "open"."subject_kind" = "item"."subject_kind" AND "open"."subject_id" = "item"."subject_id" WHERE "snooze"."state" = 'snoozed' AND "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.' AND NOT EXISTS (SELECT 1 FROM "junior_inbox_snoozes" AS "kept" WHERE "kept"."inbox_item_id" = "open"."id" AND "kept"."user_id" = "snooze"."user_id" AND "kept"."state" = 'snoozed') ORDER BY "snooze"."user_id", "open"."id", "snooze"."created_at" DESC) AS "move" WHERE "snooze"."id" = "move"."id";--> statement-breakpoint
|
|
71
|
+
-- junior:bounded-backfill: the assignees of a closed duplicate join the item that stays open, so they keep their ask. It reads only the assignees of the few duplicates. An open item with no assignees asks everyone, so it gets none.
|
|
72
|
+
INSERT INTO "junior_inbox_item_assignees" ("item_id", "user_id") SELECT DISTINCT "open"."id", "assignee"."user_id" FROM "junior_inbox_item_assignees" AS "assignee" JOIN "junior_inbox_items" AS "item" ON "item"."id" = "assignee"."item_id" JOIN "junior_inbox_items" AS "open" ON "open"."status" = 'open' AND "open"."subject_kind" = "item"."subject_kind" AND "open"."subject_id" = "item"."subject_id" WHERE "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.' AND EXISTS (SELECT 1 FROM "junior_inbox_item_assignees" AS "kept" WHERE "kept"."item_id" = "open"."id") ON CONFLICT DO NOTHING;--> statement-breakpoint
|
|
73
|
+
-- junior:bounded-backfill: the sent pushes of a closed duplicate clear, as for any closed item, so the devices close it. It reads only the deliveries of the few duplicates.
|
|
74
|
+
UPDATE "junior_inbox_item_deliveries" AS "delivery" SET "status" = 'cleared', "updated_at" = now() FROM "junior_inbox_items" AS "item" WHERE "item"."id" = "delivery"."item_id" AND "delivery"."status" = 'sent' AND "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "junior_inbox_items_open_subject_key_uidx" ON "junior_inbox_items" USING btree ("subject_kind","subject_id") WHERE "junior_inbox_items"."status" = 'open';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- `junior_inbox_items_open_subject_key_uidx` now keeps one open item per
|
|
2
|
+
-- subject. Reads find the items of an owner through the subject, so the
|
|
3
|
+
-- indexes on `owner_id` and on the provider tenant have no reader.
|
|
4
|
+
DROP INDEX IF EXISTS "junior_inbox_items_open_subject_uidx";--> statement-breakpoint
|
|
5
|
+
DROP INDEX IF EXISTS "junior_inbox_items_owner_idx";--> statement-breakpoint
|
|
6
|
+
DROP INDEX IF EXISTS "junior_inbox_items_open_action_owner_idx";--> statement-breakpoint
|
|
7
|
+
DROP INDEX IF EXISTS "junior_inbox_items_answered_idx";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- This migration does not change the database. The three migrations before
|
|
2
|
+
-- it change `junior_inbox_items` by hand, because the new unique index must
|
|
3
|
+
-- build concurrently after the duplicate open items close. This snapshot
|
|
4
|
+
-- records the schema that they leave, so `drizzle-kit generate` does not
|
|
5
|
+
-- write their changes again. `owner_kind`, `owner_id`, `visibility`,
|
|
6
|
+
-- `provider`, and `provider_tenant_id` stay in the database for one release,
|
|
7
|
+
-- because old workers still write them. The next release drops them with
|
|
8
|
+
-- DROP COLUMN IF EXISTS.
|