@headless-lms/adapter-db 0.3.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 (73) hide show
  1. package/dist/index.d.ts +6 -1
  2. package/dist/index.js +6 -1
  3. package/dist/repositories/admin.js +1 -1
  4. package/dist/repositories/assets.d.ts +1 -2
  5. package/dist/repositories/assets.js +0 -4
  6. package/dist/repositories/assets.js.map +1 -1
  7. package/dist/repositories/automations.d.ts +0 -1
  8. package/dist/repositories/automations.js +1 -17
  9. package/dist/repositories/automations.js.map +1 -1
  10. package/dist/repositories/chats.d.ts +4 -4
  11. package/dist/repositories/chats.js +33 -18
  12. package/dist/repositories/chats.js.map +1 -1
  13. package/dist/repositories/content.d.ts +3 -3
  14. package/dist/repositories/content.js +35 -12
  15. package/dist/repositories/content.js.map +1 -1
  16. package/dist/repositories/devices.d.ts +17 -0
  17. package/dist/repositories/devices.js +75 -0
  18. package/dist/repositories/devices.js.map +1 -0
  19. package/dist/repositories/digest-runs.d.ts +14 -0
  20. package/dist/repositories/digest-runs.js +39 -0
  21. package/dist/repositories/digest-runs.js.map +1 -0
  22. package/dist/repositories/discussion.d.ts +6 -1
  23. package/dist/repositories/discussion.js +9 -4
  24. package/dist/repositories/discussion.js.map +1 -1
  25. package/dist/repositories/entitlements.d.ts +3 -1
  26. package/dist/repositories/entitlements.js +12 -6
  27. package/dist/repositories/entitlements.js.map +1 -1
  28. package/dist/repositories/inserted-row.d.ts +5 -0
  29. package/dist/repositories/inserted-row.js +7 -0
  30. package/dist/repositories/inserted-row.js.map +1 -0
  31. package/dist/repositories/mentions.d.ts +17 -0
  32. package/dist/repositories/mentions.js +55 -0
  33. package/dist/repositories/mentions.js.map +1 -0
  34. package/dist/repositories/notification-settings.d.ts +19 -0
  35. package/dist/repositories/notification-settings.js +67 -0
  36. package/dist/repositories/notification-settings.js.map +1 -0
  37. package/dist/repositories/notifications.d.ts +23 -16
  38. package/dist/repositories/notifications.js +152 -44
  39. package/dist/repositories/notifications.js.map +1 -1
  40. package/dist/repositories/organizations.d.ts +1 -0
  41. package/dist/repositories/organizations.js +4 -1
  42. package/dist/repositories/organizations.js.map +1 -1
  43. package/dist/repositories/posts.d.ts +4 -8
  44. package/dist/repositories/posts.js +25 -28
  45. package/dist/repositories/posts.js.map +1 -1
  46. package/dist/repositories/subscriptions.d.ts +18 -0
  47. package/dist/repositories/subscriptions.js +72 -0
  48. package/dist/repositories/subscriptions.js.map +1 -0
  49. package/dist/schema/automations.d.ts +524 -19
  50. package/dist/schema/automations.js +73 -7
  51. package/dist/schema/automations.js.map +1 -1
  52. package/dist/schema/discussion.d.ts +277 -127
  53. package/dist/schema/discussion.js +59 -24
  54. package/dist/schema/discussion.js.map +1 -1
  55. package/dist/schema/identity.d.ts +109 -109
  56. package/dist/schema/identity.js +28 -70
  57. package/dist/schema/identity.js.map +1 -1
  58. package/dist/schema/index.d.ts +5 -5
  59. package/dist/schema/index.js +10 -6
  60. package/drizzle/0011_digest_runs.sql +8 -0
  61. package/drizzle/0012_subscriptions.sql +16 -0
  62. package/drizzle/0013_mentions.sql +10 -0
  63. package/drizzle/0014_notification_settings_devices.sql +36 -0
  64. package/drizzle/0015_automations_drop_source.sql +2 -0
  65. package/drizzle/0016_notifications_automations.sql +48 -0
  66. package/drizzle/meta/0011_snapshot.json +8868 -0
  67. package/drizzle/meta/0012_snapshot.json +8873 -0
  68. package/drizzle/meta/0013_snapshot.json +8943 -0
  69. package/drizzle/meta/0014_snapshot.json +9305 -0
  70. package/drizzle/meta/0015_snapshot.json +9270 -0
  71. package/drizzle/meta/0016_snapshot.json +9230 -0
  72. package/drizzle/meta/_journal.json +42 -0
  73. package/package.json +2 -2
@@ -1,9 +1,8 @@
1
1
  import { assets } from "./assets.js";
2
2
  import { communities, spaces } from "./content.js";
