@headless-lms/adapter-db 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/index.d.ts +12 -6
  2. package/dist/index.js +12 -6
  3. package/dist/repositories/admin.d.ts +23 -0
  4. package/dist/repositories/admin.js +393 -0
  5. package/dist/repositories/admin.js.map +1 -0
  6. package/dist/repositories/assets.d.ts +6 -3
  7. package/dist/repositories/assets.js +46 -9
  8. package/dist/repositories/assets.js.map +1 -1
  9. package/dist/repositories/automations.d.ts +5 -2
  10. package/dist/repositories/automations.js +29 -2
  11. package/dist/repositories/automations.js.map +1 -1
  12. package/dist/repositories/chats.d.ts +55 -0
  13. package/dist/repositories/chats.js +469 -0
  14. package/dist/repositories/chats.js.map +1 -0
  15. package/dist/repositories/content.d.ts +24 -1
  16. package/dist/repositories/content.js +316 -9
  17. package/dist/repositories/content.js.map +1 -1
  18. package/dist/repositories/devices.d.ts +17 -0
  19. package/dist/repositories/devices.js +75 -0
  20. package/dist/repositories/devices.js.map +1 -0
  21. package/dist/repositories/digest-runs.d.ts +14 -0
  22. package/dist/repositories/digest-runs.js +39 -0
  23. package/dist/repositories/digest-runs.js.map +1 -0
  24. package/dist/repositories/discussion.d.ts +16 -4
  25. package/dist/repositories/discussion.js +78 -18
  26. package/dist/repositories/discussion.js.map +1 -1
  27. package/dist/repositories/entitlements.d.ts +31 -9
  28. package/dist/repositories/entitlements.js +213 -17
  29. package/dist/repositories/entitlements.js.map +1 -1
  30. package/dist/repositories/grant-covers.d.ts +20 -0
  31. package/dist/repositories/grant-covers.js +55 -0
  32. package/dist/repositories/grant-covers.js.map +1 -0
  33. package/dist/repositories/identity.d.ts +4 -2
  34. package/dist/repositories/identity.js +32 -1
  35. package/dist/repositories/identity.js.map +1 -1
  36. package/dist/repositories/inserted-row.d.ts +5 -0
  37. package/dist/repositories/inserted-row.js +7 -0
  38. package/dist/repositories/inserted-row.js.map +1 -0
  39. package/dist/repositories/member.d.ts +16 -0
  40. package/dist/repositories/member.js +63 -0
  41. package/dist/repositories/member.js.map +1 -0
  42. package/dist/repositories/members.js +2 -2
  43. package/dist/repositories/members.js.map +1 -1
  44. package/dist/repositories/mentions.d.ts +17 -0
  45. package/dist/repositories/mentions.js +55 -0
  46. package/dist/repositories/mentions.js.map +1 -0
  47. package/dist/repositories/notification-settings.d.ts +19 -0
  48. package/dist/repositories/notification-settings.js +67 -0
  49. package/dist/repositories/notification-settings.js.map +1 -0
  50. package/dist/repositories/notifications.d.ts +30 -0
  51. package/dist/repositories/notifications.js +178 -0
  52. package/dist/repositories/notifications.js.map +1 -0
  53. package/dist/repositories/org-user-profile.d.ts +214 -1
  54. package/dist/repositories/org-user-profile.js +23 -2
  55. package/dist/repositories/org-user-profile.js.map +1 -1
  56. package/dist/repositories/organizations.d.ts +4 -2
  57. package/dist/repositories/organizations.js +23 -8
  58. package/dist/repositories/organizations.js.map +1 -1
  59. package/dist/repositories/pg-errors.js +3 -1
  60. package/dist/repositories/pg-errors.js.map +1 -1
  61. package/dist/repositories/posts.d.ts +35 -0
  62. package/dist/repositories/posts.js +252 -0
  63. package/dist/repositories/posts.js.map +1 -0
  64. package/dist/repositories/subscriptions.d.ts +18 -0
  65. package/dist/repositories/subscriptions.js +72 -0
  66. package/dist/repositories/subscriptions.js.map +1 -0
  67. package/dist/schema/assets.d.ts +19 -2
  68. package/dist/schema/assets.js +10 -4
  69. package/dist/schema/assets.js.map +1 -1
  70. package/dist/schema/automations.d.ts +545 -2
  71. package/dist/schema/automations.js +73 -3
  72. package/dist/schema/automations.js.map +1 -1
  73. package/dist/schema/better-auth.d.ts +1613 -238
  74. package/dist/schema/better-auth.js +107 -22
  75. package/dist/schema/better-auth.js.map +1 -1
  76. package/dist/schema/content.d.ts +642 -5
  77. package/dist/schema/content.js +119 -10
  78. package/dist/schema/content.js.map +1 -1
  79. package/dist/schema/discussion.d.ts +2182 -42
  80. package/dist/schema/discussion.js +461 -11
  81. package/dist/schema/discussion.js.map +1 -1
  82. package/dist/schema/entitlements.d.ts +432 -1
  83. package/dist/schema/entitlements.js +109 -4
  84. package/dist/schema/entitlements.js.map +1 -1
  85. package/dist/schema/identity.d.ts +517 -1
  86. package/dist/schema/identity.js +76 -2
  87. package/dist/schema/identity.js.map +1 -1
  88. package/dist/schema/index.d.ts +7 -7
  89. package/dist/schema/index.js +35 -8
  90. package/dist/schema/organizations.d.ts +4 -4
  91. package/dist/schema/organizations.js +2 -0
  92. package/dist/schema/organizations.js.map +1 -1
  93. package/drizzle/0003_community.sql +340 -0
  94. package/drizzle/0004_assets_sources.sql +1 -0
  95. package/drizzle/0005_notices_and_seed_index.sql +12 -0
  96. package/drizzle/0006_community_review_fixes.sql +24 -0
  97. package/drizzle/0007_notifications.sql +37 -0
  98. package/drizzle/0008_content_access.sql +13 -0
  99. package/drizzle/0009_community_indexes.sql +56 -0
  100. package/drizzle/0010_mcp_access.sql +114 -0
  101. package/drizzle/0011_digest_runs.sql +8 -0
  102. package/drizzle/0012_subscriptions.sql +16 -0
  103. package/drizzle/0013_mentions.sql +10 -0
  104. package/drizzle/0014_notification_settings_devices.sql +36 -0
  105. package/drizzle/0015_automations_drop_source.sql +2 -0
  106. package/drizzle/0016_notifications_automations.sql +48 -0
  107. package/drizzle/meta/0003_snapshot.json +7061 -0
  108. package/drizzle/meta/0004_snapshot.json +7068 -0
  109. package/drizzle/meta/0005_snapshot.json +7180 -0
  110. package/drizzle/meta/0006_snapshot.json +7298 -0
  111. package/drizzle/meta/0007_snapshot.json +7620 -0
  112. package/drizzle/meta/0008_snapshot.json +7666 -0
  113. package/drizzle/meta/0009_snapshot.json +8185 -0
  114. package/drizzle/meta/0010_snapshot.json +8813 -0
  115. package/drizzle/meta/0011_snapshot.json +8868 -0
  116. package/drizzle/meta/0012_snapshot.json +8873 -0
  117. package/drizzle/meta/0013_snapshot.json +8943 -0
  118. package/drizzle/meta/0014_snapshot.json +9305 -0
  119. package/drizzle/meta/0015_snapshot.json +9270 -0
  120. package/drizzle/meta/0016_snapshot.json +9230 -0
  121. package/drizzle/meta/_journal.json +99 -1
  122. package/package.json +2 -2
  123. package/dist/repositories/course-analytics.d.ts +0 -15
  124. package/dist/repositories/course-analytics.js +0 -137
  125. package/dist/repositories/course-analytics.js.map +0 -1
  126. package/dist/repositories/dashboard.d.ts +0 -14
  127. package/dist/repositories/dashboard.js +0 -57
  128. package/dist/repositories/dashboard.js.map +0 -1
  129. package/dist/repositories/learn.d.ts +0 -19
  130. package/dist/repositories/learn.js +0 -56
  131. package/dist/repositories/learn.js.map +0 -1
  132. package/dist/repositories/students.d.ts +0 -16
  133. package/dist/repositories/students.js +0 -160
  134. package/dist/repositories/students.js.map +0 -1
