@headless-lms/adapter-db 0.2.0 → 0.3.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 (104) hide show
  1. package/dist/index.d.ts +7 -6
  2. package/dist/index.js +7 -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 -2
  7. package/dist/repositories/assets.js +50 -9
  8. package/dist/repositories/assets.js.map +1 -1
  9. package/dist/repositories/automations.d.ts +6 -2
  10. package/dist/repositories/automations.js +45 -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 +454 -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 +293 -9
  17. package/dist/repositories/content.js.map +1 -1
  18. package/dist/repositories/discussion.d.ts +10 -3
  19. package/dist/repositories/discussion.js +70 -15
  20. package/dist/repositories/discussion.js.map +1 -1
  21. package/dist/repositories/entitlements.d.ts +29 -9
  22. package/dist/repositories/entitlements.js +207 -17
  23. package/dist/repositories/entitlements.js.map +1 -1
  24. package/dist/repositories/grant-covers.d.ts +20 -0
  25. package/dist/repositories/grant-covers.js +55 -0
  26. package/dist/repositories/grant-covers.js.map +1 -0
  27. package/dist/repositories/identity.d.ts +4 -2
  28. package/dist/repositories/identity.js +32 -1
  29. package/dist/repositories/identity.js.map +1 -1
  30. package/dist/repositories/member.d.ts +16 -0
  31. package/dist/repositories/member.js +63 -0
  32. package/dist/repositories/member.js.map +1 -0
  33. package/dist/repositories/members.js +2 -2
  34. package/dist/repositories/members.js.map +1 -1
  35. package/dist/repositories/notifications.d.ts +23 -0
  36. package/dist/repositories/notifications.js +70 -0
  37. package/dist/repositories/notifications.js.map +1 -0
  38. package/dist/repositories/org-user-profile.d.ts +214 -1
  39. package/dist/repositories/org-user-profile.js +23 -2
  40. package/dist/repositories/org-user-profile.js.map +1 -1
  41. package/dist/repositories/organizations.d.ts +3 -2
  42. package/dist/repositories/organizations.js +20 -8
  43. package/dist/repositories/organizations.js.map +1 -1
  44. package/dist/repositories/pg-errors.js +3 -1
  45. package/dist/repositories/pg-errors.js.map +1 -1
  46. package/dist/repositories/posts.d.ts +39 -0
  47. package/dist/repositories/posts.js +255 -0
  48. package/dist/repositories/posts.js.map +1 -0
  49. package/dist/schema/assets.d.ts +19 -2
  50. package/dist/schema/assets.js +10 -4
  51. package/dist/schema/assets.js.map +1 -1
  52. package/dist/schema/automations.d.ts +38 -0
  53. package/dist/schema/automations.js +5 -1
  54. package/dist/schema/automations.js.map +1 -1
  55. package/dist/schema/better-auth.d.ts +1613 -238
  56. package/dist/schema/better-auth.js +107 -22
  57. package/dist/schema/better-auth.js.map +1 -1
  58. package/dist/schema/content.d.ts +642 -5
  59. package/dist/schema/content.js +119 -10
  60. package/dist/schema/content.js.map +1 -1
  61. package/dist/schema/discussion.d.ts +2045 -55
  62. package/dist/schema/discussion.js +426 -11
  63. package/dist/schema/discussion.js.map +1 -1
  64. package/dist/schema/entitlements.d.ts +432 -1
  65. package/dist/schema/entitlements.js +109 -4
  66. package/dist/schema/entitlements.js.map +1 -1
  67. package/dist/schema/identity.d.ts +517 -1
  68. package/dist/schema/identity.js +118 -2
  69. package/dist/schema/identity.js.map +1 -1
  70. package/dist/schema/index.d.ts +6 -6
  71. package/dist/schema/index.js +30 -7
  72. package/dist/schema/organizations.d.ts +4 -4
  73. package/dist/schema/organizations.js +2 -0
  74. package/dist/schema/organizations.js.map +1 -1
  75. package/drizzle/0003_community.sql +340 -0
  76. package/drizzle/0004_assets_sources.sql +1 -0
  77. package/drizzle/0005_notices_and_seed_index.sql +12 -0
  78. package/drizzle/0006_community_review_fixes.sql +24 -0
  79. package/drizzle/0007_notifications.sql +37 -0
  80. package/drizzle/0008_content_access.sql +13 -0
  81. package/drizzle/0009_community_indexes.sql +56 -0
  82. package/drizzle/0010_mcp_access.sql +114 -0
  83. package/drizzle/meta/0003_snapshot.json +7061 -0
  84. package/drizzle/meta/0004_snapshot.json +7068 -0
  85. package/drizzle/meta/0005_snapshot.json +7180 -0
  86. package/drizzle/meta/0006_snapshot.json +7298 -0
  87. package/drizzle/meta/0007_snapshot.json +7620 -0
  88. package/drizzle/meta/0008_snapshot.json +7666 -0
  89. package/drizzle/meta/0009_snapshot.json +8185 -0
  90. package/drizzle/meta/0010_snapshot.json +8813 -0
  91. package/drizzle/meta/_journal.json +57 -1
  92. package/package.json +2 -2
  93. package/dist/repositories/course-analytics.d.ts +0 -15
  94. package/dist/repositories/course-analytics.js +0 -137
  95. package/dist/repositories/course-analytics.js.map +0 -1
  96. package/dist/repositories/dashboard.d.ts +0 -14
  97. package/dist/repositories/dashboard.js +0 -57
  98. package/dist/repositories/dashboard.js.map +0 -1
  99. package/dist/repositories/learn.d.ts +0 -19
  100. package/dist/repositories/learn.js +0 -56
  101. package/dist/repositories/learn.js.map +0 -1
  102. package/dist/repositories/students.d.ts +0 -16
  103. package/dist/repositories/students.js +0 -160
  104. package/dist/repositories/students.js.map +0 -1
@@ -1,18 +1,18 @@
1
1
  import { invites, orgUsers, organizations } from "./organizations.js";
2
- import { activities, activityAssets, bundleItems, bundles, contentItems, courses, downloadAssets, downloads, modules } from "./content.js";
3
- import { entitlements } from "./entitlements.js";
2
+ import { activities, activityAssets, bundleItems, bundles, communities, contentItems, courses, downloadAssets, downloads, modules, spaceLinks, spaceTopics, spaces } from "./content.js";
3
+ import { contentAccess, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, spaceMembers } from "./entitlements.js";
4
4
  import { progressRecords } from "./progress.js";
