@opengeni/db 0.22.2 → 0.26.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.
Files changed (55) hide show
  1. package/dist/{chunk-CYGFLLMN.js → chunk-7WTDI7Y3.js} +764 -283
  2. package/dist/chunk-7WTDI7Y3.js.map +1 -0
  3. package/dist/{chunk-BNGEN5QZ.js → chunk-KW6U54V2.js} +26 -2
  4. package/dist/chunk-KW6U54V2.js.map +1 -0
  5. package/dist/connection-token-resolver.d.ts +24 -2
  6. package/dist/index.d.ts +107 -5
  7. package/dist/index.js +7857 -3898
  8. package/dist/index.js.map +1 -1
  9. package/dist/preference-registry.d.ts +14 -0
  10. package/dist/provision-roles.js +1 -1
  11. package/dist/runtime-posture.d.ts +3 -3
  12. package/dist/schema.d.ts +1659 -77
  13. package/dist/schema.js +13 -1
  14. package/dist/session-control.d.ts +7 -1
  15. package/dist/session-queue-commands.d.ts +8 -0
  16. package/dist/session-realtime-context.d.ts +56 -0
  17. package/dist/session-realtime-ledger.d.ts +188 -0
  18. package/dist/session-realtime-mirror.d.ts +51 -0
  19. package/dist/session-realtime-state.d.ts +2 -0
  20. package/dist/session-realtime-terminal.d.ts +40 -0
  21. package/dist/session-realtime.d.ts +59 -0
  22. package/dist/workspace-instruction-policies-schema.d.ts +307 -0
  23. package/dist/workspace-instruction-policies.d.ts +97 -7
  24. package/drizzle/0156_slack_reaction_trigger.sql +49 -0
  25. package/drizzle/0157_session_policy_role_snapshots.sql +1146 -0
  26. package/drizzle/0158_session_realtime_mode.sql +88 -0
  27. package/drizzle/0159_session_realtime_ledger.sql +198 -0
  28. package/drizzle/0160_session_realtime_delegation_terminal.sql +38 -0
  29. package/drizzle/0161_session_realtime_context_projection.sql +82 -0
  30. package/drizzle/0162_session_realtime_connection_promotion.sql +53 -0
  31. package/drizzle/0163_session_realtime_delegation_progress.sql +35 -0
  32. package/drizzle/0164_session_realtime_models.sql +28 -0
  33. package/drizzle/0165_document_authority_foundation.sql +259 -0
  34. package/drizzle/0166_connection_disconnect_idempotency.sql +49 -0
  35. package/drizzle/0167_document_index_replay_authority.sql +61 -0
  36. package/drizzle/0168_workspace_instruction_policy_operation_receipts.sql +44 -0
  37. package/package.json +4 -4
  38. package/src/connection-token-resolver.ts +79 -16
  39. package/src/index.ts +1033 -101
  40. package/src/preference-registry.ts +114 -6
  41. package/src/provision-roles.ts +12 -0
  42. package/src/runtime-posture.ts +12 -0
  43. package/src/schema.ts +486 -43
  44. package/src/session-control.ts +643 -21
  45. package/src/session-queue-commands.ts +121 -18
  46. package/src/session-realtime-context.ts +393 -0
  47. package/src/session-realtime-ledger.ts +1790 -0
  48. package/src/session-realtime-mirror.ts +276 -0
  49. package/src/session-realtime-state.ts +25 -0
  50. package/src/session-realtime-terminal.ts +306 -0
  51. package/src/session-realtime.ts +659 -0
  52. package/src/workspace-instruction-policies-schema.ts +71 -0
  53. package/src/workspace-instruction-policies.ts +568 -25
  54. package/dist/chunk-BNGEN5QZ.js.map +0 -1
  55. package/dist/chunk-CYGFLLMN.js.map +0 -1
@@ -19,6 +19,40 @@ export declare const workspaceInstructionPolicyRevisions: import("drizzle-orm/pg
19
19
  identity: undefined;
20
20
  generated: undefined;
21
21
  }, {}, {}>;