@@ -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');
@@ -0,0 +1,114 @@
1
+ CREATE TABLE "ba_apikey" (
2
+ "id" text PRIMARY KEY NOT NULL,
3
+ "config_id" text DEFAULT 'default' NOT NULL,
4
+ "name" text,
5
+ "start" text,
6
+ "reference_id" text NOT NULL,
7
+ "prefix" text,
8
+ "key" text NOT NULL,
9
+ "refill_interval" integer,
10
+ "refill_amount" integer,
11
+ "last_refill_at" timestamp with time zone,
12
+ "enabled" boolean DEFAULT true,
13
+ "rate_limit_enabled" boolean DEFAULT true,
14
+ "rate_limit_time_window" integer DEFAULT 86400000,
15
+ "rate_limit_max" integer DEFAULT 10,
16
+ "request_count" integer DEFAULT 0,
17
+ "remaining" integer,
18
+ "last_request" timestamp with time zone,
19
+ "expires_at" timestamp with time zone,
20
+ "created_at" timestamp with time zone NOT NULL,
21
+ "updated_at" timestamp with time zone NOT NULL,
22
+ "permissions" text,
23
+ "metadata" text
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE TABLE "ba_oauth_client_assertion" (
27
+ "id" text PRIMARY KEY NOT NULL,
28
+ "expires_at" timestamp with time zone NOT NULL
29
+ );
30
+ --> statement-breakpoint
31
+ CREATE TABLE "ba_oauth_client_resource" (
32
+ "id" text PRIMARY KEY NOT NULL,
33
+ "client_id" text NOT NULL,
34
+ "resource_id" text NOT NULL,
35
+ "metadata" jsonb,
36
+ "created_at" timestamp with time zone
37
+ );
38
+ --> statement-breakpoint
39
+ CREATE TABLE "ba_oauth_resource" (
40
+ "id" text PRIMARY KEY NOT NULL,
41
+ "identifier" text NOT NULL,
42
+ "name" text NOT NULL,
43
+ "access_token_ttl" integer,
44
+ "refresh_token_ttl" integer,
45
+ "signing_algorithm" text,
46
+ "signing_key_id" text,
47
+ "allowed_scopes" text[],
48
+ "custom_claims" jsonb,
49
+ "dpop_bound_access_tokens_required" boolean DEFAULT false,
50
+ "disabled" boolean DEFAULT false,
51
+ "created_at" timestamp with time zone,
52
+ "updated_at" timestamp with time zone,
53
+ "policy_version" integer DEFAULT 1,
54
+ "metadata" jsonb,
55
+ CONSTRAINT "ba_oauth_resource_identifier_unique" UNIQUE("identifier")
56
+ );
57
+ --> statement-breakpoint
58
+ ALTER TABLE "ba_oauth_access_token" DROP CONSTRAINT "ba_oauth_access_token_client_id_ba_oauth_client_client_id_fk";
59
+ --> statement-breakpoint
60
+ ALTER TABLE "ba_oauth_access_token" DROP CONSTRAINT "ba_oauth_access_token_refresh_id_ba_oauth_refresh_token_id_fk";
61
+ --> statement-breakpoint
62
+ ALTER TABLE "ba_oauth_consent" DROP CONSTRAINT "ba_oauth_consent_client_id_ba_oauth_client_client_id_fk";
63
+ --> statement-breakpoint
64
+ ALTER TABLE "ba_oauth_refresh_token" DROP CONSTRAINT "ba_oauth_refresh_token_client_id_ba_oauth_client_client_id_fk";
65
+ --> statement-breakpoint
66
+ ALTER TABLE "ba_oauth_access_token" ALTER COLUMN "token" DROP NOT NULL;--> statement-breakpoint
67
+ ALTER TABLE "ba_oauth_access_token" ALTER COLUMN "expires_at" DROP NOT NULL;--> statement-breakpoint
68
+ ALTER TABLE "ba_oauth_access_token" ALTER COLUMN "created_at" DROP NOT NULL;--> statement-breakpoint
69
+ ALTER TABLE "ba_oauth_client" ALTER COLUMN "metadata" SET DATA TYPE jsonb USING "metadata"::jsonb;--> statement-breakpoint
70
+ ALTER TABLE "ba_oauth_consent" ALTER COLUMN "created_at" DROP NOT NULL;--> statement-breakpoint
71
+ ALTER TABLE "ba_oauth_consent" ALTER COLUMN "updated_at" DROP NOT NULL;--> statement-breakpoint
72
+ ALTER TABLE "ba_oauth_refresh_token" ALTER COLUMN "expires_at" DROP NOT NULL;--> statement-breakpoint
73
+ ALTER TABLE "ba_oauth_refresh_token" ALTER COLUMN "created_at" DROP NOT NULL;--> statement-breakpoint
74
+ ALTER TABLE "ba_jwks" ADD COLUMN "expires_at" timestamp with time zone;--> statement-breakpoint
75
+ ALTER TABLE "ba_jwks" ADD COLUMN "alg" text;--> statement-breakpoint
76
+ ALTER TABLE "ba_jwks" ADD COLUMN "crv" text;--> statement-breakpoint
77
+ ALTER TABLE "ba_oauth_access_token" ADD COLUMN "authorization_code_id" text;--> statement-breakpoint
78
+ ALTER TABLE "ba_oauth_access_token" ADD COLUMN "resources" text[];--> statement-breakpoint
79
+ ALTER TABLE "ba_oauth_access_token" ADD COLUMN "requested_user_info_claims" text[];--> statement-breakpoint
80
+ ALTER TABLE "ba_oauth_access_token" ADD COLUMN "revoked" timestamp with time zone;--> statement-breakpoint
81
+ ALTER TABLE "ba_oauth_access_token" ADD COLUMN "confirmation" jsonb;--> statement-breakpoint
82
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "client_discovery_id" text;--> statement-breakpoint
83
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "client_credentials_scopes" text[] DEFAULT '{}';--> statement-breakpoint
84
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "backchannel_logout_uri" text;--> statement-breakpoint
85
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "backchannel_logout_session_required" boolean;--> statement-breakpoint
86
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "application_type" text;--> statement-breakpoint
87
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "jwks" text;--> statement-breakpoint
88
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "jwks_uri" text;--> statement-breakpoint
89
+ ALTER TABLE "ba_oauth_client" ADD COLUMN "dpop_bound_access_tokens" boolean DEFAULT false;--> statement-breakpoint
90
+ ALTER TABLE "ba_oauth_consent" ADD COLUMN "resources" text[];--> statement-breakpoint
91
+ ALTER TABLE "ba_oauth_consent" ADD COLUMN "requested_user_info_claims" text[];--> statement-breakpoint
92
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "authorization_code_id" text;--> statement-breakpoint
93
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "resources" text[];--> statement-breakpoint
94
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "requested_user_info_claims" text[];--> statement-breakpoint
95
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "rotated_at" timestamp with time zone;--> statement-breakpoint
96
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "rotation_replay_response" text;--> statement-breakpoint
97
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "rotation_replay_expires_at" timestamp with time zone;--> statement-breakpoint
98
+ ALTER TABLE "ba_oauth_refresh_token" ADD COLUMN "confirmation" jsonb;--> statement-breakpoint
99
+ ALTER TABLE "ba_oauth_client_resource" ADD CONSTRAINT "ba_oauth_client_resource_client_id_ba_oauth_client_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."ba_oauth_client"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
100
+ ALTER TABLE "ba_oauth_client_resource" ADD CONSTRAINT "ba_oauth_client_resource_resource_id_ba_oauth_resource_identifier_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."ba_oauth_resource"("identifier") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
101
+ CREATE INDEX "ba_apikey_config_id_idx" ON "ba_apikey" USING btree ("config_id");--> statement-breakpoint
102
+ CREATE INDEX "ba_apikey_reference_id_idx" ON "ba_apikey" USING btree ("reference_id");--> statement-breakpoint
103
+ CREATE INDEX "ba_apikey_key_idx" ON "ba_apikey" USING btree ("key");--> statement-breakpoint
104
+ CREATE INDEX "ba_oauth_client_resource_client_id_idx" ON "ba_oauth_client_resource" USING btree ("client_id");--> statement-breakpoint
105
+ CREATE INDEX "ba_oauth_client_resource_resource_id_idx" ON "ba_oauth_client_resource" USING btree ("resource_id");--> statement-breakpoint
106
+ CREATE UNIQUE INDEX "ba_oauth_client_resource_client_resource_uidx" ON "ba_oauth_client_resource" USING btree ("client_id","resource_id");--> statement-breakpoint
107
+ ALTER TABLE "ba_oauth_access_token" ADD CONSTRAINT "ba_oauth_access_token_client_id_ba_oauth_client_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."ba_oauth_client"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
108
+ ALTER TABLE "ba_oauth_access_token" ADD CONSTRAINT "ba_oauth_access_token_refresh_id_ba_oauth_refresh_token_id_fk" FOREIGN KEY ("refresh_id") REFERENCES "public"."ba_oauth_refresh_token"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
109
+ ALTER TABLE "ba_oauth_consent" ADD CONSTRAINT "ba_oauth_consent_client_id_ba_oauth_client_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."ba_oauth_client"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
110
+ ALTER TABLE "ba_oauth_refresh_token" ADD CONSTRAINT "ba_oauth_refresh_token_client_id_ba_oauth_client_client_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."ba_oauth_client"("client_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
111
+ CREATE INDEX "ba_oauth_access_token_authorization_code_id_idx" ON "ba_oauth_access_token" USING btree ("authorization_code_id");--> statement-breakpoint
112
+ CREATE INDEX "ba_oauth_refresh_token_authorization_code_id_idx" ON "ba_oauth_refresh_token" USING btree ("authorization_code_id");--> statement-breakpoint
113
+ ALTER TABLE "ba_oauth_client" DROP COLUMN "public";--> statement-breakpoint
114
+ ALTER TABLE "ba_oauth_client" DROP COLUMN "type";
@@ -0,0 +1,8 @@
1
+ CREATE TABLE "digest_runs" (
2
+ "org_id" text NOT NULL,
3
+ "community_id" text NOT NULL,
4
+ "last_due_at" timestamp with time zone NOT NULL,
5
+ CONSTRAINT "digest_runs_org_id_community_id_pk" PRIMARY KEY("org_id","community_id")
6
+ );
7
+ --> statement-breakpoint
8
+ ALTER TABLE "digest_runs" ADD CONSTRAINT "digest_runs_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,16 @@
1
+ CREATE TABLE "subscriptions" (
2
+ "org_id" text NOT NULL,
3
+ "org_user_id" text NOT NULL,
4
+ "item_type" text NOT NULL,
5
+ "item_id" text NOT NULL,
6
+ "state" text NOT NULL,
7
+ "muted_until" timestamp with time zone,
8
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
9
+ CONSTRAINT "subscriptions_org_id_org_user_id_item_type_item_id_pk" PRIMARY KEY("org_id","org_user_id","item_type","item_id")
10
+ );
11
+ --> statement-breakpoint
12
+ DROP TABLE "post_follows" CASCADE;--> statement-breakpoint
13
+ ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_org_id_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
14
+ CREATE INDEX "subscriptions_item_idx" ON "subscriptions" USING btree ("org_id","item_type","item_id","state");--> statement-breakpoint
15
+ ALTER TABLE "chat_users" DROP COLUMN "muted";--> statement-breakpoint
16
+ ALTER TABLE "chat_users" DROP COLUMN "muted_until";
@@ -0,0 +1,10 @@
1
+ CREATE TABLE "mentions" (
2
+ "org_id" text NOT NULL,
3
+ "item_type" text NOT NULL,
4
+ "item_id" text NOT NULL,
5
+ "org_user_id" text NOT NULL,
6
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
7
+ CONSTRAINT "mentions_org_id_item_type_item_id_org_user_id_pk" PRIMARY KEY("org_id","item_type","item_id","org_user_id")
8
+ );
9
+ --> statement-breakpoint
10
+ ALTER TABLE "mentions" ADD CONSTRAINT "mentions_org_id_org_user_id_org_users_org_id_id_fk" FOREIGN KEY ("org_id","org_user_id") REFERENCES "public"."org_users"("org_id","id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,36 @@
1
+ CREATE TABLE "devices" (
2
+ "org_id" text NOT NULL,
3
+ "id" text NOT NULL,
4
+ "user_id" text NOT NULL,
5
+ "provider" text NOT NULL,
6
+ "token" text NOT NULL,
7
+ "p256dh" text,
8
+ "auth" text,
9
+ "app_id" text,
10
+ "environment" text,
11
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
12
+ "last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
13
+ CONSTRAINT "devices_org_id_id_pk" PRIMARY KEY("org_id","id")
14
+ );
15
+ --> statement-breakpoint
16
+ CREATE TABLE "notification_settings" (
17
+ "org_id" text NOT NULL,
18
+ "id" text NOT NULL,
19
+ "user_id" text NOT NULL,
20
+ "community_id" text,
21
+ "space_id" text,
22
+ "category" text NOT NULL,
23
+ "channel" text NOT NULL,
24
+ "enabled" boolean NOT NULL,
25
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
26
+ CONSTRAINT "notification_settings_org_id_id_pk" PRIMARY KEY("org_id","id")
27
+ );
28
+ --> statement-breakpoint
29
+ ALTER TABLE "devices" ADD CONSTRAINT "devices_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
30
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
31
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
32
+ ALTER TABLE "notification_settings" ADD CONSTRAINT "notification_settings_org_id_space_id_spaces_org_id_id_fk" FOREIGN KEY ("org_id","space_id") REFERENCES "public"."spaces"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
33
+ CREATE UNIQUE INDEX "devices_token_idx" ON "devices" USING btree ("org_id","provider","token");--> statement-breakpoint
34
+ CREATE INDEX "devices_user_idx" ON "devices" USING btree ("org_id","user_id","last_seen_at");--> statement-breakpoint
35
+ CREATE UNIQUE INDEX "notification_settings_setting_idx" ON "notification_settings" USING btree ("org_id","user_id",coalesce("community_id", ''),coalesce("space_id", ''),"category","channel");--> statement-breakpoint
36
+ CREATE INDEX "notification_settings_switched_on_idx" ON "notification_settings" USING btree ("org_id",coalesce("community_id", ''),"category",coalesce("space_id", '')) WHERE "notification_settings"."enabled";
@@ -0,0 +1,2 @@
1
+ DROP INDEX "automations_system_seed_idx";--> statement-breakpoint
2
+ ALTER TABLE "automations" DROP COLUMN "source";
@@ -0,0 +1,48 @@
1
+ DROP TABLE "notification_preferences" CASCADE;--> statement-breakpoint
2
+ DROP TABLE "notifications" CASCADE;--> statement-breakpoint
3
+ CREATE TABLE "notification_deliveries" (
4
+ "org_id" text NOT NULL,
5
+ "id" text NOT NULL,
6
+ "notification_id" text NOT NULL,
7
+ "channel" text NOT NULL,
8
+ "status" text DEFAULT 'pending' NOT NULL,
9
+ "last_error" text,
10
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
11
+ "sent_at" timestamp with time zone,
12
+ CONSTRAINT "notification_deliveries_org_id_id_pk" PRIMARY KEY("org_id","id")
13
+ );
14
+ --> statement-breakpoint
15
+ CREATE TABLE "notifications" (
16
+ "org_id" text NOT NULL,
17
+ "id" text NOT NULL,
18
+ "user_id" text NOT NULL,
19
+ "source_event_id" text,
20
+ "type" text NOT NULL,
21
+ "scope" text NOT NULL,
22
+ "reasons" text[] NOT NULL,
23
+ "matched_reason" text NOT NULL,
24
+ "category" text NOT NULL,
25
+ "community_id" text,
26
+ "space_id" text,
27
+ "actor_org_user_id" text,
28
+ "subject_type" text,
29
+ "subject_id" text,
30
+ "parent_type" text,
31
+ "parent_id" text,
32
+ "display" jsonb NOT NULL,
33
+ "in_app" boolean NOT NULL,
34
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
35
+ "read_at" timestamp with time zone,
36
+ CONSTRAINT "notifications_org_id_id_pk" PRIMARY KEY("org_id","id")
37
+ );
38
+ --> statement-breakpoint
39
+ ALTER TABLE "notification_deliveries" ADD CONSTRAINT "notification_deliveries_org_id_notification_id_notifications_org_id_id_fk" FOREIGN KEY ("org_id","notification_id") REFERENCES "public"."notifications"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
40
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_user_id_org_users_org_id_user_id_fk" FOREIGN KEY ("org_id","user_id") REFERENCES "public"."org_users"("org_id","user_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
41
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_community_id_communities_org_id_id_fk" FOREIGN KEY ("org_id","community_id") REFERENCES "public"."communities"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
42
+ ALTER TABLE "notifications" ADD CONSTRAINT "notifications_org_id_space_id_spaces_org_id_id_fk" FOREIGN KEY ("org_id","space_id") REFERENCES "public"."spaces"("org_id","id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
43
+ CREATE UNIQUE INDEX "notification_deliveries_channel_idx" ON "notification_deliveries" USING btree ("org_id","notification_id","channel");--> statement-breakpoint
44
+ CREATE UNIQUE INDEX "notifications_source_event_idx" ON "notifications" USING btree ("org_id","source_event_id","user_id",coalesce("community_id", '')) WHERE "notifications"."source_event_id" is not null;--> statement-breakpoint
45
+ CREATE INDEX "notifications_list_idx" ON "notifications" USING btree ("org_id","user_id","created_at" desc,"id" desc) WHERE "notifications"."in_app";--> statement-breakpoint
46
+ CREATE INDEX "notifications_community_idx" ON "notifications" USING btree ("org_id","user_id","community_id");--> statement-breakpoint
47
+ CREATE INDEX "notifications_category_idx" ON "notifications" USING btree ("org_id","user_id","category");--> statement-breakpoint
48
+ CREATE INDEX "notifications_reasons_idx" ON "notifications" USING gin ("reasons");