@headless-lms/adapter-db 0.2.0 → 0.4.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 (134) hide show
  1. package/dist/index.d.ts +12 -6
  2. package/dist/index.js +12 -6
  3. package/dist/repositories/admin.d.ts +23 -0
  4. package/dist/repositories/admin.js +393 -0
  5. package/dist/repositories/admin.js.map +1 -0
  6. package/dist/repositories/assets.d.ts +6 -3
  7. package/dist/repositories/assets.js +46 -9
  8. package/dist/repositories/assets.js.map +1 -1
  9. package/dist/repositories/automations.d.ts +5 -2
  10. package/dist/repositories/automations.js +29 -2
  11. package/dist/repositories/automations.js.map +1 -1
  12. package/dist/repositories/chats.d.ts +55 -0
  13. package/dist/repositories/chats.js +469 -0
  14. package/dist/repositories/chats.js.map +1 -0
  15. package/dist/repositories/content.d.ts +24 -1
  16. package/dist/repositories/content.js +316 -9
  17. package/dist/repositories/content.js.map +1 -1
  18. package/dist/repositories/devices.d.ts +17 -0
  19. package/dist/repositories/devices.js +75 -0
  20. package/dist/repositories/devices.js.map +1 -0
  21. package/dist/repositories/digest-runs.d.ts +14 -0
  22. package/dist/repositories/digest-runs.js +39 -0
  23. package/dist/repositories/digest-runs.js.map +1 -0
  24. package/dist/repositories/discussion.d.ts +16 -4
  25. package/dist/repositories/discussion.js +78 -18
  26. package/dist/repositories/discussion.js.map +1 -1
  27. package/dist/repositories/entitlements.d.ts +31 -9
  28. package/dist/repositories/entitlements.js +213 -17
  29. package/dist/repositories/entitlements.js.map +1 -1
  30. package/dist/repositories/grant-covers.d.ts +20 -0
  31. package/dist/repositories/grant-covers.js +55 -0
  32. package/dist/repositories/grant-covers.js.map +1 -0
  33. package/dist/repositories/identity.d.ts +4 -2
  34. package/dist/repositories/identity.js +32 -1
  35. package/dist/repositories/identity.js.map +1 -1
  36. package/dist/repositories/inserted-row.d.ts +5 -0
  37. package/dist/repositories/inserted-row.js +7 -0
  38. package/dist/repositories/inserted-row.js.map +1 -0
  39. package/dist/repositories/member.d.ts +16 -0
  40. package/dist/repositories/member.js +63 -0
  41. package/dist/repositories/member.js.map +1 -0
  42. package/dist/repositories/members.js +2 -2
  43. package/dist/repositories/members.js.map +1 -1
  44. package/dist/repositories/mentions.d.ts +17 -0
  45. package/dist/repositories/mentions.js +55 -0
  46. package/dist/repositories/mentions.js.map +1 -0
  47. package/dist/repositories/notification-settings.d.ts +19 -0
  48. package/dist/repositories/notification-settings.js +67 -0
  49. package/dist/repositories/notification-settings.js.map +1 -0
  50. package/dist/repositories/notifications.d.ts +30 -0
  51. package/dist/repositories/notifications.js +178 -0
  52. package/dist/repositories/notifications.js.map +1 -0
  53. package/dist/repositories/org-user-profile.d.ts +214 -1
  54. package/dist/repositories/org-user-profile.js +23 -2
  55. package/dist/repositories/org-user-profile.js.map +1 -1
  56. package/dist/repositories/organizations.d.ts +4 -2
  57. package/dist/repositories/organizations.js +23 -8
  58. package/dist/repositories/organizations.js.map +1 -1
  59. package/dist/repositories/pg-errors.js +3 -1
  60. package/dist/repositories/pg-errors.js.map +1 -1
  61. package/dist/repositories/posts.d.ts +35 -0
  62. package/dist/repositories/posts.js +252 -0
  63. package/dist/repositories/posts.js.map +1 -0
  64. package/dist/repositories/subscriptions.d.ts +18 -0
  65. package/dist/repositories/subscriptions.js +72 -0
  66. package/dist/repositories/subscriptions.js.map +1 -0
  67. package/dist/schema/assets.d.ts +19 -2
  68. package/dist/schema/assets.js +10 -4
  69. package/dist/schema/assets.js.map +1 -1
  70. package/dist/schema/automations.d.ts +545 -2
  71. package/dist/schema/automations.js +73 -3
  72. package/dist/schema/automations.js.map +1 -1
  73. package/dist/schema/better-auth.d.ts +1613 -238
  74. package/dist/schema/better-auth.js +107 -22
  75. package/dist/schema/better-auth.js.map +1 -1
  76. package/dist/schema/content.d.ts +642 -5
  77. package/dist/schema/content.js +119 -10
  78. package/dist/schema/content.js.map +1 -1
  79. package/dist/schema/discussion.d.ts +2182 -42
  80. package/dist/schema/discussion.js +461 -11
  81. package/dist/schema/discussion.js.map +1 -1
  82. package/dist/schema/entitlements.d.ts +432 -1
  83. package/dist/schema/entitlements.js +109 -4
  84. package/dist/schema/entitlements.js.map +1 -1
  85. package/dist/schema/identity.d.ts +517 -1
  86. package/dist/schema/identity.js +76 -2
  87. package/dist/schema/identity.js.map +1 -1
  88. package/dist/schema/index.d.ts +7 -7
  89. package/dist/schema/index.js +35 -8
  90. package/dist/schema/organizations.d.ts +4 -4
  91. package/dist/schema/organizations.js +2 -0
  92. package/dist/schema/organizations.js.map +1 -1
  93. package/drizzle/0003_community.sql +340 -0
  94. package/drizzle/0004_assets_sources.sql +1 -0
  95. package/drizzle/0005_notices_and_seed_index.sql +12 -0
  96. package/drizzle/0006_community_review_fixes.sql +24 -0
  97. package/drizzle/0007_notifications.sql +37 -0
  98. package/drizzle/0008_content_access.sql +13 -0
  99. package/drizzle/0009_community_indexes.sql +56 -0
  100. package/drizzle/0010_mcp_access.sql +114 -0
  101. package/drizzle/0011_digest_runs.sql +8 -0
  102. package/drizzle/0012_subscriptions.sql +16 -0
  103. package/drizzle/0013_mentions.sql +10 -0
  104. package/drizzle/0014_notification_settings_devices.sql +36 -0
  105. package/drizzle/0015_automations_drop_source.sql +2 -0
  106. package/drizzle/0016_notifications_automations.sql +48 -0
  107. package/drizzle/meta/0003_snapshot.json +7061 -0
  108. package/drizzle/meta/0004_snapshot.json +7068 -0
  109. package/drizzle/meta/0005_snapshot.json +7180 -0
  110. package/drizzle/meta/0006_snapshot.json +7298 -0
  111. package/drizzle/meta/0007_snapshot.json +7620 -0
  112. package/drizzle/meta/0008_snapshot.json +7666 -0
  113. package/drizzle/meta/0009_snapshot.json +8185 -0
  114. package/drizzle/meta/0010_snapshot.json +8813 -0
  115. package/drizzle/meta/0011_snapshot.json +8868 -0
  116. package/drizzle/meta/0012_snapshot.json +8873 -0
  117. package/drizzle/meta/0013_snapshot.json +8943 -0
  118. package/drizzle/meta/0014_snapshot.json +9305 -0
  119. package/drizzle/meta/0015_snapshot.json +9270 -0
  120. package/drizzle/meta/0016_snapshot.json +9230 -0
  121. package/drizzle/meta/_journal.json +99 -1
  122. package/package.json +2 -2
  123. package/dist/repositories/course-analytics.d.ts +0 -15
  124. package/dist/repositories/course-analytics.js +0 -137
  125. package/dist/repositories/course-analytics.js.map +0 -1
  126. package/dist/repositories/dashboard.d.ts +0 -14
  127. package/dist/repositories/dashboard.js +0 -57
  128. package/dist/repositories/dashboard.js.map +0 -1
  129. package/dist/repositories/learn.d.ts +0 -19
  130. package/dist/repositories/learn.js +0 -56
  131. package/dist/repositories/learn.js.map +0 -1
  132. package/dist/repositories/students.d.ts +0 -16
  133. package/dist/repositories/students.js +0 -160
  134. package/dist/repositories/students.js.map +0 -1