22
+ operationId: import("drizzle-orm/pg-core").PgColumn<{
23
+ name: "operation_id";
24
+ tableName: "workspace_instruction_policy_revisions";
25
+ dataType: "string";
26
+ columnType: "PgUUID";
27
+ data: string;
28
+ driverParam: string;
29
+ notNull: false;
30
+ hasDefault: false;
31
+ isPrimaryKey: false;
32
+ isAutoincrement: false;
33
+ hasRuntimeDefault: false;
34
+ enumValues: undefined;
35
+ baseColumn: never;
36
+ identity: undefined;
37
+ generated: undefined;
38
+ }, {}, {}>;
39
+ requestFingerprint: import("drizzle-orm/pg-core").PgColumn<{
40
+ name: "request_fingerprint";
41
+ tableName: "workspace_instruction_policy_revisions";
42
+ dataType: "string";
43
+ columnType: "PgText";
44
+ data: string;
45
+ driverParam: string;
46
+ notNull: false;
47
+ hasDefault: false;
48
+ isPrimaryKey: false;
49
+ isAutoincrement: false;
50
+ hasRuntimeDefault: false;
51
+ enumValues: [string, ...string[]];
52
+ baseColumn: never;
53
+ identity: undefined;
54
+ generated: undefined;
55
+ }, {}, {}>;
22
56
  accountId: import("drizzle-orm/pg-core").PgColumn<{
23
57
  name: "account_id";
24
58
  tableName: "workspace_instruction_policy_revisions";
@@ -458,6 +492,40 @@ export declare const workspaceInstructionPolicyActivationEvents: import("drizzle
458
492
  identity: undefined;
459
493
  generated: undefined;
460
494
  }, {}, {}>;
495
+ operationId: import("drizzle-orm/pg-core").PgColumn<{
496
+ name: "operation_id";
497
+ tableName: "workspace_instruction_policy_activation_events";
498
+ dataType: "string";
499
+ columnType: "PgUUID";
500
+ data: string;
501
+ driverParam: string;
502
+ notNull: false;
503
+ hasDefault: false;
504
+ isPrimaryKey: false;
505
+ isAutoincrement: false;
506
+ hasRuntimeDefault: false;
507
+ enumValues: undefined;
508
+ baseColumn: never;
509
+ identity: undefined;
510
+ generated: undefined;
511
+ }, {}, {}>;
512
+ requestFingerprint: import("drizzle-orm/pg-core").PgColumn<{
513
+ name: "request_fingerprint";
514
+ tableName: "workspace_instruction_policy_activation_events";
515
+ dataType: "string";
516
+ columnType: "PgText";
517
+ data: string;
518
+ driverParam: string;
519
+ notNull: false;
520
+ hasDefault: false;
521
+ isPrimaryKey: false;
522
+ isAutoincrement: false;
523
+ hasRuntimeDefault: false;
524
+ enumValues: [string, ...string[]];
525
+ baseColumn: never;
526
+ identity: undefined;
527
+ generated: undefined;
528
+ }, {}, {}>;
461
529
  accountId: import("drizzle-orm/pg-core").PgColumn<{
462
530
  name: "account_id";
463
531
  tableName: "workspace_instruction_policy_activation_events";
@@ -733,3 +801,242 @@ export declare const workspaceInstructionPolicyActivationEvents: import("drizzle
733
801
  };
734
802
  dialect: 'pg';
735
803
  }>;
804
+ export declare const workspaceInstructionPolicySnapshots: import("drizzle-orm/pg-core").PgTableWithColumns<{
805
+ name: "workspace_instruction_policy_snapshots";
806
+ schema: undefined;
807
+ columns: {
808
+ id: import("drizzle-orm/pg-core").PgColumn<{
809
+ name: "id";
810
+ tableName: "workspace_instruction_policy_snapshots";
811
+ dataType: "string";
812
+ columnType: "PgUUID";
813
+ data: string;
814
+ driverParam: string;
815
+ notNull: true;
816
+ hasDefault: true;
817
+ isPrimaryKey: true;
818
+ isAutoincrement: false;
819
+ hasRuntimeDefault: false;
820
+ enumValues: undefined;
821
+ baseColumn: never;
822
+ identity: undefined;
823
+ generated: undefined;
824
+ }, {}, {}>;
825
+ accountId: import("drizzle-orm/pg-core").PgColumn<{
826
+ name: "account_id";
827
+ tableName: "workspace_instruction_policy_snapshots";
828
+ dataType: "string";
829
+ columnType: "PgUUID";
830
+ data: string;
831
+ driverParam: string;
832
+ notNull: true;
833
+ hasDefault: false;
834
+ isPrimaryKey: false;
835
+ isAutoincrement: false;
836
+ hasRuntimeDefault: false;
837
+ enumValues: undefined;
838
+ baseColumn: never;
839
+ identity: undefined;
840
+ generated: undefined;
841
+ }, {}, {}>;
842
+ workspaceId: import("drizzle-orm/pg-core").PgColumn<{
843
+ name: "workspace_id";
844
+ tableName: "workspace_instruction_policy_snapshots";
845
+ dataType: "string";
846
+ columnType: "PgUUID";
847
+ data: string;
848
+ driverParam: string;
849
+ notNull: true;
850
+ hasDefault: false;
851
+ isPrimaryKey: false;
852
+ isAutoincrement: false;
853
+ hasRuntimeDefault: false;
854
+ enumValues: undefined;
855
+ baseColumn: never;
856
+ identity: undefined;
857
+ generated: undefined;
858
+ }, {}, {}>;
859
+ sessionId: import("drizzle-orm/pg-core").PgColumn<{
860
+ name: "session_id";
861
+ tableName: "workspace_instruction_policy_snapshots";
862
+ dataType: "string";
863
+ columnType: "PgUUID";
864
+ data: string;
865
+ driverParam: string;
866
+ notNull: true;
867
+ hasDefault: false;
868
+ isPrimaryKey: false;
869
+ isAutoincrement: false;
870
+ hasRuntimeDefault: false;
871
+ enumValues: undefined;
872
+ baseColumn: never;
873
+ identity: undefined;
874
+ generated: undefined;
875
+ }, {}, {}>;
876
+ turnId: import("drizzle-orm/pg-core").PgColumn<{
877
+ name: "turn_id";
878
+ tableName: "workspace_instruction_policy_snapshots";
879
+ dataType: "string";
880
+ columnType: "PgUUID";
881
+ data: string;
882
+ driverParam: string;
883
+ notNull: true;
884
+ hasDefault: false;
885
+ isPrimaryKey: false;
886
+ isAutoincrement: false;
887
+ hasRuntimeDefault: false;
888
+ enumValues: undefined;
889
+ baseColumn: never;
890
+ identity: undefined;
891
+ generated: undefined;
892
+ }, {}, {}>;
893
+ attemptId: import("drizzle-orm/pg-core").PgColumn<{
894
+ name: "attempt_id";
895
+ tableName: "workspace_instruction_policy_snapshots";
896
+ dataType: "string";
897
+ columnType: "PgUUID";
898
+ data: string;
899
+ driverParam: string;
900
+ notNull: true;
901
+ hasDefault: false;
902
+ isPrimaryKey: false;
903
+ isAutoincrement: false;
904
+ hasRuntimeDefault: false;
905
+ enumValues: undefined;
906
+ baseColumn: never;
907
+ identity: undefined;
908
+ generated: undefined;
909
+ }, {}, {}>;
910
+ executionGeneration: import("drizzle-orm/pg-core").PgColumn<{
911
+ name: "execution_generation";
912
+ tableName: "workspace_instruction_policy_snapshots";
913
+ dataType: "number";
914
+ columnType: "PgInteger";
915
+ data: number;
916
+ driverParam: string | number;
917
+ notNull: true;
918
+ hasDefault: false;
919
+ isPrimaryKey: false;
920
+ isAutoincrement: false;
921
+ hasRuntimeDefault: false;
922
+ enumValues: undefined;
923
+ baseColumn: never;
924
+ identity: undefined;
925
+ generated: undefined;
926
+ }, {}, {}>;
927
+ policyRole: import("drizzle-orm/pg-core").PgColumn<{
928
+ name: "policy_role";
929
+ tableName: "workspace_instruction_policy_snapshots";
930
+ dataType: "string";
931
+ columnType: "PgText";
932
+ data: string;
933
+ driverParam: string;
934
+ notNull: false;
935
+ hasDefault: false;
936
+ isPrimaryKey: false;
937
+ isAutoincrement: false;
938
+ hasRuntimeDefault: false;
939
+ enumValues: [string, ...string[]];
940
+ baseColumn: never;
941
+ identity: undefined;
942
+ generated: undefined;
943
+ }, {}, {}>;
944
+ roleSource: import("drizzle-orm/pg-core").PgColumn<{
945
+ name: "role_source";
946
+ tableName: "workspace_instruction_policy_snapshots";
947
+ dataType: "string";
948
+ columnType: "PgText";
949
+ data: string;
950
+ driverParam: string;
951
+ notNull: true;
952
+ hasDefault: false;
953
+ isPrimaryKey: false;
954
+ isAutoincrement: false;
955
+ hasRuntimeDefault: false;
956
+ enumValues: [string, ...string[]];
957
+ baseColumn: never;
958
+ identity: undefined;
959
+ generated: undefined;
960
+ }, {}, {}>;
961
+ entries: import("drizzle-orm/pg-core").PgColumn<{
962
+ name: "entries";
963
+ tableName: "workspace_instruction_policy_snapshots";
964
+ dataType: "json";
965
+ columnType: "PgJsonb";
966
+ data: {
967
+ kind: "charter" | "policy";
968
+ scope: "global" | "role";
969
+ roleKey: string | null;
970
+ revisionId: string;
971
+ revision: number;
972
+ contentHash: string;
973
+ activationVersion: number;
974
+ activatedAt: string;
975
+ provenance: {
976
+ source: "human" | "knowledge_proposal" | "legacy_import" | "onboarding";
977
+ sourceIdHash: string | null;
978
+ };
979
+ }[];
980
+ driverParam: unknown;
981
+ notNull: true;
982
+ hasDefault: false;
983
+ isPrimaryKey: false;
984
+ isAutoincrement: false;
985
+ hasRuntimeDefault: false;
986
+ enumValues: undefined;
987
+ baseColumn: never;
988
+ identity: undefined;
989
+ generated: undefined;
990
+ }, {}, {
991
+ $type: {
992
+ kind: "charter" | "policy";
993
+ scope: "global" | "role";
994
+ roleKey: string | null;
995
+ revisionId: string;
996
+ revision: number;
997
+ contentHash: string;
998
+ activationVersion: number;
999
+ activatedAt: string;
1000
+ provenance: {
1001
+ source: "human" | "knowledge_proposal" | "legacy_import" | "onboarding";
1002
+ sourceIdHash: string | null;
1003
+ };
1004
+ }[];
1005
+ }>;
1006
+ entryHash: import("drizzle-orm/pg-core").PgColumn<{
1007
+ name: "entry_hash";
1008
+ tableName: "workspace_instruction_policy_snapshots";
1009
+ dataType: "string";
1010
+ columnType: "PgText";
1011
+ data: string;
1012
+ driverParam: string;
1013
+ notNull: true;
1014
+ hasDefault: false;
1015
+ isPrimaryKey: false;
1016
+ isAutoincrement: false;
1017
+ hasRuntimeDefault: false;
1018
+ enumValues: [string, ...string[]];
1019
+ baseColumn: never;
1020
+ identity: undefined;
1021
+ generated: undefined;
1022
+ }, {}, {}>;
1023
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
1024
+ name: "created_at";
1025
+ tableName: "workspace_instruction_policy_snapshots";
1026
+ dataType: "date";
1027
+ columnType: "PgTimestamp";
1028
+ data: Date;
1029
+ driverParam: string;
1030
+ notNull: true;
1031
+ hasDefault: true;
1032
+ isPrimaryKey: false;
1033
+ isAutoincrement: false;
1034
+ hasRuntimeDefault: false;
1035
+ enumValues: undefined;
1036
+ baseColumn: never;
1037
+ identity: undefined;
1038
+ generated: undefined;
1039
+ }, {}, {}>;
1040
+ };
1041
+ dialect: 'pg';
1042
+ }>;
@@ -1,6 +1,8 @@
1
+ import { WorkspaceInstructionPolicySnapshot } from "@opengeni/contracts";
1
2
  import type { WorkspaceInstructionPolicyActivationResponse, WorkspaceInstructionPolicyDiffResponse, WorkspaceInstructionPolicyDraftProvenanceSource, WorkspaceInstructionPolicyHead, WorkspaceInstructionPolicyListQuery, WorkspaceInstructionPolicyListResponse, WorkspaceInstructionPolicyProvenanceSource, WorkspaceInstructionPolicyRevision, WorkspaceInstructionPolicyTarget } from "@opengeni/contracts";
