@headless-lms/adapter-db 0.1.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.
- package/README.md +79 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +8 -6
- package/dist/migrate.js.map +1 -1
- 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 -2
- package/dist/repositories/assets.js +53 -9
- package/dist/repositories/assets.js.map +1 -1
- package/dist/repositories/automations.d.ts +12 -6
- package/dist/repositories/automations.js +79 -11
- package/dist/repositories/automations.js.map +1 -1
- package/dist/repositories/chats.d.ts +55 -0
- package/dist/repositories/chats.js +454 -0
- package/dist/repositories/chats.js.map +1 -0
- package/dist/repositories/content.d.ts +44 -7
- package/dist/repositories/content.js +458 -24
- package/dist/repositories/content.js.map +1 -1
- package/dist/repositories/credentials.js +2 -0
- package/dist/repositories/credentials.js.map +1 -1
- package/dist/repositories/discussion.d.ts +11 -4
- package/dist/repositories/discussion.js +72 -15
- package/dist/repositories/discussion.js.map +1 -1
- package/dist/repositories/entitlements.d.ts +36 -10
- package/dist/repositories/entitlements.js +238 -23
- 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 +34 -1
- package/dist/repositories/identity.js.map +1 -1
- package/dist/repositories/integrations.d.ts +1 -1
- package/dist/repositories/integrations.js +2 -0
- package/dist/repositories/integrations.js.map +1 -1
- 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 +4 -2
- package/dist/repositories/members.js.map +1 -1
- package/dist/repositories/notifications.d.ts +23 -0
- package/dist/repositories/notifications.js +70 -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 +6 -7
- package/dist/repositories/organizations.js +45 -52
- package/dist/repositories/organizations.js.map +1 -1
- package/dist/repositories/outbox.js +3 -0
- package/dist/repositories/outbox.js.map +1 -1
- package/dist/repositories/pg-errors.d.ts +53 -5
- package/dist/repositories/pg-errors.js +99 -8
- package/dist/repositories/pg-errors.js.map +1 -1
- package/dist/repositories/posts.d.ts +39 -0
- package/dist/repositories/posts.js +255 -0
- package/dist/repositories/posts.js.map +1 -0
- package/dist/repositories/progress.d.ts +1 -1
- package/dist/repositories/progress.js +3 -0
- package/dist/repositories/progress.js.map +1 -1
- package/dist/repositories/settings.js +2 -0
- package/dist/repositories/settings.js.map +1 -1
- package/dist/schema/assets.d.ts +36 -2
- package/dist/schema/assets.js +12 -5
- package/dist/schema/assets.js.map +1 -1
- package/dist/schema/automations.d.ts +123 -8
- package/dist/schema/automations.js +11 -4
- 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 +909 -22
- package/dist/schema/content.js +157 -13
- package/dist/schema/content.js.map +1 -1
- package/dist/schema/credentials.js +1 -1
- package/dist/schema/credentials.js.map +1 -1
- package/dist/schema/discussion.d.ts +2079 -55
- package/dist/schema/discussion.js +430 -13
- package/dist/schema/discussion.js.map +1 -1
- package/dist/schema/entitlements.d.ts +484 -2
- package/dist/schema/entitlements.js +121 -6
- package/dist/schema/entitlements.js.map +1 -1
- package/dist/schema/identity.d.ts +517 -1
- package/dist/schema/identity.js +118 -2
- package/dist/schema/identity.js.map +1 -1
- package/dist/schema/index.d.ts +6 -6
- package/dist/schema/index.js +32 -7
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/integrations.js +1 -1
- package/dist/schema/integrations.js.map +1 -1
- package/dist/schema/organizations.d.ts +21 -4
- package/dist/schema/organizations.js +4 -1
- package/dist/schema/organizations.js.map +1 -1
- package/dist/schema/outbox.d.ts +17 -0
- package/dist/schema/outbox.js +1 -0
- package/dist/schema/outbox.js.map +1 -1
- package/dist/schema/progress.d.ts +17 -0
- package/dist/schema/progress.js +1 -0
- package/dist/schema/progress.js.map +1 -1
- package/dist/schema/settings.js.map +1 -1
- package/dist/unit-of-work.js +7 -2
- package/dist/unit-of-work.js.map +1 -1
- package/drizzle/0000_baseline.sql +0 -1
- package/drizzle/0001_new_sentry.sql +43 -0
- package/drizzle/0002_automation_kinds.sql +7 -0
- 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/meta/0000_snapshot.json +167 -597
- package/drizzle/meta/0001_snapshot.json +3769 -0
- package/drizzle/meta/0002_snapshot.json +3770 -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/_journal.json +71 -1
- package/package.json +3 -2
- package/dist/repositories/dashboard.d.ts +0 -14
- package/dist/repositories/dashboard.js +0 -55
- package/dist/repositories/dashboard.js.map +0 -1
- package/dist/repositories/learn.d.ts +0 -19
- package/dist/repositories/learn.js +0 -54
- package/dist/repositories/learn.js.map +0 -1
- package/dist/repositories/students.d.ts +0 -15
- package/dist/repositories/students.js +0 -83
- package/dist/repositories/students.js.map +0 -1
|
@@ -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);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
CREATE VIEW "public"."content_access" AS (
|
|
2
|
+
select e.org_id, e.org_user_id, e.content_id, e.id as entitlement_id, e.granted_at, e.expires_at
|
|
3
|
+
from entitlements e
|
|
4
|
+
where e.content_id is not null
|
|
5
|
+
and e.status = 'active'
|
|
6
|
+
and (e.expires_at is null or e.expires_at > now())
|
|
7
|
+
union all
|
|
8
|
+
select e.org_id, e.org_user_id, bi.content_id, e.id as entitlement_id, e.granted_at, e.expires_at
|
|
9
|
+
from entitlements e
|
|
10
|
+
join bundle_items bi on bi.org_id = e.org_id and bi.bundle_id = e.bundle_id
|
|
11
|
+
where e.status = 'active'
|
|
12
|
+
and (e.expires_at is null or e.expires_at > now())
|
|
13
|
+
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
ALTER TABLE "chats" DROP CONSTRAINT "chats_locked_check";--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "comments" DROP CONSTRAINT "comments_removed_by_check";--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "posts" DROP CONSTRAINT "posts_removed_by_check";--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "chats" DROP CONSTRAINT "chats_org_id_created_by_org_users_org_id_id_fk";
|
|
5
|
+
--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "chats" DROP CONSTRAINT "chats_org_id_locked_by_org_users_org_id_id_fk";
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
ALTER TABLE "comment_flags" DROP CONSTRAINT "comment_flags_org_id_org_user_id_org_users_org_id_id_fk";
|
|
9
|
+
--> statement-breakpoint
|
|
10
|
+
ALTER TABLE "comment_reactions" DROP CONSTRAINT "comment_reactions_org_id_org_user_id_org_users_org_id_id_fk";
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
ALTER TABLE "comments" DROP CONSTRAINT "comments_org_id_removed_by_org_users_org_id_id_fk";
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
ALTER TABLE "message_flags" DROP CONSTRAINT "message_flags_org_id_org_user_id_org_users_org_id_id_fk";
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "post_flags" DROP CONSTRAINT "post_flags_org_id_org_user_id_org_users_org_id_id_fk";
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
ALTER TABLE "posts" DROP CONSTRAINT "posts_org_id_removed_by_org_users_org_id_id_fk";
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
DROP INDEX "posts_author_idx";--> statement-breakpoint
|
|
21
|
+
ALTER TABLE "chats" ALTER COLUMN "created_by" DROP NOT NULL;--> statement-breakpoint
|
|
22
|
+
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 set null ("created_by") ON UPDATE no action;--> statement-breakpoint
|
|
23
|
+
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 set null ("locked_by") ON UPDATE no action;--> statement-breakpoint
|
|
24
|
+
ALTER TABLE "comment_flags" ADD CONSTRAINT "comment_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 cascade ON UPDATE no action;--> statement-breakpoint
|
|
25
|
+
ALTER TABLE "comment_reactions" ADD CONSTRAINT "comment_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
|
|
26
|
+
ALTER TABLE "comments" ADD CONSTRAINT "comments_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 set null ("removed_by") ON UPDATE no action;--> statement-breakpoint
|
|
27
|
+
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 cascade ON UPDATE no action;--> statement-breakpoint
|
|
28
|
+
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 cascade ON UPDATE no action;--> statement-breakpoint
|
|
29
|
+
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 set null ("removed_by") ON UPDATE no action;--> statement-breakpoint
|
|
30
|
+
CREATE INDEX "activity_assets_asset_idx" ON "activity_assets" USING btree ("org_id","asset_id");--> statement-breakpoint
|
|
31
|
+
CREATE INDEX "bundle_items_content_idx" ON "bundle_items" USING btree ("org_id","content_id");--> statement-breakpoint
|
|
32
|
+
CREATE INDEX "communities_thumbnail_idx" ON "communities" USING btree ("org_id","thumbnail_asset_id");--> statement-breakpoint
|
|
33
|
+
CREATE INDEX "courses_thumbnail_idx" ON "courses" USING btree ("org_id","thumbnail_asset_id");--> statement-breakpoint
|
|
34
|
+
CREATE INDEX "download_assets_asset_idx" ON "download_assets" USING btree ("org_id","asset_id");--> statement-breakpoint
|
|
35
|
+
CREATE INDEX "downloads_thumbnail_idx" ON "downloads" USING btree ("org_id","thumbnail_asset_id");--> statement-breakpoint
|
|
36
|
+
CREATE INDEX "space_links_content_idx" ON "space_links" USING btree ("org_id","content_id");--> statement-breakpoint
|
|
37
|
+
CREATE INDEX "entitlements_content_idx" ON "entitlements" USING btree ("org_id","content_id");--> statement-breakpoint
|
|
38
|
+
CREATE INDEX "entitlements_bundle_idx" ON "entitlements" USING btree ("org_id","bundle_id");--> statement-breakpoint
|
|
39
|
+
CREATE INDEX "notifications_feed_idx" ON "notifications" USING btree ("org_id","user_id","created_at" desc,"id" desc);--> statement-breakpoint
|
|
40
|
+
CREATE INDEX "notifications_community_idx" ON "notifications" USING btree ("org_id","community_id");--> statement-breakpoint
|
|
41
|
+
CREATE INDEX "notifications_space_idx" ON "notifications" USING btree ("org_id","space_id");--> statement-breakpoint
|
|
42
|
+
CREATE INDEX "notifications_post_idx" ON "notifications" USING btree ("org_id","post_id");--> statement-breakpoint
|
|
43
|
+
CREATE INDEX "notifications_comment_idx" ON "notifications" USING btree ("org_id","comment_id");--> statement-breakpoint
|
|
44
|
+
CREATE INDEX "notifications_chat_idx" ON "notifications" USING btree ("org_id","chat_id");--> statement-breakpoint
|
|
45
|
+
CREATE INDEX "notifications_message_idx" ON "notifications" USING btree ("org_id","message_id");--> statement-breakpoint
|
|
46
|
+
CREATE INDEX "user_profiles_image_idx" ON "user_profiles" USING btree ("image_asset_org_id","image_asset_id");--> statement-breakpoint
|
|
47
|
+
CREATE INDEX "assets_member_uploads_idx" ON "assets" USING btree ("org_id","created_at") WHERE "assets"."source" = 'member';--> statement-breakpoint
|
|
48
|
+
CREATE INDEX "comments_community_idx" ON "comments" USING btree ("org_id","community_id");--> statement-breakpoint
|
|
49
|
+
CREATE INDEX "comments_parent_idx" ON "comments" USING btree ("org_id","parent_id","created_at");--> statement-breakpoint
|
|
50
|
+
CREATE INDEX "message_attachments_asset_idx" ON "message_attachments" USING btree ("org_id","asset_id");--> statement-breakpoint
|
|
51
|
+
CREATE INDEX "messages_reply_idx" ON "messages" USING btree ("org_id","reply_to_id");--> statement-breakpoint
|
|
52
|
+
CREATE INDEX "posts_cover_asset_idx" ON "posts" USING btree ("org_id","cover_asset_id");--> statement-breakpoint
|
|
53
|
+
CREATE INDEX "posts_author_idx" ON "posts" USING btree ("org_id","org_user_id","created_at");--> statement-breakpoint
|
|
54
|
+
ALTER TABLE "chats" ADD CONSTRAINT "chats_locked_check" CHECK ("chats"."locked_by" is null or "chats"."locked_at" is not null);--> statement-breakpoint
|
|
55
|
+
ALTER TABLE "comments" ADD CONSTRAINT "comments_removed_by_check" CHECK ("comments"."removed_by" is null or "comments"."status" = 'removed');--> statement-breakpoint
|
|
56
|
+
ALTER TABLE "posts" ADD CONSTRAINT "posts_removed_by_check" CHECK ("posts"."removed_by" is null or "posts"."status" = 'removed');
|