5
- import { users } from "./identity.js";
5
+ import { notificationPreferences, notifications, 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
10
  import { automationRuns, automations } from "./automations.js";
11
11
  import { settings } from "./settings.js";
12
- import { commentReactions, commentReports, comments } from "./discussion.js";
12
+ import { blockedUsers, chatUsers, chats, commentFlags, commentReactions, comments, messageAttachments, messageFlags, messageReactions, messages, postBookmarks, postFlags, postFollows, postReactions, posts } from "./discussion.js";
13
13
  declare namespace index_d_exports {
14
- export { activities, activityAssets, assets, automationRuns, automations, bundleItems, bundles, commentReactions, commentReports, comments, connections, contentItems, courses, credentials, downloadAssets, downloads, entitlements, eventOutbox, invites, modules, orgUsers, organizations, progressRecords, settings, users };
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 };
15
15
  }
16
16
  //#endregion
17
- export { activities, activityAssets, assets, automationRuns, automations, bundleItems, bundles, commentReactions, commentReports, comments, connections, contentItems, courses, credentials, downloadAssets, downloads, entitlements, eventOutbox, index_d_exports, invites, modules, orgUsers, organizations, progressRecords, settings, users };
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 };
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,16 +1,16 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
- import { users } from "./identity.js";
3
- import { invites, orgUsers, organizations } from "./organizations.js";
4
2
  import { assets } from "./assets.js";
5
- import { activities, activityAssets, bundleItems, bundles, contentItems, courses, downloadAssets, downloads, modules } from "./content.js";
6
- import { entitlements } from "./entitlements.js";
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";
6
+ import { invites, orgUsers, organizations } from "./organizations.js";
7
+ import { contentAccess, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, spaceMembers } from "./entitlements.js";
7
8
  import { progressRecords } from "./progress.js";
8
9
  import { credentials } from "./credentials.js";
9
10
  import { connections } from "./integrations.js";
10
11
  import { eventOutbox } from "./outbox.js";
11
12
  import { automationRuns, automations } from "./automations.js";
12
13
  import { settings } from "./settings.js";
13
- import { commentReactions, commentReports, comments } from "./discussion.js";
14
14
  //#region src/schema/index.ts