2
3
  import type { Database } from "./index";
3
- type DraftInput = WorkspaceInstructionPolicyTarget & {
4
+ type DraftRequestInput = WorkspaceInstructionPolicyTarget & {
5
+ operationId: string;
4
6
  accountId: string;
5
7
  workspaceId: string;
6
8
  content: string;
@@ -9,15 +11,28 @@ type DraftInput = WorkspaceInstructionPolicyTarget & {
9
11
  supersedesRevisionId: string | null;
10
12
  createdBySubjectId: string;
11
13
  };
12
- type CallerDraftInput = Omit<DraftInput, "provenanceSource"> & {
14
+ type CallerDraftInput = Omit<DraftRequestInput, "operationId" | "provenanceSource"> & {
15
+ operationId?: string;
13
16
  provenanceSource: WorkspaceInstructionPolicyDraftProvenanceSource;
14
17
  };
18
+ type ImportLegacyRequestInput = {
19
+ operationId: string;
20
+ accountId: string;
21
+ workspaceId: string;
22
+ createdBySubjectId: string;
23
+ supersedesRevisionId: string | null;
24
+ };
15
25
  export declare class WorkspaceInstructionPolicyConflictError extends Error {
16
26
  readonly currentHead: WorkspaceInstructionPolicyHead | null;
17
27
  readonly name = "WorkspaceInstructionPolicyConflictError";
18
28
  readonly code = "WORKSPACE_INSTRUCTION_POLICY_CONFLICT";
19
29
  constructor(currentHead: WorkspaceInstructionPolicyHead | null);
20
30
  }
31
+ export declare class WorkspaceInstructionPolicyOperationReuseError extends Error {
32
+ readonly name = "WorkspaceInstructionPolicyOperationReuseError";
33
+ readonly code = "WORKSPACE_INSTRUCTION_POLICY_OPERATION_REUSED";
34
+ constructor();
35
+ }
21
36
  export declare class WorkspaceInstructionPolicyNotFoundError extends Error {
22
37
  readonly name = "WorkspaceInstructionPolicyNotFoundError";
23
38
  constructor(message?: string);
@@ -29,13 +44,51 @@ export declare class WorkspaceInstructionPolicyLegacyUnavailableError extends Er
29
44
  readonly name = "WorkspaceInstructionPolicyLegacyUnavailableError";
30
45
  constructor();
31
46
  }
32
- export declare function createWorkspaceInstructionPolicyDraft(db: Database, input: CallerDraftInput): Promise<WorkspaceInstructionPolicyRevision>;
33
- /** Import only the stored legacy override; never materialize a deployment default or activate it. */
34
- export declare function importLegacyWorkspaceInstructionPolicyDraft(db: Database, input: {
47
+ export declare class WorkspaceInstructionPolicySnapshotAuthorityError extends Error {
48
+ readonly name = "WorkspaceInstructionPolicySnapshotAuthorityError";
49
+ }
50
+ export type WorkspaceInstructionPolicyAttemptClaims = {
35
51
  accountId: string;
36
52
  workspaceId: string;
37
- createdBySubjectId: string;
38
- supersedesRevisionId: string | null;
53
+ sessionId: string;
54
+ turnId: string;
55
+ attemptId: string;
56
+ executionGeneration: number;
57
+ };
58
+ export type WorkspaceStateAcceptedAttemptGovernance = {
59
+ attemptId: string;
60
+ executionGeneration: number;
61
+ acceptedAt: string;
62
+ policySnapshot: WorkspaceInstructionPolicySnapshot | null;
63
+ preferenceSnapshot: {
64
+ id: string;
65
+ descriptorHash: string;
66
+ descriptors: Array<{
67
+ id: string;
68
+ revisionId: string;
69
+ contentHash: string;
70
+ activeVersion: number;
71
+ scope: "organization" | "workspace" | "user";
72
+ }>;
73
+ truncated: boolean;
74
+ createdAt: string;
75
+ } | null;
76
+ };
77
+ /**
78
+ * Inspect one immutable accepted attempt only when the authenticated caller is
79
+ * exactly its frozen initiating human. The null result deliberately conflates
80
+ * absence, cross-account/workspace lookup, and another subject's attempt.
81
+ */
82
+ export declare function getWorkspaceStateAcceptedAttemptGovernance(db: Database, input: {
83
+ accountId: string;
84
+ workspaceId: string;
85
+ subjectId: string;
86
+ attemptId: string;
87
+ }): Promise<WorkspaceStateAcceptedAttemptGovernance | null>;
88
+ export declare function createWorkspaceInstructionPolicyDraft(db: Database, input: CallerDraftInput): Promise<WorkspaceInstructionPolicyRevision>;
89
+ /** Import only the stored legacy override; never materialize a deployment default or activate it. */
90
+ export declare function importLegacyWorkspaceInstructionPolicyDraft(db: Database, input: Omit<ImportLegacyRequestInput, "operationId"> & {
91
+ operationId?: string;
39
92
  }): Promise<WorkspaceInstructionPolicyRevision>;
40
93
  export declare function listWorkspaceInstructionPolicyRevisions(db: Database, workspaceId: string, query: WorkspaceInstructionPolicyListQuery): Promise<WorkspaceInstructionPolicyListResponse>;
41
94
  export declare function getWorkspaceInstructionPolicyRevision(db: Database, workspaceId: string, revisionId: string): Promise<WorkspaceInstructionPolicyRevision>;
@@ -46,19 +99,56 @@ export declare function diffWorkspaceInstructionPolicyRevisions(db: Database, wo
46
99
  toRevisionId: string;
47
100
  }): Promise<WorkspaceInstructionPolicyDiffResponse>;
48
101
  export declare function activateWorkspaceInstructionPolicyRevision(db: Database, input: {
102
+ operationId?: string;
49
103
  accountId: string;
50
104
  workspaceId: string;
51
105
  revisionId: string;
52
106
  expectedCurrentRevisionId: string | null;
107
+ expectedActivationVersion?: number;
53
108
  actorSubjectId: string;
54
109
  reason: string;
55
110
  }): Promise<WorkspaceInstructionPolicyActivationResponse>;
56
111
  export declare function rollbackWorkspaceInstructionPolicyRevision(db: Database, input: {
112
+ operationId?: string;
57
113
  accountId: string;
58
114
  workspaceId: string;
59
115
  targetRevisionId: string;
60
116
  expectedCurrentRevisionId: string;
117
+ expectedActivationVersion?: number;
61
118
  actorSubjectId: string;
62
119
  reason: string;
63
120
  }): Promise<WorkspaceInstructionPolicyActivationResponse>;
121
+ /**
122
+ * Freeze (or replay) the exact active charter/global/role policy set for one
123
+ * accepted attempt, then resolve only those immutable revisions. The snapshot
124
+ * stores bounded descriptors/hashes; full policy text remains in the revision
125
+ * table and cannot be widened by a later head activation.
126
+ */
127
+ export declare function getOrCreateWorkspaceInstructionPolicySnapshot(db: Database, claims: WorkspaceInstructionPolicyAttemptClaims): Promise<{
128
+ id: string;
129
+ workspaceId: string;
130
+ sessionId: string;
131
+ turnId: string;
132
+ attemptId: string;
133
+ executionGeneration: number;
134
+ policyRole: string | null;
135
+ roleSource: "invalid_metadata_fallback" | "metadata_fallback" | "none" | "session_binding";
136
+ entryHash: string;
137
+ createdAt: string;
138
+ entries: {
139
+ kind: "charter" | "policy";
140
+ scope: "global" | "role";
141
+ roleKey: string | null;
142
+ revisionId: string;
143
+ revision: number;
144
+ contentHash: string;
145
+ activationVersion: number;
146
+ activatedAt: string;
147
+ provenance: {
148
+ source: "human" | "knowledge_proposal" | "legacy_import" | "onboarding";
149
+ sourceIdHash: string | null;
150
+ };
151
+ content: string;
152
+ }[];
153
+ }>;
64
154
  export {};
@@ -0,0 +1,49 @@
1
+ -- deployment-mode: rolling
2
+ -- Admit the optional Slack emoji-reaction summon source into the existing
3
+ -- durable interaction inbox. Older writers use only the existing subset, so
4
+ -- this CHECK expansion is mixed-version compatible.
5
+
6
+ SET LOCAL lock_timeout = '5s';
7
+ SET LOCAL statement_timeout = '10min';
8
+
9
+ ALTER TABLE "slack_interaction_inbox"
10
+ DROP CONSTRAINT "slack_interaction_inbox_trigger_check";
11
+
12
+ ALTER TABLE "slack_interaction_inbox"
13
+ ADD CONSTRAINT "slack_interaction_inbox_trigger_check"
14
+ CHECK (
15
+ "trigger_kind" IN (
16
+ 'app_mention',
17
+ 'dm',
18
+ 'reaction',
19
+ 'slash_command',
20
+ 'message_shortcut',
21
+ 'thread_reply'
22
+ )
23
+ ) NOT VALID;
24
+
25
+ ALTER TABLE "slack_interaction_inbox"
26
+ VALIDATE CONSTRAINT "slack_interaction_inbox_trigger_check";
27
+
28
+ -- A rate-limited conversations.replies traversal must resume at the exact next
29
+ -- cursor instead of consuming the next one-request-per-minute allowance by
30
+ -- refetching page one. The payload is application-authenticated and bounded;
31
+ -- this database constraint additionally prevents terminal/non-reaction rows
32
+ -- from retaining checkpoint material.
33
+ ALTER TABLE "slack_interaction_inbox"
34
+ ADD COLUMN "reaction_context_checkpoint" jsonb;
35
+
36
+ ALTER TABLE "slack_interaction_inbox"
37
+ ADD CONSTRAINT "slack_interaction_inbox_reaction_checkpoint_check"
38
+ CHECK (
39
+ "reaction_context_checkpoint" IS NULL
40
+ OR (
41
+ "trigger_kind" = 'reaction'
42
+ AND "status" IN ('pending', 'processing')
43
+ AND jsonb_typeof("reaction_context_checkpoint") = 'object'
44
+ AND octet_length("reaction_context_checkpoint"::text) <= 131072
45
+ )
46
+ ) NOT VALID;
47
+
48
+ ALTER TABLE "slack_interaction_inbox"
49
+ VALIDATE CONSTRAINT "slack_interaction_inbox_reaction_checkpoint_check";