···1+CREATE TABLE "categories" (
2+ "id" bigserial PRIMARY KEY NOT NULL,
3+ "did" text NOT NULL,
4+ "rkey" text NOT NULL,
5+ "cid" text NOT NULL,
6+ "name" text NOT NULL,
7+ "description" text,
8+ "slug" text,
9+ "sort_order" integer,
10+ "forum_id" bigint,
11+ "created_at" timestamp with time zone NOT NULL,
12+ "indexed_at" timestamp with time zone NOT NULL
13+);
14+--> statement-breakpoint
15+CREATE TABLE "forums" (
16+ "id" bigserial PRIMARY KEY NOT NULL,
17+ "did" text NOT NULL,
18+ "rkey" text NOT NULL,
19+ "cid" text NOT NULL,
20+ "name" text NOT NULL,
21+ "description" text,
22+ "indexed_at" timestamp with time zone NOT NULL
23+);
24+--> statement-breakpoint
25+CREATE TABLE "memberships" (
26+ "id" bigserial PRIMARY KEY NOT NULL,
27+ "did" text NOT NULL,
28+ "rkey" text NOT NULL,
29+ "cid" text NOT NULL,
30+ "forum_id" bigint,
31+ "forum_uri" text NOT NULL,
32+ "role" text,
33+ "role_uri" text,
34+ "joined_at" timestamp with time zone,
35+ "created_at" timestamp with time zone NOT NULL,
36+ "indexed_at" timestamp with time zone NOT NULL
37+);
38+--> statement-breakpoint
39+CREATE TABLE "mod_actions" (
40+ "id" bigserial PRIMARY KEY NOT NULL,
41+ "did" text NOT NULL,
42+ "rkey" text NOT NULL,
43+ "cid" text NOT NULL,
44+ "action" text NOT NULL,
45+ "subject_did" text,
46+ "subject_post_uri" text,
47+ "forum_id" bigint,
48+ "reason" text,
49+ "created_by" text NOT NULL,
50+ "expires_at" timestamp with time zone,
51+ "created_at" timestamp with time zone NOT NULL,
52+ "indexed_at" timestamp with time zone NOT NULL
53+);
54+--> statement-breakpoint
55+CREATE TABLE "posts" (
56+ "id" bigserial PRIMARY KEY NOT NULL,
57+ "did" text NOT NULL,
58+ "rkey" text NOT NULL,
59+ "cid" text NOT NULL,
60+ "text" text NOT NULL,
61+ "forum_uri" text,
62+ "root_post_id" bigint,
63+ "parent_post_id" bigint,
64+ "root_uri" text,
65+ "parent_uri" text,
66+ "created_at" timestamp with time zone NOT NULL,
67+ "indexed_at" timestamp with time zone NOT NULL,
68+ "deleted" boolean DEFAULT false NOT NULL
69+);
70+--> statement-breakpoint
71+CREATE TABLE "users" (
72+ "did" text PRIMARY KEY NOT NULL,
73+ "handle" text,
74+ "indexed_at" timestamp with time zone NOT NULL
75+);
76+--> statement-breakpoint
77+ALTER TABLE "categories" ADD CONSTRAINT "categories_forum_id_forums_id_fk" FOREIGN KEY ("forum_id") REFERENCES "public"."forums"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
78+ALTER TABLE "memberships" ADD CONSTRAINT "memberships_did_users_did_fk" FOREIGN KEY ("did") REFERENCES "public"."users"("did") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
79+ALTER TABLE "memberships" ADD CONSTRAINT "memberships_forum_id_forums_id_fk" FOREIGN KEY ("forum_id") REFERENCES "public"."forums"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
80+ALTER TABLE "mod_actions" ADD CONSTRAINT "mod_actions_forum_id_forums_id_fk" FOREIGN KEY ("forum_id") REFERENCES "public"."forums"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
81+ALTER TABLE "posts" ADD CONSTRAINT "posts_did_users_did_fk" FOREIGN KEY ("did") REFERENCES "public"."users"("did") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
82+ALTER TABLE "posts" ADD CONSTRAINT "posts_root_post_id_posts_id_fk" FOREIGN KEY ("root_post_id") REFERENCES "public"."posts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
83+ALTER TABLE "posts" ADD CONSTRAINT "posts_parent_post_id_posts_id_fk" FOREIGN KEY ("parent_post_id") REFERENCES "public"."posts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
84+CREATE UNIQUE INDEX "categories_did_rkey_idx" ON "categories" USING btree ("did","rkey");--> statement-breakpoint
85+CREATE UNIQUE INDEX "forums_did_rkey_idx" ON "forums" USING btree ("did","rkey");--> statement-breakpoint
86+CREATE UNIQUE INDEX "memberships_did_rkey_idx" ON "memberships" USING btree ("did","rkey");--> statement-breakpoint
87+CREATE INDEX "memberships_did_idx" ON "memberships" USING btree ("did");--> statement-breakpoint
88+CREATE UNIQUE INDEX "mod_actions_did_rkey_idx" ON "mod_actions" USING btree ("did","rkey");--> statement-breakpoint
89+CREATE UNIQUE INDEX "posts_did_rkey_idx" ON "posts" USING btree ("did","rkey");--> statement-breakpoint
90+CREATE INDEX "posts_forum_uri_idx" ON "posts" USING btree ("forum_uri");--> statement-breakpoint
91+CREATE INDEX "posts_root_post_id_idx" ON "posts" USING btree ("root_post_id");