3
- import { chats, comments, messages, posts } from "./discussion.js";
4
3
  import { orgUsers } from "./organizations.js";
5
- import { desc, sql } from "drizzle-orm";
6
- import { boolean, check, foreignKey, index, jsonb, pgTable, primaryKey, text, timestamp } from "drizzle-orm/pg-core";
4
+ import { sql } from "drizzle-orm";
5
+ import { boolean, check, foreignKey, index, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
7
6
  import { genId } from "@headless-lms/core/shared/id";
8
7
  //#region src/schema/identity.ts
9
8
  const users = pgTable("users", {
@@ -33,41 +32,16 @@ const userProfiles = pgTable("user_profiles", {
33
32
  imageCk: check("user_profiles_image_check", sql`(${t.imageAssetOrgId} is null) = (${t.imageAssetId} is null)`),
34
33
  imageIdx: index("user_profiles_image_idx").on(t.imageAssetOrgId, t.imageAssetId)
35
34
  }));
36
- const NOTIFICATION_KINDS = [
37
- "newPostInSpace",
38
- "newCommentOnPost",
39
- "replyToYourComment",
40
- "yourPostWasPublished",
41
- "yourPostWasRemoved",
42
- "yourCommentWasRemoved",
43
- "requestApproved",
44
- "requestDeclined",
45
- "invitedToSpace",
46
- "newMessage",
47
- "messageRequest",
48
- "addedToGroupChat",
49
- "youAreNowAModerator",
50
- "membershipEndingSoon",
51
- "welcomeToCommunity",
52
- "postAwaitingReview",
53
- "joinRequest",
54
- "somethingWasFlagged",
55
- "messageWasFlagged"
56
- ];
57
- const notifications = pgTable("notifications", {
35
+ const notificationSettings = pgTable("notification_settings", {
58
36
  orgId: text("org_id").notNull(),
59
- id: text("id").notNull().$defaultFn(() => genId("notification")),
37
+ id: text("id").notNull().$defaultFn(() => genId("notificationSetting")),
60
38
  userId: text("user_id").notNull(),
61
- kind: text("kind", { enum: NOTIFICATION_KINDS }).notNull(),
62
- actorOrgUserId: text("actor_org_user_id"),
63
39
  communityId: text("community_id"),
64
40
  spaceId: text("space_id"),
65
- postId: text("post_id"),
66
- commentId: text("comment_id"),
67
- chatId: text("chat_id"),
68
- messageId: text("message_id"),
69
- createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
70
- readAt: timestamp("read_at", { withTimezone: true })
41
+ category: text("category").notNull(),
42
+ channel: text("channel").notNull(),
43
+ enabled: boolean("enabled").notNull(),
44
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
71
45
  }, (t) => ({
72
46
  pk: primaryKey({ columns: [t.orgId, t.id] }),
73
47
  userFk: foreignKey({
@@ -82,51 +56,35 @@ const notifications = pgTable("notifications", {
82
56
  columns: [t.orgId, t.spaceId],
83
57
  foreignColumns: [spaces.orgId, spaces.id]
84
58
  }).onDelete("cascade"),
85
- postFk: foreignKey({
86
- columns: [t.orgId, t.postId],
87
- foreignColumns: [posts.orgId, posts.id]
88
- }).onDelete("cascade"),
89
- commentFk: foreignKey({
90
- columns: [t.orgId, t.commentId],
91
- foreignColumns: [comments.orgId, comments.id]
92
- }).onDelete("cascade"),
93
- chatFk: foreignKey({
94
- columns: [t.orgId, t.chatId],
95
- foreignColumns: [chats.orgId, chats.id]
96
- }).onDelete("cascade"),
97
- messageFk: foreignKey({
98
- columns: [t.orgId, t.messageId],
99
- foreignColumns: [messages.orgId, messages.id]
100
- }).onDelete("cascade"),
101
- listIdx: index("notifications_list_idx").on(t.orgId, t.userId, t.readAt, desc(t.createdAt)),
102
- feedIdx: index("notifications_feed_idx").on(t.orgId, t.userId, desc(t.createdAt), desc(t.id)),
103
- communityIdx: index("notifications_community_idx").on(t.orgId, t.communityId),
104
- spaceIdx: index("notifications_space_idx").on(t.orgId, t.spaceId),
105
- postIdx: index("notifications_post_idx").on(t.orgId, t.postId),
106
- commentIdx: index("notifications_comment_idx").on(t.orgId, t.commentId),
107
- chatIdx: index("notifications_chat_idx").on(t.orgId, t.chatId),
108
- messageIdx: index("notifications_message_idx").on(t.orgId, t.messageId)
59
+ settingIdx: uniqueIndex("notification_settings_setting_idx").on(t.orgId, t.userId, sql`coalesce(${t.communityId}, '')`, sql`coalesce(${t.spaceId}, '')`, t.category, t.channel),
60
+ switchedOnIdx: index("notification_settings_switched_on_idx").on(t.orgId, sql`coalesce(${t.communityId}, '')`, t.category, sql`coalesce(${t.spaceId}, '')`).where(sql`${t.enabled}`)
109
61
  }));
110
- const notificationPreferences = pgTable("notification_preferences", {
62
+ const devices = pgTable("devices", {
111
63
  orgId: text("org_id").notNull(),
64
+ id: text("id").notNull().$defaultFn(() => genId("device")),
112
65
  userId: text("user_id").notNull(),
113
- kind: text("kind", { enum: NOTIFICATION_KINDS }).notNull(),
114
- inApp: boolean("in_app").notNull(),
115
- email: boolean("email").notNull(),
66
+ provider: text("provider", { enum: [
67
+ "apns",
68
+ "fcm",
69
+ "webpush"
70
+ ] }).notNull(),
71
+ token: text("token").notNull(),
72
+ p256dh: text("p256dh"),
73
+ auth: text("auth"),
74
+ appId: text("app_id"),
75
+ environment: text("environment", { enum: ["production", "sandbox"] }),
116
76
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
117
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
77
+ lastSeenAt: timestamp("last_seen_at", { withTimezone: true }).notNull().defaultNow()
118
78
  }, (t) => ({
119
- pk: primaryKey({ columns: [
120
- t.orgId,
121
- t.userId,
122
- t.kind
123
- ] }),
79
+ pk: primaryKey({ columns: [t.orgId, t.id] }),
124
80
  userFk: foreignKey({
125
81
  columns: [t.orgId, t.userId],
126
82
  foreignColumns: [orgUsers.orgId, orgUsers.userId]
127
- }).onDelete("cascade")
83
+ }).onDelete("cascade"),
84
+ tokenIdx: uniqueIndex("devices_token_idx").on(t.orgId, t.provider, t.token),
85
+ userIdx: index("devices_user_idx").on(t.orgId, t.userId, t.lastSeenAt)
128
86
  }));
129
87
  //#endregion
130
- export { notificationPreferences, notifications, userProfiles, users };
88
+ export { devices, notificationSettings, userProfiles, users };
131
89
 
132
90
  //# sourceMappingURL=identity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.js","names":[],"sources":["../../src/schema/identity.ts"],"sourcesContent":["// identity tables — the person.\n//\n// One row per human, global, storing auth ID in `external_id`.\nimport { desc, sql } from \"drizzle-orm\";\nimport {\n pgTable,\n text,\n jsonb,\n timestamp,\n boolean,\n foreignKey,\n check,\n index,\n primaryKey,\n} from \"drizzle-orm/pg-core\";\nimport type { Notification, User, UserProfile } from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { assets } from \"./assets.js\";\nimport { orgUsers } from \"./organizations.js\";\nimport { communities, spaces } from \"./content.js\";\nimport { chats, comments, messages, posts } from \"./discussion.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const users = pgTable(\"users\", {\n id: text(\"id\")\n .primaryKey()\n .$defaultFn(() => genId(\"user\")),\n // auth engine's ID - e.g. better-auth.\n externalId: text(\"external_id\").unique(),\n email: text(\"email\").notNull().unique(),\n firstName: text(\"first_name\"),\n lastName: text(\"last_name\"),\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\nexport const userProfiles = pgTable(\n \"user_profiles\",\n {\n userId: text(\"user_id\")\n .primaryKey()\n .references(() => users.id, { onDelete: \"cascade\" }),\n displayName: text(\"display_name\"),\n headline: text(\"headline\"),\n bio: text(\"bio\"),\n imageAssetOrgId: text(\"image_asset_org_id\"),\n imageAssetId: text(\"image_asset_id\"),\n extra: jsonb(\"extra\").$type<UserProfile[\"extra\"]>().notNull().default({}),\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 imageFk: foreignKey({\n columns: [t.imageAssetOrgId, t.imageAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n imageCk: check(\n \"user_profiles_image_check\",\n sql`(${t.imageAssetOrgId} is null) = (${t.imageAssetId} is null)`,\n ),\n imageIdx: index(\"user_profiles_image_idx\").on(t.imageAssetOrgId, t.imageAssetId),\n }),\n);\n\nconst NOTIFICATION_KINDS = [\n \"newPostInSpace\",\n \"newCommentOnPost\",\n \"replyToYourComment\",\n \"yourPostWasPublished\",\n \"yourPostWasRemoved\",\n \"yourCommentWasRemoved\",\n \"requestApproved\",\n \"requestDeclined\",\n \"invitedToSpace\",\n \"newMessage\",\n \"messageRequest\",\n \"addedToGroupChat\",\n \"youAreNowAModerator\",\n \"membershipEndingSoon\",\n \"welcomeToCommunity\",\n \"postAwaitingReview\",\n \"joinRequest\",\n \"somethingWasFlagged\",\n \"messageWasFlagged\",\n] as const;\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 kind: text(\"kind\", { enum: NOTIFICATION_KINDS }).notNull(),\n actorOrgUserId: text(\"actor_org_user_id\"),\n communityId: text(\"community_id\"),\n spaceId: text(\"space_id\"),\n postId: text(\"post_id\"),\n commentId: text(\"comment_id\"),\n chatId: text(\"chat_id\"),\n messageId: text(\"message_id\"),\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 postFk: foreignKey({\n columns: [t.orgId, t.postId],\n foreignColumns: [posts.orgId, posts.id],\n }).onDelete(\"cascade\"),\n commentFk: foreignKey({\n columns: [t.orgId, t.commentId],\n foreignColumns: [comments.orgId, comments.id],\n }).onDelete(\"cascade\"),\n chatFk: foreignKey({\n columns: [t.orgId, t.chatId],\n foreignColumns: [chats.orgId, chats.id],\n }).onDelete(\"cascade\"),\n messageFk: foreignKey({\n columns: [t.orgId, t.messageId],\n foreignColumns: [messages.orgId, messages.id],\n }).onDelete(\"cascade\"),\n listIdx: index(\"notifications_list_idx\").on(t.orgId, t.userId, t.readAt, desc(t.createdAt)),\n feedIdx: index(\"notifications_feed_idx\").on(t.orgId, t.userId, desc(t.createdAt), desc(t.id)),\n communityIdx: index(\"notifications_community_idx\").on(t.orgId, t.communityId),\n spaceIdx: index(\"notifications_space_idx\").on(t.orgId, t.spaceId),\n postIdx: index(\"notifications_post_idx\").on(t.orgId, t.postId),\n commentIdx: index(\"notifications_comment_idx\").on(t.orgId, t.commentId),\n chatIdx: index(\"notifications_chat_idx\").on(t.orgId, t.chatId),\n messageIdx: index(\"notifications_message_idx\").on(t.orgId, t.messageId),\n }),\n);\n\nexport const notificationPreferences = pgTable(\n \"notification_preferences\",\n {\n orgId: text(\"org_id\").notNull(),\n userId: text(\"user_id\").notNull(),\n kind: text(\"kind\", { enum: NOTIFICATION_KINDS }).notNull(),\n inApp: boolean(\"in_app\").notNull(),\n email: boolean(\"email\").notNull(),\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.userId, t.kind] }),\n userFk: foreignKey({\n columns: [t.orgId, t.userId],\n foreignColumns: [orgUsers.orgId, orgUsers.userId],\n }).onDelete(\"cascade\"),\n }),\n);\n\ntype _UsersDrift = Expect<NoDrift<typeof users.$inferSelect, User>>;\ntype _UserProfilesDrift = Expect<NoDrift<typeof userProfiles.$inferSelect, UserProfile>>;\ntype _NotificationsDrift = Expect<NoDrift<typeof notifications.$inferSelect, Notification>>;\n"],"mappings":";;;;;;;;AAuBA,MAAa,QAAQ,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,MAAM,2BAA2B,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS;AACxE,EACF;AAEA,MAAa,0BAA0B,QACrC,4BACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAAC,QAAQ;CAC9B,QAAQ,KAAK,SAAS,CAAC,CAAC,QAAQ;CAChC,MAAM,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC,CAAC,CAAC,QAAQ;CACzD,OAAO,QAAQ,QAAQ,CAAC,CAAC,QAAQ;CACjC,OAAO,QAAQ,OAAO,CAAC,CAAC,QAAQ;CAChC,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;EAAC,EAAE;EAAO,EAAE;EAAQ,EAAE;CAAI,EAAE,CAAC;CACvD,QAAQ,WAAW;EACjB,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM;EAC3B,gBAAgB,CAAC,SAAS,OAAO,SAAS,MAAM;CAClD,CAAC,CAAC,CAAC,SAAS,SAAS;AACvB,EACF"}
1
+ {"version":3,"file":"identity.js","names":[],"sources":["../../src/schema/identity.ts"],"sourcesContent":["// identity tables — the person.\n//\n// One row per human, global, storing auth ID in `external_id`.\nimport { sql } from \"drizzle-orm\";\nimport {\n pgTable,\n text,\n jsonb,\n timestamp,\n boolean,\n foreignKey,\n check,\n index,\n primaryKey,\n uniqueIndex,\n} from \"drizzle-orm/pg-core\";\nimport type { User, UserProfile } from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { assets } from \"./assets.js\";\nimport { orgUsers } from \"./organizations.js\";\nimport { communities, spaces } from \"./content.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const users = pgTable(\"users\", {\n id: text(\"id\")\n .primaryKey()\n .$defaultFn(() => genId(\"user\")),\n // auth engine's ID - e.g. better-auth.\n externalId: text(\"external_id\").unique(),\n email: text(\"email\").notNull().unique(),\n firstName: text(\"first_name\"),\n lastName: text(\"last_name\"),\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\nexport const userProfiles = pgTable(\n \"user_profiles\",\n {\n userId: text(\"user_id\")\n .primaryKey()\n .references(() => users.id, { onDelete: \"cascade\" }),\n displayName: text(\"display_name\"),\n headline: text(\"headline\"),\n bio: text(\"bio\"),\n imageAssetOrgId: text(\"image_asset_org_id\"),\n imageAssetId: text(\"image_asset_id\"),\n extra: jsonb(\"extra\").$type<UserProfile[\"extra\"]>().notNull().default({}),\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 imageFk: foreignKey({\n columns: [t.imageAssetOrgId, t.imageAssetId],\n foreignColumns: [assets.orgId, assets.id],\n }),\n imageCk: check(\n \"user_profiles_image_check\",\n sql`(${t.imageAssetOrgId} is null) = (${t.imageAssetId} is null)`,\n ),\n imageIdx: index(\"user_profiles_image_idx\").on(t.imageAssetOrgId, t.imageAssetId),\n }),\n);\n\nexport const notificationSettings = pgTable(\n \"notification_settings\",\n {\n orgId: text(\"org_id\").notNull(),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"notificationSetting\")),\n userId: text(\"user_id\").notNull(),\n communityId: text(\"community_id\"),\n spaceId: text(\"space_id\"),\n category: text(\"category\").notNull(),\n channel: text(\"channel\").notNull(),\n enabled: boolean(\"enabled\").notNull(),\n updatedAt: timestamp(\"updated_at\", { withTimezone: true }).notNull().defaultNow(),\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 settingIdx: uniqueIndex(\"notification_settings_setting_idx\").on(\n t.orgId,\n t.userId,\n sql`coalesce(${t.communityId}, '')`,\n sql`coalesce(${t.spaceId}, '')`,\n t.category,\n t.channel,\n ),\n switchedOnIdx: index(\"notification_settings_switched_on_idx\")\n .on(t.orgId, sql`coalesce(${t.communityId}, '')`, t.category, sql`coalesce(${t.spaceId}, '')`)\n .where(sql`${t.enabled}`),\n }),\n);\n\nexport const devices = pgTable(\n \"devices\",\n {\n orgId: text(\"org_id\").notNull(),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"device\")),\n userId: text(\"user_id\").notNull(),\n provider: text(\"provider\", { enum: [\"apns\", \"fcm\", \"webpush\"] }).notNull(),\n token: text(\"token\").notNull(),\n p256dh: text(\"p256dh\"),\n auth: text(\"auth\"),\n appId: text(\"app_id\"),\n environment: text(\"environment\", { enum: [\"production\", \"sandbox\"] }),\n createdAt: timestamp(\"created_at\", { withTimezone: true }).notNull().defaultNow(),\n lastSeenAt: timestamp(\"last_seen_at\", { withTimezone: true }).notNull().defaultNow(),\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 tokenIdx: uniqueIndex(\"devices_token_idx\").on(t.orgId, t.provider, t.token),\n userIdx: index(\"devices_user_idx\").on(t.orgId, t.userId, t.lastSeenAt),\n }),\n);\n\ntype _UsersD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,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK;CAC1E,SAAS,MAAM,kBAAkB,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;AACvE,EACF"}
@@ -2,17 +2,17 @@ import { invites, orgUsers, organizations } from "./organizations.js";
2
2
  import { activities, activityAssets, bundleItems, bundles, communities, contentItems, courses, downloadAssets, downloads, modules, spaceLinks, spaceTopics, spaces } from "./content.js";
3
3
  import { contentAccess, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, spaceMembers } from "./entitlements.js";
4
4
  import { progressRecords } from "./progress.js";
5
- import { notificationPreferences, notifications, userProfiles, users } from "./identity.js";
5
+ import { devices, notificationSettings, userProfiles, users } from "./identity.js";
6
6
  import { assets } from "./assets.js";
7
7
  import { credentials } from "./credentials.js";
8
8
  import { connections } from "./integrations.js";
9
9
  import { eventOutbox } from "./outbox.js";
10
- import { automationRuns, automations } from "./automations.js";
10
+ import { automationRuns, automations, notificationDeliveries, notifications } from "./automations.js";
11
11
  import { settings } from "./settings.js";
12
- import { blockedUsers, chatUsers, chats, commentFlags, commentReactions, comments, messageAttachments, messageFlags, messageReactions, messages, postBookmarks, postFlags, postFollows, postReactions, posts } from "./discussion.js";
12
+ import { blockedUsers, chatUsers, chats, commentFlags, commentReactions, comments, digestRuns, mentions, messageAttachments, messageFlags, messageReactions, messages, postBookmarks, postFlags, postReactions, posts, subscriptions } from "./discussion.js";
13
13
  declare namespace index_d_exports {
14
- export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, invites, messageAttachments, messageFlags, messageReactions, messages, modules, notificationPreferences, notifications, orgUsers, organizations, postBookmarks, postFlags, postFollows, postReactions, posts, progressRecords, settings, spaceLinks, spaceMembers, spaceTopics, spaces, userProfiles, users };
14
+ export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, devices, digestRuns, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, invites, mentions, messageAttachments, messageFlags, messageReactions, messages, modules, notificationDeliveries, notificationSettings, notifications, orgUsers, organizations, postBookmarks, postFlags, postReactions, posts, progressRecords, settings, spaceLinks, spaceMembers, spaceTopics, spaces, subscriptions, userProfiles, users };
15
15
  }
16
16
  //#endregion
17
- export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, index_d_exports, invites, messageAttachments, messageFlags, messageReactions, messages, modules, notificationPreferences, notifications, orgUsers, organizations, postBookmarks, postFlags, postFollows, postReactions, posts, progressRecords, settings, spaceLinks, spaceMembers, spaceTopics, spaces, userProfiles, users };
17
+ export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, devices, digestRuns, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, index_d_exports, invites, mentions, messageAttachments, messageFlags, messageReactions, messages, modules, notificationDeliveries, notificationSettings, notifications, orgUsers, organizations, postBookmarks, postFlags, postReactions, posts, progressRecords, settings, spaceLinks, spaceMembers, spaceTopics, spaces, subscriptions, userProfiles, users };
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,16 +1,16 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { assets } from "./assets.js";
3
3
  import { activities, activityAssets, bundleItems, bundles, communities, contentItems, courses, downloadAssets, downloads, modules, spaceLinks, spaceTopics, spaces } from "./content.js";
4
- import { blockedUsers, chatUsers, chats, commentFlags, commentReactions, comments, messageAttachments, messageFlags, messageReactions, messages, postBookmarks, postFlags, postFollows, postReactions, posts } from "./discussion.js";
5
- import { notificationPreferences, notifications, userProfiles, users } from "./identity.js";
4
+ import { devices, notificationSettings, userProfiles, users } from "./identity.js";
6
5
  import { invites, orgUsers, organizations } from "./organizations.js";
7
6
  import { contentAccess, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, spaceMembers } from "./entitlements.js";
8
7
  import { progressRecords } from "./progress.js";
9
8
  import { credentials } from "./credentials.js";
10
9
  import { connections } from "./integrations.js";
11
10
  import { eventOutbox } from "./outbox.js";
12
- import { automationRuns, automations } from "./automations.js";
11
+ import { automationRuns, automations, notificationDeliveries, notifications } from "./automations.js";
13
12
  import { settings } from "./settings.js";
13
+ import { blockedUsers, chatUsers, chats, commentFlags, commentReactions, comments, digestRuns, mentions, messageAttachments, messageFlags, messageReactions, messages, postBookmarks, postFlags, postReactions, posts, subscriptions } from "./discussion.js";
14
14
  //#region src/schema/index.ts
15
15
  var schema_exports = /* @__PURE__ */ __exportAll({
16
16
  activities: () => activities,
@@ -32,6 +32,8 @@ var schema_exports = /* @__PURE__ */ __exportAll({
32
32
  contentItems: () => contentItems,
33
33
  courses: () => courses,
34
34
  credentials: () => credentials,
35
+ devices: () => devices,
36
+ digestRuns: () => digestRuns,
35
37
  downloadAssets: () => downloadAssets,
36
38
  downloads: () => downloads,
37
39
  entitlementEndingSoonNotices: () => entitlementEndingSoonNotices,
@@ -39,18 +41,19 @@ var schema_exports = /* @__PURE__ */ __exportAll({
39
41
  entitlements: () => entitlements,
40
42
  eventOutbox: () => eventOutbox,
41
43
  invites: () => invites,
44
+ mentions: () => mentions,
42
45
  messageAttachments: () => messageAttachments,
43
46
  messageFlags: () => messageFlags,
44
47
  messageReactions: () => messageReactions,
45
48
  messages: () => messages,
46
49
  modules: () => modules,
47
- notificationPreferences: () => notificationPreferences,
50
+ notificationDeliveries: () => notificationDeliveries,
51
+ notificationSettings: () => notificationSettings,
48
52
  notifications: () => notifications,
49
53
  orgUsers: () => orgUsers,
50
54
  organizations: () => organizations,
51
55
  postBookmarks: () => postBookmarks,
52
56
  postFlags: () => postFlags,
53
- postFollows: () => postFollows,
54
57
  postReactions: () => postReactions,
55
58
  posts: () => posts,
56
59
  progressRecords: () => progressRecords,
@@ -59,10 +62,11 @@ var schema_exports = /* @__PURE__ */ __exportAll({
59
62
  spaceMembers: () => spaceMembers,
60
63
  spaceTopics: () => spaceTopics,
61
64
  spaces: () => spaces,
65
+ subscriptions: () => subscriptions,
62
66
  userProfiles: () => userProfiles,
63
67
  users: () => users
64
68
  });
65
69
  //#endregion
66
- export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, invites, messageAttachments, messageFlags, messageReactions, messages, modules, notificationPreferences, notifications, orgUsers, organizations, postBookmarks, postFlags, postFollows, postReactions, posts, progressRecords, schema_exports, settings, spaceLinks, spaceMembers, spaceTopics, spaces, userProfiles, users };
70
+ export { activities, activityAssets, assets, automationRuns, automations, blockedUsers, bundleItems, bundles, chatUsers, chats, commentFlags, commentReactions, comments, communities, connections, contentAccess, contentItems, courses, credentials, devices, digestRuns, downloadAssets, downloads, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, eventOutbox, invites, mentions, messageAttachments, messageFlags, messageReactions, messages, modules, notificationDeliveries, notificationSettings, notifications, orgUsers, organizations, postBookmarks, postFlags, postReactions, posts, progressRecords, schema_exports, settings, spaceLinks, spaceMembers, spaceTopics, spaces, subscriptions, userProfiles, users };
67
71
 
68
72
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ CREATE TABLE "digest_runs" (
2
+ "org_id" text NOT NULL,
3
+ "community_id" text NOT NULL,
4
+ "last_due_at" timestamp with time zone NOT NULL,
5
+ CONSTRAINT "digest_runs_org_id_community_id_pk" PRIMARY KEY("org_id","community_id")
6
+ );
7
+ --> statement-breakpoint
8
+ ALTER TABLE "digest_runs" ADD CONSTRAINT "digest_runs_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,16 @@
1
+ CREATE TABLE "subscriptions" (
2
+ "org_id" text NOT NULL,
3
+ "org_user_id" text NOT NULL,
4
+ "item_type" text NOT NULL,
5
+ "item_id" text NOT NULL,
6
+ "state" text NOT NULL,
7
+ "muted_until" timestamp with time zone,
8
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
9
+ CONSTRAINT "subscriptions_org_id_org_user_id_item_type_item_id_pk" PRIMARY KEY("org_id","org_user_id","item_type","item_id")
10
+ );
11
+ --> statement-breakpoint
12
+ DROP TABLE "post_follows" CASCADE;--> statement-breakpoint
13
+ ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_org_id_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
14
+ CREATE INDEX "subscriptions_item_idx" ON "subscriptions" USING btree ("org_id","item_type","item_id","state");--> statement-breakpoint
15
+ ALTER TABLE "chat_users" DROP COLUMN "muted";--> statement-breakpoint
16
+ ALTER TABLE "chat_users" DROP COLUMN "muted_until";
@@ -0,0 +1,10 @@
1
+ CREATE TABLE "mentions" (
2
+ "org_id" text NOT NULL,
3
+ "item_type" text NOT NULL,
4
+ "item_id" text NOT NULL,
5
+ "org_user_id" text NOT NULL,
6
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ CONSTRAINT "mentions_org_id_item_type_item_id_org_user_id_pk" PRIMARY KEY("org_id","item_type","item_id","org_user_id")
8
+ );
9
+ --> statement-breakpoint
10
+ ALTER TABLE "mentions" ADD CONSTRAINT "mentions_org_id_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,36 @@
1
+ CREATE TABLE "devices" (
2
+ "org_id" text NOT NULL,
3
+ "id" text NOT NULL,
4
+ "user_id" text NOT NULL,
5
+ "provider" text NOT NULL,
6
+ "token" text NOT NULL,
7
+ "p256dh" text,
8
+ "auth" text,
9
+ "app_id" text,
10
+ "environment" text,
11
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
12
+ "last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
13
+ CONSTRAINT "devices_org_id_id_pk" PRIMARY KEY("org_id","id")
14
+ );
15
+ --> statement-breakpoint
16
+ CREATE TABLE "notification_settings" (
17
+ "org_id" text NOT NULL,
18
+ "id" text NOT NULL,
19
+ "user_id" text NOT NULL,
20
+ "community_id" text,
21
+ "space_id" text,
22
+ "category" text NOT NULL,
23
+ "channel" text NOT NULL,
24
+ "enabled" boolean NOT NULL,
25
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
26
+ CONSTRAINT "notification_settings_org_id_id_pk" PRIMARY KEY("org_id","id")
27
+ );
28
+ --> statement-breakpoint
29
+ ALTER TABLE "devices" ADD CONSTRAINT "devices_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
30
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
31
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
32
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_space_id_spaces_org_id_id_fk" FOREIGN KEY ("org_id","space_id") REFERENCES "public"."spaces"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
33
+ CREATE UNIQUE INDEX "devices_token_idx" ON "devices" USING btree ("org_id","provider","token");--> statement-breakpoint
34
+ CREATE INDEX "devices_user_idx" ON "devices" USING btree ("org_id","user_id","last_seen_at");--> statement-breakpoint
35
+ CREATE UNIQUE INDEX "notification_settings_setting_idx" ON "notification_settings" USING btree ("org_id","user_id",coalesce("community_id", ''),coalesce("space_id", ''),"category","channel");--> statement-breakpoint
36
+ CREATE INDEX "notification_settings_switched_on_idx" ON "notification_settings" USING btree ("org_id",coalesce("community_id", ''),"category",coalesce("space_id", '')) WHERE "notification_settings"."enabled";
@@ -0,0 +1,2 @@
1
+ DROP INDEX "automations_system_seed_idx";--> statement-breakpoint
2
+ ALTER TABLE "automations" DROP COLUMN "source";
@@ -0,0 +1,48 @@
1
+ DROP TABLE "notification_preferences" CASCADE;--> statement-breakpoint
2
+ DROP TABLE "notifications" CASCADE;--> statement-breakpoint
3
+ CREATE TABLE "notification_deliveries" (
4
+ "org_id" text NOT NULL,
5
+ "id" text NOT NULL,
6
+ "notification_id" text NOT NULL,
7
+ "channel" text NOT NULL,
8
+ "status" text DEFAULT 'pending' NOT NULL,
9
+ "last_error" text,
10
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
11
+ "sent_at" timestamp with time zone,
12
+ CONSTRAINT "notification_deliveries_org_id_id_pk" PRIMARY KEY("org_id","id")
13
+ );
14
+ --> statement-breakpoint
15
+ CREATE TABLE "notifications" (
16
+ "org_id" text NOT NULL,
17
+ "id" text NOT NULL,
18
+ "user_id" text NOT NULL,
19
+ "source_event_id" text,
20
+ "type" text NOT NULL,
21
+ "scope" text NOT NULL,
22
+ "reasons" text[] NOT NULL,
23
+ "matched_reason" text NOT NULL,
24
+ "category" text NOT NULL,
25
+ "community_id" text,
26
+ "space_id" text,
27
+ "actor_org_user_id" text,
28
+ "subject_type" text,
29
+ "subject_id" text,
30
+ "parent_type" text,
31
+ "parent_id" text,
32
+ "display" jsonb NOT NULL,
33
+ "in_app" boolean NOT NULL,
34
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
35
+ "read_at" timestamp with time zone,
36
+ CONSTRAINT "notifications_org_id_id_pk" PRIMARY KEY("org_id","id")
37
+ );
38
+ --> statement-breakpoint
39
+ ALTER TABLE "notification_deliveries" ADD CONSTRAINT "notification_deliveries_org_id_notification_id_notifications_org_id_id_fk" FOREIGN KEY ("org_id","notification_id") REFERENCES "public"."notifications"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
40
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
41
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
42
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_space_id_spaces_org_id_id_fk" FOREIGN KEY ("org_id","space_id") REFERENCES "public"."spaces"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
43
+ CREATE UNIQUE INDEX "notification_deliveries_channel_idx" ON "notification_deliveries" USING btree ("org_id","notification_id","channel");--> statement-breakpoint
44
+ CREATE UNIQUE INDEX "notifications_source_event_idx" ON "notifications" USING btree ("org_id","source_event_id","user_id",coalesce("community_id", '')) WHERE "notifications"."source_event_id" is not null;--> statement-breakpoint
45
+ CREATE INDEX "notifications_list_idx" ON "notifications" USING btree ("org_id","user_id","created_at" desc,"id" desc) WHERE "notifications"."in_app";--> statement-breakpoint
46
+ CREATE INDEX "notifications_community_idx" ON "notifications" USING btree ("org_id","user_id","community_id");--> statement-breakpoint
47
+ CREATE INDEX "notifications_category_idx" ON "notifications" USING btree ("org_id","user_id","category");--> statement-breakpoint
48
+ CREATE INDEX "notifications_reasons_idx" ON "notifications" USING gin ("reasons");