@@ -1,5 +1,7 @@
1
- import { organizations } from "./organizations.js";
2
- import { boolean, index, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
1
+ import { communities, spaces } from "./content.js";
2
+ import { orgUsers, organizations } from "./organizations.js";
3
+ import { desc, sql } from "drizzle-orm";
4
+ import { boolean, foreignKey, index, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
3
5
  import { genId } from "@headless-lms/core/shared/id";
4
6
  //#region src/schema/automations.ts
5
7
  const automations = pgTable("automations", {
@@ -11,6 +13,7 @@ const automations = pgTable("automations", {
11
13
  triggers: text("triggers").array().notNull(),
12
14
  actions: jsonb("actions").$type().notNull(),
13
15
  enabled: boolean("enabled").notNull().default(true),
16
+ filter: jsonb("filter").$type(),
14
17
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
15
18
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
16
19
  }, (t) => ({
@@ -39,7 +42,74 @@ const automationRuns = pgTable("automation_runs", {
39
42
  automationIdx: index("automation_runs_org_automation_idx").on(t.orgId, t.automationId),
40
43
  eventDedupeIdx: uniqueIndex("automation_runs_org_automation_event_idx").on(t.orgId, t.automationId, t.eventId)
41
44
  }));
45
+ const notifications = pgTable("notifications", {
46
+ orgId: text("org_id").notNull(),
47
+ id: text("id").notNull().$defaultFn(() => genId("notification")),
48
+ userId: text("user_id").notNull(),
49
+ sourceEventId: text("source_event_id"),
50
+ type: text("type").notNull(),
51
+ scope: text("scope", { enum: [
52
+ "org",
53
+ "community",
54
+ "space",
55
+ "chat"
56
+ ] }).notNull(),
57
+ reasons: text("reasons").array().$type().notNull(),
58
+ matchedReason: text("matched_reason").$type().notNull(),
59
+ category: text("category").notNull(),
60
+ communityId: text("community_id"),
61
+ spaceId: text("space_id"),
62
+ actorOrgUserId: text("actor_org_user_id"),
63
+ subjectType: text("subject_type"),
64
+ subjectId: text("subject_id"),
65
+ parentType: text("parent_type"),
66
+ parentId: text("parent_id"),
67
+ display: jsonb("display").$type().notNull(),
68
+ inApp: boolean("in_app").notNull(),
69
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
70
+ readAt: timestamp("read_at", { withTimezone: true })
71
+ }, (t) => ({
72
+ pk: primaryKey({ columns: [t.orgId, t.id] }),
73
+ userFk: foreignKey({
74
+ columns: [t.orgId, t.userId],
75
+ foreignColumns: [orgUsers.orgId, orgUsers.userId]
76
+ }).onDelete("cascade"),
77
+ communityFk: foreignKey({
78
+ columns: [t.orgId, t.communityId],
79
+ foreignColumns: [communities.orgId, communities.id]
80
+ }).onDelete("cascade"),
81
+ spaceFk: foreignKey({
82
+ columns: [t.orgId, t.spaceId],
83
+ foreignColumns: [spaces.orgId, spaces.id]
84
+ }).onDelete("cascade"),
85
+ sourceIdx: uniqueIndex("notifications_source_event_idx").on(t.orgId, t.sourceEventId, t.userId, sql`coalesce(${t.communityId}, '')`).where(sql`${t.sourceEventId} is not null`),
86
+ listIdx: index("notifications_list_idx").on(t.orgId, t.userId, desc(t.createdAt), desc(t.id)).where(sql`${t.inApp}`),
87
+ communityIdx: index("notifications_community_idx").on(t.orgId, t.userId, t.communityId),
88
+ categoryIdx: index("notifications_category_idx").on(t.orgId, t.userId, t.category),
89
+ reasonsIdx: index("notifications_reasons_idx").using("gin", t.reasons)
90
+ }));
91
+ const notificationDeliveries = pgTable("notification_deliveries", {
92
+ orgId: text("org_id").notNull(),
93
+ id: text("id").notNull().$defaultFn(() => genId("notificationDelivery")),
94
+ notificationId: text("notification_id").notNull(),
95
+ channel: text("channel").notNull(),
96
+ status: text("status", { enum: [
97
+ "pending",
98
+ "sent",
99
+ "failed"
100
+ ] }).notNull().default("pending"),
101
+ lastError: text("last_error"),
102
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
103
+ sentAt: timestamp("sent_at", { withTimezone: true })
104
+ }, (t) => ({
105
+ pk: primaryKey({ columns: [t.orgId, t.id] }),
106
+ notificationFk: foreignKey({
107
+ columns: [t.orgId, t.notificationId],
108
+ foreignColumns: [notifications.orgId, notifications.id]
109
+ }).onDelete("cascade"),
110
+ channelIdx: uniqueIndex("notification_deliveries_channel_idx").on(t.orgId, t.notificationId, t.channel)
111
+ }));
42
112
  //#endregion
43
- export { automationRuns, automations };
113
+ export { automationRuns, automations, notificationDeliveries, notifications };
44
114
 
45
115
  //# sourceMappingURL=automations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"automations.js","names":[],"sources":["../../src/schema/automations.ts"],"sourcesContent":["// automations tables — org-scoped automation definitions and their run\n// history. `automations.actions` and `automation_runs.action_results` are\n// ordered jsonb blobs (contract types owned by @headless-lms/core/types); a run's\n// `event` is the triggering DomainEvent snapshot, stored verbatim.\nimport {\n pgTable,\n text,\n boolean,\n jsonb,\n timestamp,\n primaryKey,\n index,\n uniqueIndex,\n} from \"drizzle-orm/pg-core\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { organizations } from \"./organizations.js\";\nimport type {\n Automation,\n AutomationAction,\n AutomationActionResult,\n AutomationRun,\n} from \"@headless-lms/core/schemas\";\nimport type { DomainEvent } from \"@headless-lms/core/shared/ports\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const automations = pgTable(\n \"automations\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"automation\")),\n name: text(\"name\").notNull(),\n kind: text(\"kind\", { enum: [\"workflow\", \"webhook\"] })\n .notNull()\n .default(\"workflow\"),\n description: text(\"description\"),\n triggers: text(\"triggers\").array().notNull(),\n actions: jsonb(\"actions\").$type<AutomationAction[]>().notNull(),\n enabled: boolean(\"enabled\").notNull().default(true),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n triggersIdx: index(\"automations_triggers_idx\").using(\"gin\", t.triggers),\n }),\n);\n\nexport const automationRuns = pgTable(\n \"automation_runs\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"automationRun\")),\n automationId: text(\"automation_id\").notNull(),\n trigger: text(\"trigger\").notNull(),\n // At-least-once dedupe key for the triggering event; DB-internal, not part of the domain `AutomationRun` type.\n eventId: text(\"event_id\").notNull(),\n event: jsonb(\"event\").$type<DomainEvent>().notNull(),\n status: text(\"status\", { enum: [\"running\", \"completed\", \"failed\"] }).notNull(),\n actionResults: jsonb(\"action_results\").$type<AutomationActionResult[]>().notNull().default([]),\n startedAt: timestamp(\"started_at\", { withTimezone: true }).notNull(),\n finishedAt: timestamp(\"finished_at\", { withTimezone: true }),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n automationIdx: index(\"automation_runs_org_automation_idx\").on(t.orgId, t.automationId),\n eventDedupeIdx: uniqueIndex(\"automation_runs_org_automation_event_idx\").on(\n t.orgId,\n t.automationId,\n t.eventId,\n ),\n }),\n);\n\ntype _AutomationsDrift = Expect<NoDrift<typeof automations.$inferSelect, Automation>>;\ntype _AutomationRunsDrift = Expect<NoDrift<typeof automationRuns.$inferSelect, AutomationRun>>;\n"],"mappings":";;;;AAyBA,MAAa,cAAc,QACzB,eACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAClB,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,IAAI,KAAK,IAAI,CAAC,CACX,QAAQ,CAAC,CACT,iBAAiB,MAAM,YAAY,CAAC;CACvC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,MAAM,KAAK,QAAQ,EAAE,MAAM,CAAC,YAAY,SAAS,EAAE,CAAC,CAAC,CAClD,QAAQ,CAAC,CACT,QAAQ,UAAU;CACrB,aAAa,KAAK,aAAa;CAC/B,UAAU,KAAK,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ;CAC3C,SAAS,MAAM,SAAS,CAAC,CAAC,MAA0B,CAAC,CAAC,QAAQ;CAC9D,SAAS,QAAQ,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,IAAI;CAClD,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAC3C,aAAa,MAAM,0BAA0B,CAAC,CAAC,MAAM,OAAO,EAAE,QAAQ;AACxE,EACF;AAEA,MAAa,iBAAiB,QAC5B,mBACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAClB,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,IAAI,KAAK,IAAI,CAAC,CACX,QAAQ,CAAC,CACT,iBAAiB,MAAM,eAAe,CAAC;CAC1C,cAAc,KAAK,eAAe,CAAC,CAAC,QAAQ;CAC5C,SAAS,KAAK,SAAS,CAAC,CAAC,QAAQ;CAEjC,SAAS,KAAK,UAAU,CAAC,CAAC,QAAQ;CAClC,OAAO,MAAM,OAAO,CAAC,CAAC,MAAmB,CAAC,CAAC,QAAQ;CACnD,QAAQ,KAAK,UAAU,EAAE,MAAM;EAAC;EAAW;EAAa;CAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ;CAC7E,eAAe,MAAM,gBAAgB,CAAC,CAAC,MAAgC,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;CAC7F,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ;CACnE,YAAY,UAAU,eAAe,EAAE,cAAc,KAAK,CAAC;CAC3D,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,WAAW;CAChF,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,CAAC,CACvD,QAAQ,CAAC,CACT,WAAW,CAAC,CACZ,gCAAgB,IAAI,KAAK,CAAC;AAC/B,IACC,OAAO;CACN,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;CAC3C,eAAe,MAAM,oCAAoC,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY;CACrF,gBAAgB,YAAY,0CAA0C,CAAC,CAAC,GACtE,EAAE,OACF,EAAE,cACF,EAAE,OACJ;AACF,EACF"}
1
+ {"version":3,"file":"automations.js","names":[],"sources":["../../src/schema/automations.ts"],"sourcesContent":["// automations tables — org-scoped automation definitions and their run\n// history. `automations.actions` and `automation_runs.action_results` are\n// ordered jsonb blobs (contract types owned by @headless-lms/core/types); a run's\n// `event` is the triggering DomainEvent snapshot, stored verbatim.\nimport {\n pgTable,\n text,\n boolean,\n jsonb,\n timestamp,\n primaryKey,\n foreignKey,\n index,\n uniqueIndex,\n} from \"drizzle-orm/pg-core\";\nimport { desc, sql } from \"drizzle-orm\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { organizations, orgUsers } from \"./organizations.js\";\nimport { communities, spaces } from \"./content.js\";\nimport type {\n Automation,\n AutomationAction,\n AutomationActionResult,\n AutomationRun,\n} from \"@headless-lms/core/schemas\";\nimport type { DomainEvent, JsonValue } from \"@headless-lms/core/shared/ports\";\nimport type { Reason } from \"@headless-lms/core/types\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const automations = pgTable(\n \"automations\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"automation\")),\n name: text(\"name\").notNull(),\n kind: text(\"kind\", { enum: [\"workflow\", \"webhook\"] })\n .notNull()\n .default(\"workflow\"),\n description: text(\"description\"),\n triggers: text(\"triggers\").array().notNull(),\n actions: jsonb(\"actions\").$type<AutomationAction[]>().notNull(),\n enabled: boolean(\"enabled\").notNull().default(true),\n filter: jsonb(\"filter\").$type<Automation[\"filter\"]>(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n triggersIdx: index(\"automations_triggers_idx\").using(\"gin\", t.triggers),\n }),\n);\n\nexport const automationRuns = pgTable(\n \"automation_runs\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"automationRun\")),\n automationId: text(\"automation_id\").notNull(),\n trigger: text(\"trigger\").notNull(),\n // At-least-once dedupe key for the triggering event; DB-internal, not part of the domain `AutomationRun` type.\n eventId: text(\"event_id\").notNull(),\n event: jsonb(\"event\").$type<DomainEvent>().notNull(),\n status: text(\"status\", { enum: [\"running\", \"completed\", \"failed\"] }).notNull(),\n actionResults: jsonb(\"action_results\").$type<AutomationActionResult[]>().notNull().default([]),\n startedAt: timestamp(\"started_at\", { withTimezone: true }).notNull(),\n finishedAt: timestamp(\"finished_at\", { withTimezone: true }),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true })\n .notNull()\n .defaultNow()\n .$onUpdate(() => new Date()),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n automationIdx: index(\"automation_runs_org_automation_idx\").on(t.orgId, t.automationId),\n eventDedupeIdx: uniqueIndex(\"automation_runs_org_automation_event_idx\").on(\n t.orgId,\n t.automationId,\n t.eventId,\n ),\n }),\n);\n\nexport const notifications = pgTable(\n \"notifications\",\n {\n orgId: text(\"org_id\").notNull(),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"notification\")),\n userId: text(\"user_id\").notNull(),\n sourceEventId: text(\"source_event_id\"),\n type: text(\"type\").notNull(),\n scope: text(\"scope\", { enum: [\"org\", \"community\", \"space\", \"chat\"] }).notNull(),\n reasons: text(\"reasons\").array().$type<Reason[]>().notNull(),\n matchedReason: text(\"matched_reason\").$type<Reason>().notNull(),\n category: text(\"category\").notNull(),\n communityId: text(\"community_id\"),\n spaceId: text(\"space_id\"),\n actorOrgUserId: text(\"actor_org_user_id\"),\n subjectType: text(\"subject_type\"),\n subjectId: text(\"subject_id\"),\n parentType: text(\"parent_type\"),\n parentId: text(\"parent_id\"),\n display: jsonb(\"display\").$type<Record<string, JsonValue>>().notNull(),\n inApp: boolean(\"in_app\").notNull(),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n readAt: timestamp(\"read_at\", { withTimezone: true }),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n userFk: foreignKey({\n columns: [t.orgId, t.userId],\n foreignColumns: [orgUsers.orgId, orgUsers.userId],\n }).onDelete(\"cascade\"),\n communityFk: foreignKey({\n columns: [t.orgId, t.communityId],\n foreignColumns: [communities.orgId, communities.id],\n }).onDelete(\"cascade\"),\n spaceFk: foreignKey({\n columns: [t.orgId, t.spaceId],\n foreignColumns: [spaces.orgId, spaces.id],\n }).onDelete(\"cascade\"),\n sourceIdx: uniqueIndex(\"notifications_source_event_idx\")\n .on(t.orgId, t.sourceEventId, t.userId, sql`coalesce(${t.communityId}, '')`)\n .where(sql`${t.sourceEventId} is not null`),\n listIdx: index(\"notifications_list_idx\")\n .on(t.orgId, t.userId, desc(t.createdAt), desc(t.id))\n .where(sql`${t.inApp}`),\n communityIdx: index(\"notifications_community_idx\").on(t.orgId, t.userId, t.communityId),\n categoryIdx: index(\"notifications_category_idx\").on(t.orgId, t.userId, t.category),\n reasonsIdx: index(\"notifications_reasons_idx\").using(\"gin\", t.reasons),\n }),\n);\n\nexport const notificationDeliveries = pgTable(\n \"notification_deliveries\",\n {\n orgId: text(\"org_id\").notNull(),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"notificationDelivery\")),\n notificationId: text(\"notification_id\").notNull(),\n channel: text(\"channel\").notNull(),\n status: text(\"status\", { enum: [\"pending\", \"sent\", \"failed\"] })\n .notNull()\n .default(\"pending\"),\n lastError: text(\"last_error\"),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n sentAt: timestamp(\"sent_at\", { withTimezone: true }),\n },\n (t) => ({\n pk: primaryKey({ columns: [t.orgId, t.id] }),\n notificationFk: foreignKey({\n columns: [t.orgId, t.notificationId],\n foreignColumns: [notifications.orgId, notifications.id],\n }).onDelete(\"cascade\"),\n channelIdx: uniqueIndex(\"notification_deliveries_channel_idx\").on(\n t.orgId,\n t.notificationId,\n t.channel,\n ),\n }),\n);\n\ntype _Aut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