15
15
  var schema_exports = /* @__PURE__ */ __exportAll({
16
16
  activities: () => activities,
@@ -18,28 +18,51 @@ var schema_exports = /* @__PURE__ */ __exportAll({
18
18
  assets: () => assets,
19
19
  automationRuns: () => automationRuns,
20
20
  automations: () => automations,
21
+ blockedUsers: () => blockedUsers,
21
22
  bundleItems: () => bundleItems,
22
23
  bundles: () => bundles,
24
+ chatUsers: () => chatUsers,
25
+ chats: () => chats,
26
+ commentFlags: () => commentFlags,
23
27
  commentReactions: () => commentReactions,
24
- commentReports: () => commentReports,
25
28
  comments: () => comments,
29
+ communities: () => communities,
26
30
  connections: () => connections,
31
+ contentAccess: () => contentAccess,
27
32
  contentItems: () => contentItems,
28
33
  courses: () => courses,
29
34
  credentials: () => credentials,
30
35
  downloadAssets: () => downloadAssets,
31
36
  downloads: () => downloads,
37
+ entitlementEndingSoonNotices: () => entitlementEndingSoonNotices,
38
+ entitlementExpiryNotices: () => entitlementExpiryNotices,
32
39
  entitlements: () => entitlements,
33
40
  eventOutbox: () => eventOutbox,
34
41
  invites: () => invites,
42
+ messageAttachments: () => messageAttachments,
43
+ messageFlags: () => messageFlags,
44
+ messageReactions: () => messageReactions,
45
+ messages: () => messages,
35
46
  modules: () => modules,
47
+ notificationPreferences: () => notificationPreferences,
48
+ notifications: () => notifications,
36
49
  orgUsers: () => orgUsers,
37
50
  organizations: () => organizations,
51
+ postBookmarks: () => postBookmarks,
52
+ postFlags: () => postFlags,
53
+ postFollows: () => postFollows,
54
+ postReactions: () => postReactions,
55
+ posts: () => posts,
38
56
  progressRecords: () => progressRecords,
39
57
  settings: () => settings,
58
+ spaceLinks: () => spaceLinks,
59
+ spaceMembers: () => spaceMembers,
60
+ spaceTopics: () => spaceTopics,
61
+ spaces: () => spaces,
62
+ userProfiles: () => userProfiles,
40
63
  users: () => users
41
64
  });
42
65
  //#endregion
43
- export { activities, activityAssets, assets, automationRuns, automations, bundleItems, bundles, commentReactions, commentReports, comments, connections, contentItems, courses, credentials, downloadAssets, downloads, entitlements, eventOutbox, invites, modules, orgUsers, organizations, progressRecords, schema_exports, settings, users };
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 };
44
67
 
45
68
  //# sourceMappingURL=index.js.map
@@ -185,14 +185,14 @@ declare const orgUsers: import("drizzle-orm/pg-core").PgTableWithColumns<{
185
185
  tableName: "org_users";
186
186
  dataType: "string";
187
187
  columnType: "PgText";
188
- data: "student" | "owner" | "admin" | "instructor";
188
+ data: "student" | "owner" | "admin" | "instructor" | "moderator";
189
189
  driverParam: string;
190
190
  notNull: true;
191
191
  hasDefault: false;
192
192
  isPrimaryKey: false;
193
193
  isAutoincrement: false;
194
194
  hasRuntimeDefault: false;
195
- enumValues: ["owner", "admin", "instructor", "student"];
195
+ enumValues: ["owner", "admin", "instructor", "moderator", "student"];
196
196
  baseColumn: never;
197
197
  identity: undefined;
198
198
  generated: undefined;
@@ -311,14 +311,14 @@ declare const invites: import("drizzle-orm/pg-core").PgTableWithColumns<{
311
311
  tableName: "invites";
312
312
  dataType: "string";
313
313
  columnType: "PgText";
314
- data: "student" | "admin" | "instructor";
314
+ data: "student" | "admin" | "instructor" | "moderator";
315
315
  driverParam: string;
316
316
  notNull: true;
317
317
  hasDefault: false;
318
318
  isPrimaryKey: false;
319
319
  isAutoincrement: false;
320
320
  hasRuntimeDefault: false;
321
- enumValues: ["admin", "instructor", "student"];
321
+ enumValues: ["admin", "instructor", "moderator", "student"];
322
322
  baseColumn: never;
323
323
  identity: undefined;
324
324
  generated: undefined;
@@ -20,6 +20,7 @@ const orgUsers = pgTable("org_users", {
20
20
  "owner",
21
21
  "admin",
22
22
  "instructor",
23
+ "moderator",
23
24
  "student"
24
25
  ] }).notNull(),
25
26
  status: text("status", { enum: ["invited", "active"] }).notNull().default("active"),
@@ -36,6 +37,7 @@ const invites = pgTable("invites", {
36
37
  role: text("role", { enum: [
37
38
  "admin",
38
39
  "instructor",
40
+ "moderator",
39
41
  "student"
40
42
  ] }).notNull(),
41
43
  status: text("status", { enum: [
@@ -1 +1 @@
1
- {"version":3,"file":"organizations.js","names":[],"sources":["../../src/schema/organizations.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport { pgTable, text, timestamp, primaryKey, unique, uniqueIndex } from \"drizzle-orm/pg-core\";\nimport type { Invite, Organization, OrgUser } from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { users } from \"./identity.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const organizations = pgTable(\"organizations\", {\n id: text(\"id\")\n .primaryKey()\n .$defaultFn(() => genId(\"organization\")),\n // Links to the better-auth organization record.\n externalId: text(\"external_id\").unique(),\n name: text(\"name\").notNull(),\n slug: text(\"slug\").notNull().unique(),\n ownerId: text(\"owner_id\")\n .notNull()\n .references(() => users.id),\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\n// A person's link to an organization under one role\nexport const orgUsers = pgTable(\n \"org_users\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"orgUser\")),\n\n userId: text(\"user_id\")\n .notNull()\n .references(() => users.id),\n role: text(\"role\", { enum: [\"owner\", \"admin\", \"instructor\", \"student\"] }).notNull(),\n // 'invited' from the moment an admin adds a student until they accept.\n // Staff rows are mirrored from an auth member record that only exists once\n // they have joined, so they are created 'active'.\n status: text(\"status\", { enum: [\"invited\", \"active\"] })\n .notNull()\n .default(\"active\"),\n\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 userUq: unique().on(t.orgId, t.userId),\n }),\n);\n\nexport const invites = pgTable(\n \"invites\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"invite\")),\n email: text(\"email\").notNull(),\n role: text(\"role\", { enum: [\"admin\", \"instructor\", \"student\"] }).notNull(),\n status: text(\"status\", {\n enum: [\"pending\", \"accepted\", \"rejected\", \"canceled\"],\n }).notNull(),\n invitedBy: text(\"invited_by\")\n .notNull()\n .references(() => users.id),\n tokenHash: text(\"token_hash\").unique(),\n expiresAt: timestamp(\"expires_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 // One pending invite per (org, email) — the upsert's conflict target.\n pendingEmailUq: uniqueIndex(\"invites_pending_email_uq\")\n .on(t.orgId, t.email)\n .where(sql`${t.status} = 'pending'`),\n }),\n);\n\ntype _OrganizationsDrift = Expect<NoDrift<typeof organizations.$inferSelect, Organization>>;\ntype _OrgUsersDrift = Expect<NoDrift<typeof orgUsers.$inferSelect, OrgUser>>;\ntype _InvitesDrift = Expect<NoDrift<typeof invites.$inferSelect, Invite>>;\n"],"mappings":"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"}
1
+ {"version":3,"file":"organizations.js","names":[],"sources":["../../src/schema/organizations.ts"],"sourcesContent":["import { sql } from \"drizzle-orm\";\nimport { pgTable, text, timestamp, primaryKey, unique, uniqueIndex } from \"drizzle-orm/pg-core\";\nimport type { Invite, Organization, OrgUser } from \"@headless-lms/core/schemas\";\nimport { genId } from \"@headless-lms/core/shared/id\";\nimport { users } from \"./identity.js\";\nimport type { Expect, NoDrift } from \"./drift.js\";\n\nexport const organizations = pgTable(\"organizations\", {\n id: text(\"id\")\n .primaryKey()\n .$defaultFn(() => genId(\"organization\")),\n // Links to the better-auth organization record.\n externalId: text(\"external_id\").unique(),\n name: text(\"name\").notNull(),\n slug: text(\"slug\").notNull().unique(),\n ownerId: text(\"owner_id\")\n .notNull()\n .references(() => users.id),\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\n// A person's link to an organization under one role\nexport const orgUsers = pgTable(\n \"org_users\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"orgUser\")),\n\n userId: text(\"user_id\")\n .notNull()\n .references(() => users.id),\n role: text(\"role\", {\n enum: [\"owner\", \"admin\", \"instructor\", \"moderator\", \"student\"],\n }).notNull(),\n // 'invited' from the moment an admin adds a student until they accept.\n // Staff rows are mirrored from an auth member record that only exists once\n // they have joined, so they are created 'active'.\n status: text(\"status\", { enum: [\"invited\", \"active\"] })\n .notNull()\n .default(\"active\"),\n\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 userUq: unique().on(t.orgId, t.userId),\n }),\n);\n\nexport const invites = pgTable(\n \"invites\",\n {\n orgId: text(\"org_id\")\n .notNull()\n .references(() => organizations.id),\n id: text(\"id\")\n .notNull()\n .$defaultFn(() => genId(\"invite\")),\n email: text(\"email\").notNull(),\n role: text(\"role\", { enum: [\"admin\", \"instructor\", \"moderator\", \"student\"] }).notNull(),\n status: text(\"status\", {\n enum: [\"pending\", \"accepted\", \"rejected\", \"canceled\"],\n }).notNull(),\n invitedBy: text(\"invited_by\")\n .notNull()\n .references(() => users.id),\n tokenHash: text(\"token_hash\").unique(),\n expiresAt: timestamp(\"expires_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 // One pending invite per (org, email) — the upsert's conflict target.\n pendingEmailUq: uniqueIndex(\"invites_pending_email_uq\")\n .on(t.orgId, t.email)\n .where(sql`${t.status} = 'pending'`),\n }),\n);\n\ntype _OrganizationsDrift = Expect<NoDrift<typeof organizations.$inferSelect, Organization>>;\ntype _OrgUsersDrift = Expect<NoDrift<typeof orgUsers.$inferSelect, OrgUser>>;\ntype _InvitesDrift = Expect<NoDrift<typeof invites.$inferSelect, Invite>>;\n"],"mappings":";;;;;AAOA,MAAa,gBAAgB,QAAQ,iBAAiB;CACpD,IAAI,KAAK,IAAI,CAAC,CACX,WAAW,CAAC,CACZ,iBAAiB,MAAM,cAAc,CAAC;CAEzC,YAAY,KAAK,aAAa,CAAC,CAAC,OAAO;CACvC,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ;CAC3B,MAAM,KAAK,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO;CACpC,SAAS,KAAK,UAAU,CAAC,CACtB,QAAQ,CAAC,CACT,iBAAiB,MAAM,EAAE;CAC5B,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,CAAC;AAGD,MAAa,WAAW,QACtB,aACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAClB,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,IAAI,KAAK,IAAI,CAAC,CACX,QAAQ,CAAC,CACT,iBAAiB,MAAM,SAAS,CAAC;CAEpC,QAAQ,KAAK,SAAS,CAAC,CACpB,QAAQ,CAAC,CACT,iBAAiB,MAAM,EAAE;CAC5B,MAAM,KAAK,QAAQ,EACjB,MAAM;EAAC;EAAS;EAAS;EAAc;EAAa;CAAS,EAC/D,CAAC,CAAC,CAAC,QAAQ;CAIX,QAAQ,KAAK,UAAU,EAAE,MAAM,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAC,CACpD,QAAQ,CAAC,CACT,QAAQ,QAAQ;CAEnB,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,QAAQ,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM;AACvC,EACF;AAEA,MAAa,UAAU,QACrB,WACA;CACE,OAAO,KAAK,QAAQ,CAAC,CAClB,QAAQ,CAAC,CACT,iBAAiB,cAAc,EAAE;CACpC,IAAI,KAAK,IAAI,CAAC,CACX,QAAQ,CAAC,CACT,iBAAiB,MAAM,QAAQ,CAAC;CACnC,OAAO,KAAK,OAAO,CAAC,CAAC,QAAQ;CAC7B,MAAM,KAAK,QAAQ,EAAE,MAAM;EAAC;EAAS;EAAc;EAAa;CAAS,EAAE,CAAC,CAAC,CAAC,QAAQ;CACtF,QAAQ,KAAK,UAAU,EACrB,MAAM;EAAC;EAAW;EAAY;EAAY;CAAU,EACtD,CAAC,CAAC,CAAC,QAAQ;CACX,WAAW,KAAK,YAAY,CAAC,CAC1B,QAAQ,CAAC,CACT,iBAAiB,MAAM,EAAE;CAC5B,WAAW,KAAK,YAAY,CAAC,CAAC,OAAO;CACrC,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC;CACzD,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;CAE3C,gBAAgB,YAAY,0BAA0B,CAAC,CACpD,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CACpB,MAAM,GAAG,GAAG,EAAE,OAAO,aAAa;AACvC,EACF"}
@@ -0,0 +1,340 @@
1
+ ALTER TABLE "comment_reports" RENAME TO "comment_flags";--> statement-breakpoint
2
+ ALTER TABLE "comment_flags" RENAME CONSTRAINT "comment_reports_org_id_id_pk" TO "comment_flags_org_id_id_pk";--> statement-breakpoint
3
+ ALTER TABLE "comment_flags" RENAME CONSTRAINT "comment_reports_org_id_comment_id_org_user_id_unique" TO "comment_flags_org_id_comment_id_org_user_id_unique";--> statement-breakpoint
4
+ ALTER TABLE "comment_flags" RENAME CONSTRAINT "comment_reports_org_id_organizations_id_fk" TO "comment_flags_org_id_organizations_id_fk";--> statement-breakpoint
5
+ ALTER TABLE "comment_flags" RENAME CONSTRAINT "comment_reports_org_id_comment_id_comments_org_id_id_fk" TO "comment_flags_org_id_comment_id_comments_org_id_id_fk";--> statement-breakpoint
6
+ ALTER TABLE "comment_flags" RENAME CONSTRAINT "comment_reports_org_id_org_user_id_org_users_org_id_id_fk" TO "comment_flags_org_id_org_user_id_org_users_org_id_id_fk";--> statement-breakpoint
7
+ ALTER INDEX "comment_reports_open_idx" RENAME TO "comment_flags_open_idx";--> statement-breakpoint
8
+ ALTER TABLE "comment_flags" ADD COLUMN "resolution" text;--> statement-breakpoint
9
+ ALTER TABLE "comment_flags" ADD COLUMN "resolved_by" text;--> statement-breakpoint
10
+ ALTER TABLE "comment_flags" ADD CONSTRAINT "comment_flags_resolved_check" CHECK (("comment_flags"."resolved_at" is null) = ("comment_flags"."resolution" is null) and ("comment_flags"."resolved_by" is null or "comment_flags"."resolved_at" is not null));--> statement-breakpoint
11
+ ALTER TABLE "comments" ALTER COLUMN "activity_id" DROP NOT NULL;--> statement-breakpoint
12
+ CREATE TABLE "communities" (
13
+ "org_id" text NOT NULL,
14
+ "id" text NOT NULL,
15
+ "type" text GENERATED ALWAYS AS ('community') STORED NOT NULL,
16
+ "title" text NOT NULL,
17
+ "slug" text NOT NULL,
18
+ "description" text DEFAULT '' NOT NULL,
19
+ "status" text DEFAULT 'draft' NOT NULL,
20
+ "thumbnail_asset_id" text,
21
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
22
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
23
+ CONSTRAINT "communities_org_id_id_pk" PRIMARY KEY("org_id","id"),
24
+ CONSTRAINT "communities_org_id_slug_unique" UNIQUE("org_id","slug")
25
+ );
26
+ --> statement-breakpoint
27
+ CREATE TABLE "space_links" (
28
+ "org_id" text NOT NULL,
29
+ "id" text NOT NULL,
30
+ "space_id" text NOT NULL,
31
+ "content_id" text NOT NULL,
32
+ "seq" integer DEFAULT 0 NOT NULL,
33
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
34
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
35
+ CONSTRAINT "space_links_org_id_id_pk" PRIMARY KEY("org_id","id"),
36
+ CONSTRAINT "space_links_org_id_space_id_content_id_unique" UNIQUE("org_id","space_id","content_id")
37
+ );
38
+ --> statement-breakpoint
39
+ CREATE TABLE "space_topics" (
40
+ "org_id" text NOT NULL,
41
+ "id" text NOT NULL,
42
+ "space_id" text NOT NULL,
43
+ "name" text NOT NULL,
44
+ "seq" integer NOT NULL,
45
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
46
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
47
+ CONSTRAINT "space_topics_org_id_id_pk" PRIMARY KEY("org_id","id"),
48
+ CONSTRAINT "space_topics_org_id_space_id_name_unique" UNIQUE("org_id","space_id","name"),
49
+ CONSTRAINT "space_topics_org_id_space_id_id_unique" UNIQUE("org_id","space_id","id")
50
+ );
51
+ --> statement-breakpoint
52
+ CREATE TABLE "spaces" (
53
+ "org_id" text NOT NULL,
54
+ "id" text NOT NULL,
55
+ "community_id" text NOT NULL,
56
+ "name" text NOT NULL,
57
+ "description" text DEFAULT '' NOT NULL,
58
+ "seq" integer NOT NULL,
59
+ "access_rule" text DEFAULT 'all_members' NOT NULL,
60
+ "capacity" integer,
61
+ "settings" jsonb DEFAULT '{"comments":true,"reactions":true,"requireReview":false}'::jsonb NOT NULL,
62
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
63
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
64
+ CONSTRAINT "spaces_org_id_id_pk" PRIMARY KEY("org_id","id"),
65
+ CONSTRAINT "spaces_org_id_id_community_id_unique" UNIQUE("org_id","id","community_id"),
66
+ CONSTRAINT "spaces_capacity_check" CHECK ("spaces"."capacity" is null or "spaces"."access_rule" <> 'all_members')
67
+ );
68
+ --> statement-breakpoint
69
+ CREATE TABLE "space_members" (
70
+ "org_id" text NOT NULL,
71
+ "id" text NOT NULL,
72
+ "community_id" text NOT NULL,
73
+ "space_id" text NOT NULL,
74
+ "org_user_id" text NOT NULL,
75
+ "status" text NOT NULL,
76
+ "source" text DEFAULT 'request' NOT NULL,
77
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
78
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
79
+ CONSTRAINT "space_members_org_id_id_pk" PRIMARY KEY("org_id","id"),
80
+ CONSTRAINT "space_members_org_id_space_id_org_user_id_unique" UNIQUE("org_id","space_id","org_user_id")
81
+ );
82
+ --> statement-breakpoint
83
+ CREATE TABLE "user_profiles" (
84
+ "user_id" text PRIMARY KEY NOT NULL,
85
+ "display_name" text,
86
+ "headline" text,
87
+ "bio" text,
88
+ "image_asset_org_id" text,
89
+ "image_asset_id" text,
90
+ "extra" jsonb DEFAULT '{}'::jsonb NOT NULL,
91
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
92
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
93
+ CONSTRAINT "user_profiles_image_check" CHECK (("user_profiles"."image_asset_org_id" is null) = ("user_profiles"."image_asset_id" is null))
94
+ );
95
+ --> statement-breakpoint
96
+ CREATE TABLE "blocked_users" (
97
+ "org_id" text NOT NULL,
98
+ "community_id" text NOT NULL,
99
+ "blocker_org_user_id" text NOT NULL,
100
+ "blocked_org_user_id" text NOT NULL,
101
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
102
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
103
+ CONSTRAINT "blocked_users_org_id_community_id_blocker_org_user_id_blocked_org_user_id_pk" PRIMARY KEY("org_id","community_id","blocker_org_user_id","blocked_org_user_id")
104
+ );
105
+ --> statement-breakpoint
106
+ CREATE TABLE "chat_users" (
107
+ "org_id" text NOT NULL,
108
+ "community_id" text NOT NULL,
109
+ "chat_id" text NOT NULL,
110
+ "org_user_id" text NOT NULL,
111
+ "joined_at" timestamp with time zone DEFAULT now() NOT NULL,
112
+ "left_at" timestamp with time zone,
113
+ "last_read_message_id" text,
114
+ "muted" boolean DEFAULT false NOT NULL,
115
+ "muted_until" timestamp with time zone,
116
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
117
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
118
+ CONSTRAINT "chat_users_org_id_chat_id_org_user_id_pk" PRIMARY KEY("org_id","chat_id","org_user_id")
119
+ );
120
+ --> statement-breakpoint
121
+ CREATE TABLE "chats" (
122
+ "org_id" text NOT NULL,
123
+ "id" text NOT NULL,
124
+ "community_id" text NOT NULL,
125
+ "kind" text NOT NULL,
126
+ "status" text DEFAULT 'open' NOT NULL,
127
+ "created_by" text NOT NULL,
128
+ "locked_at" timestamp with time zone,
129
+ "locked_by" text,
130
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
131
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
132
+ CONSTRAINT "chats_org_id_id_pk" PRIMARY KEY("org_id","id"),
133
+ CONSTRAINT "chats_org_id_id_community_id_unique" UNIQUE("org_id","id","community_id"),
134
+ CONSTRAINT "chats_locked_check" CHECK (("chats"."locked_at" is null) = ("chats"."locked_by" is null))
135
+ );
136
+ --> statement-breakpoint
137
+ CREATE TABLE "message_attachments" (
138
+ "org_id" text NOT NULL,
139
+ "community_id" text NOT NULL,
140
+ "message_id" text NOT NULL,
141
+ "asset_id" text NOT NULL,
142
+ "seq" integer DEFAULT 0 NOT NULL,
143
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
144
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
145
+ CONSTRAINT "message_attachments_org_id_message_id_asset_id_pk" PRIMARY KEY("org_id","message_id","asset_id")
146
+ );
147
+ --> statement-breakpoint
148
+ CREATE TABLE "message_flags" (
149
+ "org_id" text NOT NULL,
150
+ "id" text NOT NULL,
151
+ "community_id" text NOT NULL,
152
+ "message_id" text NOT NULL,
153
+ "org_user_id" text NOT NULL,
154
+ "reason" text DEFAULT '' NOT NULL,
155
+ "resolved_at" timestamp with time zone,
156
+ "resolution" text,
157
+ "resolved_by" text,
158
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
159
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
160
+ CONSTRAINT "message_flags_org_id_id_pk" PRIMARY KEY("org_id","id"),
161
+ CONSTRAINT "message_flags_org_id_message_id_org_user_id_unique" UNIQUE("org_id","message_id","org_user_id"),
162
+ CONSTRAINT "message_flags_resolved_check" CHECK (("message_flags"."resolved_at" is null) = ("message_flags"."resolution" is null) and ("message_flags"."resolved_at" is null) = ("message_flags"."resolved_by" is null))
163
+ );
164
+ --> statement-breakpoint
165
+ CREATE TABLE "message_reactions" (
166
+ "org_id" text NOT NULL,
167
+ "community_id" text NOT NULL,
168
+ "message_id" text NOT NULL,
169
+ "org_user_id" text NOT NULL,
170
+ "emoji" text NOT NULL,
171
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
172
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
173
+ CONSTRAINT "message_reactions_org_id_message_id_org_user_id_pk" PRIMARY KEY("org_id","message_id","org_user_id")
174
+ );
175
+ --> statement-breakpoint
176
+ CREATE TABLE "messages" (
177
+ "org_id" text NOT NULL,
178
+ "id" text NOT NULL,
179
+ "community_id" text NOT NULL,
180
+ "chat_id" text NOT NULL,
181
+ "org_user_id" text NOT NULL,
182
+ "body" text NOT NULL,
183
+ "reply_to_id" text,
184
+ "edited_at" timestamp with time zone,
185
+ "deleted_at" timestamp with time zone,
186
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
187
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
188
+ CONSTRAINT "messages_org_id_id_pk" PRIMARY KEY("org_id","id"),
189
+ CONSTRAINT "messages_org_id_id_community_id_unique" UNIQUE("org_id","id","community_id")
190
+ );
191
+ --> statement-breakpoint
192
+ CREATE TABLE "post_bookmarks" (
193
+ "org_id" text NOT NULL,
194
+ "post_id" text NOT NULL,
195
+ "org_user_id" text NOT NULL,
196
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
197
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
198
+ CONSTRAINT "post_bookmarks_org_id_post_id_org_user_id_pk" PRIMARY KEY("org_id","post_id","org_user_id")
199
+ );
200
+ --> statement-breakpoint
201
+ CREATE TABLE "post_flags" (
202
+ "org_id" text NOT NULL,
203
+ "id" text NOT NULL,
204
+ "post_id" text NOT NULL,
205
+ "org_user_id" text NOT NULL,
206
+ "reason" text DEFAULT '' NOT NULL,
207
+ "resolved_at" timestamp with time zone,
208
+ "resolution" text,
209
+ "resolved_by" text,
210
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
211
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
212
+ CONSTRAINT "post_flags_org_id_id_pk" PRIMARY KEY("org_id","id"),
213
+ CONSTRAINT "post_flags_org_id_post_id_org_user_id_unique" UNIQUE("org_id","post_id","org_user_id"),
214
+ CONSTRAINT "post_flags_resolved_check" CHECK (("post_flags"."resolved_at" is null) = ("post_flags"."resolution" is null) and ("post_flags"."resolved_at" is null) = ("post_flags"."resolved_by" is null))
215
+ );
216
+ --> statement-breakpoint
217
+ CREATE TABLE "post_follows" (
218
+ "org_id" text NOT NULL,
219
+ "post_id" text NOT NULL,
220
+ "org_user_id" text NOT NULL,
221
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
222
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
223
+ CONSTRAINT "post_follows_org_id_post_id_org_user_id_pk" PRIMARY KEY("org_id","post_id","org_user_id")
224
+ );
225
+ --> statement-breakpoint
226
+ CREATE TABLE "post_reactions" (
227
+ "org_id" text NOT NULL,
228
+ "post_id" text NOT NULL,
229
+ "org_user_id" text NOT NULL,
230
+ "emoji" text NOT NULL,
231
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
232
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
233
+ CONSTRAINT "post_reactions_org_id_post_id_org_user_id_pk" PRIMARY KEY("org_id","post_id","org_user_id")
234
+ );
235
+ --> statement-breakpoint
236
+ CREATE TABLE "posts" (
237
+ "org_id" text NOT NULL,
238
+ "id" text NOT NULL,
239
+ "community_id" text NOT NULL,
240
+ "space_id" text NOT NULL,
241
+ "org_user_id" text NOT NULL,
242
+ "topic_id" text,
243
+ "title" text NOT NULL,
244
+ "body" text NOT NULL,
245
+ "extra" jsonb DEFAULT '{}'::jsonb NOT NULL,
246
+ "cover_asset_id" text,
247
+ "status" text DEFAULT 'draft' NOT NULL,
248
+ "scheduled_at" timestamp with time zone,
249
+ "published_at" timestamp with time zone,
250
+ "removed_by" text,
251
+ "pinned" boolean DEFAULT false NOT NULL,
252
+ "comments_closed" boolean,
253
+ "reactions_enabled" boolean,
254
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
255
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
256
+ CONSTRAINT "posts_org_id_id_pk" PRIMARY KEY("org_id","id"),
257
+ CONSTRAINT "posts_removed_by_check" CHECK (("posts"."status" = 'removed') = ("posts"."removed_by" is not null)),
258
+ CONSTRAINT "posts_scheduled_check" CHECK ("posts"."status" <> 'scheduled' or "posts"."scheduled_at" is not null)
259
+ );
260
+ --> statement-breakpoint
261
+ ALTER TABLE "content_items" DROP CONSTRAINT "content_items_type_check";--> statement-breakpoint
262
+ ALTER TABLE "automations" ADD COLUMN "filter" jsonb;--> statement-breakpoint
263
+ ALTER TABLE "automations" ADD COLUMN "source" text DEFAULT 'user' NOT NULL;--> statement-breakpoint
264
+ ALTER TABLE "comments" ADD COLUMN "post_id" text;--> statement-breakpoint
265
+ ALTER TABLE "comments" ADD COLUMN "community_id" text;--> statement-breakpoint
266
+ ALTER TABLE "communities" ADD CONSTRAINT "communities_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
267
+ ALTER TABLE "communities" ADD CONSTRAINT "communities_org_id_id_type_content_items_org_id_id_type_fk" FOREIGN KEY ("org_id","id","type") REFERENCES "public"."content_items"("org_id","id","type") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
268
+ ALTER TABLE "communities" ADD CONSTRAINT "communities_org_id_thumbnail_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","thumbnail_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
269
+ ALTER TABLE "space_links" ADD CONSTRAINT "space_links_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
270
+ ALTER TABLE "space_links" ADD CONSTRAINT "space_links_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
271
+ ALTER TABLE "space_links" ADD CONSTRAINT "space_links_org_id_content_id_content_items_org_id_id_fk" FOREIGN KEY ("org_id","content_id") REFERENCES "public"."content_items"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
272
+ ALTER TABLE "space_topics" ADD CONSTRAINT "space_topics_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
273
+ ALTER TABLE "space_topics" ADD CONSTRAINT "space_topics_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
274
+ ALTER TABLE "spaces" ADD CONSTRAINT "spaces_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
275
+ ALTER TABLE "spaces" ADD CONSTRAINT "spaces_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
276
+ ALTER TABLE "space_members" ADD CONSTRAINT "space_members_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
277
+ ALTER TABLE "space_members" ADD CONSTRAINT "space_members_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
278
+ ALTER TABLE "space_members" ADD CONSTRAINT "space_members_org_id_space_id_community_id_spaces_org_id_id_community_id_fk" FOREIGN KEY ("org_id","space_id","community_id") REFERENCES "public"."spaces"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
279
+ ALTER TABLE "space_members" ADD CONSTRAINT "space_members_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
280
+ ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
281
+ ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_image_asset_org_id_image_asset_id_assets_org_id_id_fk" FOREIGN KEY ("image_asset_org_id","image_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
282
+ ALTER TABLE "blocked_users" ADD CONSTRAINT "blocked_users_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
283
+ ALTER TABLE "blocked_users" ADD CONSTRAINT "blocked_users_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
284
+ ALTER TABLE "blocked_users" ADD CONSTRAINT "blocked_users_org_id_blocker_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","blocker_org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
285
+ ALTER TABLE "blocked_users" ADD CONSTRAINT "blocked_users_org_id_blocked_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","blocked_org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
286
+ ALTER TABLE "chat_users" ADD CONSTRAINT "chat_users_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
287
+ ALTER TABLE "chat_users" ADD CONSTRAINT "chat_users_org_id_chat_id_community_id_chats_org_id_id_community_id_fk" FOREIGN KEY ("org_id","chat_id","community_id") REFERENCES "public"."chats"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
288
+ ALTER TABLE "chat_users" ADD CONSTRAINT "chat_users_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
289
+ ALTER TABLE "chats" ADD CONSTRAINT "chats_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
290
+ ALTER TABLE "chats" ADD CONSTRAINT "chats_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
291
+ ALTER TABLE "chats" ADD CONSTRAINT "chats_org_id_created_by_org_users_org_id_id_fk" FOREIGN KEY ("org_id","created_by") REFERENCES "public"."org_users"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
292
+ ALTER TABLE "chats" ADD CONSTRAINT "chats_org_id_locked_by_org_users_org_id_id_fk" FOREIGN KEY ("org_id","locked_by") REFERENCES "public"."org_users"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
293
+ ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
294
+ ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_org_id_message_id_community_id_messages_org_id_id_community_id_fk" FOREIGN KEY ("org_id","message_id","community_id") REFERENCES "public"."messages"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
295
+ ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_org_id_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
296
+ ALTER TABLE "message_flags" ADD CONSTRAINT "message_flags_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
297
+ ALTER TABLE "message_flags" ADD CONSTRAINT "message_flags_org_id_message_id_community_id_messages_org_id_id_community_id_fk" FOREIGN KEY ("org_id","message_id","community_id") REFERENCES "public"."messages"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
298
+ ALTER TABLE "message_flags" ADD CONSTRAINT "message_flags_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 no action ON UPDATE no action;--> statement-breakpoint
299
+ ALTER TABLE "message_reactions" ADD CONSTRAINT "message_reactions_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
300
+ ALTER TABLE "message_reactions" ADD CONSTRAINT "message_reactions_org_id_message_id_community_id_messages_org_id_id_community_id_fk" FOREIGN KEY ("org_id","message_id","community_id") REFERENCES "public"."messages"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
301
+ ALTER TABLE "message_reactions" ADD CONSTRAINT "message_reactions_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
302
+ ALTER TABLE "messages" ADD CONSTRAINT "messages_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
303
+ ALTER TABLE "messages" ADD CONSTRAINT "messages_org_id_chat_id_community_id_chats_org_id_id_community_id_fk" FOREIGN KEY ("org_id","chat_id","community_id") REFERENCES "public"."chats"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
304
+ ALTER TABLE "messages" ADD CONSTRAINT "messages_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 no action ON UPDATE no action;--> statement-breakpoint
305
+ ALTER TABLE "messages" ADD CONSTRAINT "messages_org_id_reply_to_id_messages_org_id_id_fk" FOREIGN KEY ("org_id","reply_to_id") REFERENCES "public"."messages"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
306
+ ALTER TABLE "post_bookmarks" ADD CONSTRAINT "post_bookmarks_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
307
+ ALTER TABLE "post_bookmarks" ADD CONSTRAINT "post_bookmarks_org_id_post_id_posts_org_id_id_fk" FOREIGN KEY ("org_id","post_id") REFERENCES "public"."posts"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
308
+ ALTER TABLE "post_bookmarks" ADD CONSTRAINT "post_bookmarks_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
309
+ ALTER TABLE "post_flags" ADD CONSTRAINT "post_flags_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
310
+ ALTER TABLE "post_flags" ADD CONSTRAINT "post_flags_org_id_post_id_posts_org_id_id_fk" FOREIGN KEY ("org_id","post_id") REFERENCES "public"."posts"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
311
+ ALTER TABLE "post_flags" ADD CONSTRAINT "post_flags_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 no action ON UPDATE no action;--> statement-breakpoint
312
+ ALTER TABLE "post_follows" ADD CONSTRAINT "post_follows_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
313
+ ALTER TABLE "post_follows" ADD CONSTRAINT "post_follows_org_id_post_id_posts_org_id_id_fk" FOREIGN KEY ("org_id","post_id") REFERENCES "public"."posts"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
314
+ ALTER TABLE "post_follows" ADD CONSTRAINT "post_follows_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
315
+ ALTER TABLE "post_reactions" ADD CONSTRAINT "post_reactions_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
316
+ ALTER TABLE "post_reactions" ADD CONSTRAINT "post_reactions_org_id_post_id_posts_org_id_id_fk" FOREIGN KEY ("org_id","post_id") REFERENCES "public"."posts"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
317
+ ALTER TABLE "post_reactions" ADD CONSTRAINT "post_reactions_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
318
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
319
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_org_id_space_id_community_id_spaces_org_id_id_community_id_fk" FOREIGN KEY ("org_id","space_id","community_id") REFERENCES "public"."spaces"("org_id","id","community_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
320
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_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 no action ON UPDATE no action;--> statement-breakpoint
321
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_org_id_space_id_topic_id_space_topics_org_id_space_id_id_fk" FOREIGN KEY ("org_id","space_id","topic_id") REFERENCES "public"."space_topics"("org_id","space_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
322
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_org_id_cover_asset_id_assets_org_id_id_fk" FOREIGN KEY ("org_id","cover_asset_id") REFERENCES "public"."assets"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
323
+ ALTER TABLE "posts" ADD CONSTRAINT "posts_org_id_removed_by_org_users_org_id_id_fk" FOREIGN KEY ("org_id","removed_by") REFERENCES "public"."org_users"("org_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
324
+ CREATE INDEX "spaces_order_idx" ON "spaces" USING btree ("org_id","community_id","seq");--> statement-breakpoint
325
+ CREATE INDEX "space_members_space_idx" ON "space_members" USING btree ("org_id","space_id","status");--> statement-breakpoint
326
+ CREATE INDEX "space_members_community_idx" ON "space_members" USING btree ("org_id","community_id");--> statement-breakpoint
327
+ CREATE INDEX "blocked_users_blocked_idx" ON "blocked_users" USING btree ("org_id","community_id","blocked_org_user_id");--> statement-breakpoint
328
+ CREATE INDEX "chat_users_user_idx" ON "chat_users" USING btree ("org_id","community_id","org_user_id");--> statement-breakpoint
329
+ CREATE INDEX "message_flags_open_idx" ON "message_flags" USING btree ("org_id","community_id","message_id","resolved_at");--> statement-breakpoint
330
+ CREATE INDEX "messages_chat_idx" ON "messages" USING btree ("org_id","chat_id","created_at");--> statement-breakpoint
331
+ CREATE INDEX "post_flags_open_idx" ON "post_flags" USING btree ("org_id","post_id","resolved_at");--> statement-breakpoint
332
+ CREATE INDEX "posts_feed_idx" ON "posts" USING btree ("org_id","space_id","status","pinned" desc,"published_at" desc);--> statement-breakpoint
333
+ CREATE INDEX "posts_due_idx" ON "posts" USING btree ("org_id","status","scheduled_at");--> statement-breakpoint
334
+ CREATE INDEX "posts_author_idx" ON "posts" USING btree ("org_id","org_user_id");--> statement-breakpoint
335
+ ALTER TABLE "comments" ADD CONSTRAINT "comments_org_id_post_id_posts_org_id_id_fk" FOREIGN KEY ("org_id","post_id") REFERENCES "public"."posts"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
336
+ ALTER TABLE "comments" ADD CONSTRAINT "comments_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
337
+ CREATE INDEX "comments_post_idx" ON "comments" USING btree ("org_id","post_id","status","created_at");--> statement-breakpoint
338
+ ALTER TABLE "content_items" ADD CONSTRAINT "content_items_type_check" CHECK ("content_items"."type" in ('course', 'download', 'community'));--> statement-breakpoint
339
+ ALTER TABLE "comments" ADD CONSTRAINT "comments_target_check" CHECK (num_nonnulls("comments"."activity_id", "comments"."post_id") = 1);--> statement-breakpoint
340
+ ALTER TABLE "comments" ADD CONSTRAINT "comments_community_check" CHECK ("comments"."post_id" is null or "comments"."community_id" is not null);
@@ -0,0 +1 @@
1
+ ALTER TABLE "assets" ADD COLUMN "source" text DEFAULT 'library' NOT NULL;
@@ -0,0 +1,12 @@
1
+ CREATE TABLE "entitlement_notices" (
2
+ "org_id" text NOT NULL,
3
+ "entitlement_id" text NOT NULL,
4
+ "kind" text NOT NULL,
5
+ "community_id" text DEFAULT '' NOT NULL,
6
+ "notified_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ CONSTRAINT "entitlement_notices_org_id_entitlement_id_kind_community_id_pk" PRIMARY KEY("org_id","entitlement_id","kind","community_id")
8
+ );
9
+ --> statement-breakpoint
10
+ ALTER TABLE "entitlement_notices" ADD CONSTRAINT "entitlement_notices_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
11
+ ALTER TABLE "entitlement_notices" ADD CONSTRAINT "entitlement_notices_org_id_entitlement_id_entitlements_org_id_id_fk" FOREIGN KEY ("org_id","entitlement_id") REFERENCES "public"."entitlements"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
12
+ CREATE UNIQUE INDEX "automations_system_seed_idx" ON "automations" USING btree ("org_id","name",coalesce("filter"->>'communityId', '')) WHERE "automations"."source" = 'system';
@@ -0,0 +1,24 @@
1
+ CREATE TABLE "entitlement_ending_soon_notices" (
2
+ "org_id" text NOT NULL,
3
+ "entitlement_id" text NOT NULL,
4
+ "community_id" text NOT NULL,
5
+ "expires_at" timestamp with time zone NOT NULL,
6
+ "notified_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ CONSTRAINT "entitlement_ending_soon_notices_org_id_entitlement_id_community_id_expires_at_pk" PRIMARY KEY("org_id","entitlement_id","community_id","expires_at")
8
+ );
9
+ --> statement-breakpoint
10
+ CREATE TABLE "entitlement_expiry_notices" (
11
+ "org_id" text NOT NULL,
12
+ "entitlement_id" text NOT NULL,
13
+ "expires_at" timestamp with time zone NOT NULL,
14
+ "notified_at" timestamp with time zone DEFAULT now() NOT NULL,
15
+ CONSTRAINT "entitlement_expiry_notices_org_id_entitlement_id_expires_at_pk" PRIMARY KEY("org_id","entitlement_id","expires_at")
16
+ );
17
+ --> statement-breakpoint
18
+ ALTER TABLE "entitlement_ending_soon_notices" ADD CONSTRAINT "entitlement_ending_soon_notices_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
19
+ ALTER TABLE "entitlement_ending_soon_notices" ADD CONSTRAINT "entitlement_ending_soon_notices_org_id_entitlement_id_entitlements_org_id_id_fk" FOREIGN KEY ("org_id","entitlement_id") REFERENCES "public"."entitlements"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
20
+ ALTER TABLE "entitlement_ending_soon_notices" ADD CONSTRAINT "entitlement_ending_soon_notices_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
21
+ ALTER TABLE "entitlement_expiry_notices" ADD CONSTRAINT "entitlement_expiry_notices_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
22
+ ALTER TABLE "entitlement_expiry_notices" ADD CONSTRAINT "entitlement_expiry_notices_org_id_entitlement_id_entitlements_org_id_id_fk" FOREIGN KEY ("org_id","entitlement_id") REFERENCES "public"."entitlements"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
23
+ CREATE INDEX "post_bookmarks_user_idx" ON "post_bookmarks" USING btree ("org_id","org_user_id","created_at");--> statement-breakpoint
24
+ DROP TABLE "entitlement_notices" CASCADE;