@headless-lms/adapter-db 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -6
- package/dist/index.js +12 -6
- package/dist/repositories/admin.d.ts +23 -0
- package/dist/repositories/admin.js +393 -0
- package/dist/repositories/admin.js.map +1 -0
- package/dist/repositories/assets.d.ts +6 -3
- package/dist/repositories/assets.js +46 -9
- package/dist/repositories/assets.js.map +1 -1
- package/dist/repositories/automations.d.ts +5 -2
- package/dist/repositories/automations.js +29 -2
- package/dist/repositories/automations.js.map +1 -1
- package/dist/repositories/chats.d.ts +55 -0
- package/dist/repositories/chats.js +469 -0
- package/dist/repositories/chats.js.map +1 -0
- package/dist/repositories/content.d.ts +24 -1
- package/dist/repositories/content.js +316 -9
- package/dist/repositories/content.js.map +1 -1
- package/dist/repositories/devices.d.ts +17 -0
- package/dist/repositories/devices.js +75 -0
- package/dist/repositories/devices.js.map +1 -0
- package/dist/repositories/digest-runs.d.ts +14 -0
- package/dist/repositories/digest-runs.js +39 -0
- package/dist/repositories/digest-runs.js.map +1 -0
- package/dist/repositories/discussion.d.ts +16 -4
- package/dist/repositories/discussion.js +78 -18
- package/dist/repositories/discussion.js.map +1 -1
- package/dist/repositories/entitlements.d.ts +31 -9
- package/dist/repositories/entitlements.js +213 -17
- package/dist/repositories/entitlements.js.map +1 -1
- package/dist/repositories/grant-covers.d.ts +20 -0
- package/dist/repositories/grant-covers.js +55 -0
- package/dist/repositories/grant-covers.js.map +1 -0
- package/dist/repositories/identity.d.ts +4 -2
- package/dist/repositories/identity.js +32 -1
- package/dist/repositories/identity.js.map +1 -1
- package/dist/repositories/inserted-row.d.ts +5 -0
- package/dist/repositories/inserted-row.js +7 -0
- package/dist/repositories/inserted-row.js.map +1 -0
- package/dist/repositories/member.d.ts +16 -0
- package/dist/repositories/member.js +63 -0
- package/dist/repositories/member.js.map +1 -0
- package/dist/repositories/members.js +2 -2
- package/dist/repositories/members.js.map +1 -1
- package/dist/repositories/mentions.d.ts +17 -0
- package/dist/repositories/mentions.js +55 -0
- package/dist/repositories/mentions.js.map +1 -0
- package/dist/repositories/notification-settings.d.ts +19 -0
- package/dist/repositories/notification-settings.js +67 -0
- package/dist/repositories/notification-settings.js.map +1 -0
- package/dist/repositories/notifications.d.ts +30 -0
- package/dist/repositories/notifications.js +178 -0
- package/dist/repositories/notifications.js.map +1 -0
- package/dist/repositories/org-user-profile.d.ts +214 -1
- package/dist/repositories/org-user-profile.js +23 -2
- package/dist/repositories/org-user-profile.js.map +1 -1
- package/dist/repositories/organizations.d.ts +4 -2
- package/dist/repositories/organizations.js +23 -8
- package/dist/repositories/organizations.js.map +1 -1
- package/dist/repositories/pg-errors.js +3 -1
- package/dist/repositories/pg-errors.js.map +1 -1
- package/dist/repositories/posts.d.ts +35 -0
- package/dist/repositories/posts.js +252 -0
- package/dist/repositories/posts.js.map +1 -0
- package/dist/repositories/subscriptions.d.ts +18 -0
- package/dist/repositories/subscriptions.js +72 -0
- package/dist/repositories/subscriptions.js.map +1 -0
- package/dist/schema/assets.d.ts +19 -2
- package/dist/schema/assets.js +10 -4
- package/dist/schema/assets.js.map +1 -1
- package/dist/schema/automations.d.ts +545 -2
- package/dist/schema/automations.js +73 -3
- package/dist/schema/automations.js.map +1 -1
- package/dist/schema/better-auth.d.ts +1613 -238
- package/dist/schema/better-auth.js +107 -22
- package/dist/schema/better-auth.js.map +1 -1
- package/dist/schema/content.d.ts +642 -5
- package/dist/schema/content.js +119 -10
- package/dist/schema/content.js.map +1 -1
- package/dist/schema/discussion.d.ts +2182 -42
- package/dist/schema/discussion.js +461 -11
- package/dist/schema/discussion.js.map +1 -1
- package/dist/schema/entitlements.d.ts +432 -1
- package/dist/schema/entitlements.js +109 -4
- package/dist/schema/entitlements.js.map +1 -1
- package/dist/schema/identity.d.ts +517 -1
- package/dist/schema/identity.js +76 -2
- package/dist/schema/identity.js.map +1 -1
- package/dist/schema/index.d.ts +7 -7
- package/dist/schema/index.js +35 -8
- package/dist/schema/organizations.d.ts +4 -4
- package/dist/schema/organizations.js +2 -0
- package/dist/schema/organizations.js.map +1 -1
- package/drizzle/0003_community.sql +340 -0
- package/drizzle/0004_assets_sources.sql +1 -0
- package/drizzle/0005_notices_and_seed_index.sql +12 -0
- package/drizzle/0006_community_review_fixes.sql +24 -0
- package/drizzle/0007_notifications.sql +37 -0
- package/drizzle/0008_content_access.sql +13 -0
- package/drizzle/0009_community_indexes.sql +56 -0
- package/drizzle/0010_mcp_access.sql +114 -0
- package/drizzle/0011_digest_runs.sql +8 -0
- package/drizzle/0012_subscriptions.sql +16 -0
- package/drizzle/0013_mentions.sql +10 -0
- package/drizzle/0014_notification_settings_devices.sql +36 -0
- package/drizzle/0015_automations_drop_source.sql +2 -0
- package/drizzle/0016_notifications_automations.sql +48 -0
- package/drizzle/meta/0003_snapshot.json +7061 -0
- package/drizzle/meta/0004_snapshot.json +7068 -0
- package/drizzle/meta/0005_snapshot.json +7180 -0
- package/drizzle/meta/0006_snapshot.json +7298 -0
- package/drizzle/meta/0007_snapshot.json +7620 -0
- package/drizzle/meta/0008_snapshot.json +7666 -0
- package/drizzle/meta/0009_snapshot.json +8185 -0
- package/drizzle/meta/0010_snapshot.json +8813 -0
- package/drizzle/meta/0011_snapshot.json +8868 -0
- package/drizzle/meta/0012_snapshot.json +8873 -0
- package/drizzle/meta/0013_snapshot.json +8943 -0
- package/drizzle/meta/0014_snapshot.json +9305 -0
- package/drizzle/meta/0015_snapshot.json +9270 -0
- package/drizzle/meta/0016_snapshot.json +9230 -0
- package/drizzle/meta/_journal.json +99 -1
- package/package.json +2 -2
- package/dist/repositories/course-analytics.d.ts +0 -15
- package/dist/repositories/course-analytics.js +0 -137
- package/dist/repositories/course-analytics.js.map +0 -1
- package/dist/repositories/dashboard.d.ts +0 -14
- package/dist/repositories/dashboard.js +0 -57
- package/dist/repositories/dashboard.js.map +0 -1
- package/dist/repositories/learn.d.ts +0 -19
- package/dist/repositories/learn.js +0 -56
- package/dist/repositories/learn.js.map +0 -1
- package/dist/repositories/students.d.ts +0 -16
- package/dist/repositories/students.js +0 -160
- package/dist/repositories/students.js.map +0 -1
package/dist/schema/index.js
CHANGED
|
@@ -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 {
|
|
3
|
+
import { activities, activityAssets, bundleItems, bundles, communities, contentItems, courses, downloadAssets, downloads, modules, spaceLinks, spaceTopics, spaces } from "./content.js";
|
|
4
|
+
import { devices, notificationSettings, userProfiles, users } from "./identity.js";
|
|
5
|
+
import { invites, orgUsers, organizations } from "./organizations.js";
|
|
6
|
+
import { contentAccess, entitlementEndingSoonNotices, entitlementExpiryNotices, entitlements, spaceMembers } from "./entitlements.js";
|
|
7
7
|
import { progressRecords } from "./progress.js";
|
|
8
8
|
import { credentials } from "./credentials.js";
|
|
9
9
|
import { connections } from "./integrations.js";
|
|
10
10
|
import { eventOutbox } from "./outbox.js";
|
|
11
|
-
import { automationRuns, automations } from "./automations.js";
|
|
11
|
+
import { automationRuns, automations, notificationDeliveries, notifications } from "./automations.js";
|
|
12
12
|
import { settings } from "./settings.js";
|
|
13
|
-
import {
|
|
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,
|
|
@@ -18,28 +18,55 @@ 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,
|
|
35
|
+
devices: () => devices,
|
|
36
|
+
digestRuns: () => digestRuns,
|
|
30
37
|
downloadAssets: () => downloadAssets,
|
|
31
38
|
downloads: () => downloads,
|
|
39
|
+
entitlementEndingSoonNotices: () => entitlementEndingSoonNotices,
|
|
40
|
+
entitlementExpiryNotices: () => entitlementExpiryNotices,
|
|
32
41
|
entitlements: () => entitlements,
|
|
33
42
|
eventOutbox: () => eventOutbox,
|
|
34
43
|
invites: () => invites,
|
|
44
|
+
mentions: () => mentions,
|
|
45
|
+
messageAttachments: () => messageAttachments,
|
|
46
|
+
messageFlags: () => messageFlags,
|
|
47
|
+
messageReactions: () => messageReactions,
|
|
48
|
+
messages: () => messages,
|
|
35
49
|
modules: () => modules,
|
|
50
|
+
notificationDeliveries: () => notificationDeliveries,
|
|
51
|
+
notificationSettings: () => notificationSettings,
|
|
52
|
+
notifications: () => notifications,
|
|
36
53
|
orgUsers: () => orgUsers,
|
|
37
54
|
organizations: () => organizations,
|
|
55
|
+
postBookmarks: () => postBookmarks,
|
|
56
|
+
postFlags: () => postFlags,
|
|
57
|
+
postReactions: () => postReactions,
|
|
58
|
+
posts: () => posts,
|
|
38
59
|
progressRecords: () => progressRecords,
|
|
39
60
|
settings: () => settings,
|
|
61
|
+
spaceLinks: () => spaceLinks,
|
|
62
|
+
spaceMembers: () => spaceMembers,
|
|
63
|
+
spaceTopics: () => spaceTopics,
|
|
64
|
+
spaces: () => spaces,
|
|
65
|
+
subscriptions: () => subscriptions,
|
|
66
|
+
userProfiles: () => userProfiles,
|
|
40
67
|
users: () => users
|
|
41
68
|
});
|
|
42
69
|
//#endregion
|
|
43
|
-
export { activities, activityAssets, assets, automationRuns, automations, bundleItems, bundles,
|
|
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 };
|
|
44
71
|
|
|
45
72
|
//# 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\", {
|
|
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;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
CREATE TABLE "notification_preferences" (
|
|
2
|
+
"org_id" text NOT NULL,
|
|
3
|
+
"user_id" text NOT NULL,
|
|
4
|
+
"kind" text NOT NULL,
|
|
5
|
+
"in_app" boolean NOT NULL,
|
|
6
|
+
"email" boolean NOT NULL,
|
|
7
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
8
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
9
|
+
CONSTRAINT "notification_preferences_org_id_user_id_kind_pk" PRIMARY KEY("org_id","user_id","kind")
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE TABLE "notifications" (
|
|
13
|
+
"org_id" text NOT NULL,
|
|
14
|
+
"id" text NOT NULL,
|
|
15
|
+
"user_id" text NOT NULL,
|
|
16
|
+
"kind" text NOT NULL,
|
|
17
|
+
"actor_org_user_id" text,
|
|
18
|
+
"community_id" text,
|
|
19
|
+
"space_id" text,
|
|
20
|
+
"post_id" text,
|
|
21
|
+
"comment_id" text,
|
|
22
|
+
"chat_id" text,
|
|
23
|
+
"message_id" text,
|
|
24
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
25
|
+
"read_at" timestamp with time zone,
|
|
26
|
+
CONSTRAINT "notifications_org_id_id_pk" PRIMARY KEY("org_id","id")
|
|
27
|
+
);
|
|
28
|
+
--> statement-breakpoint
|
|
29
|
+
ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_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 "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
|
|
31
|
+
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
|
|
32
|
+
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
|
|
33
|
+
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_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
|
|
34
|
+
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_comment_id_comments_org_id_id_fk" FOREIGN KEY ("org_id","comment_id") REFERENCES "public"."comments"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
35
|
+
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_chat_id_chats_org_id_id_fk" FOREIGN KEY ("org_id","chat_id") REFERENCES "public"."chats"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
36
|
+
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_message_id_messages_org_id_id_fk" FOREIGN KEY ("org_id","message_id") REFERENCES "public"."messages"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
37
|
+
CREATE INDEX "notifications_list_idx" ON "notifications" USING btree ("org_id","user_id","read_at","created_at" desc);
|