Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/lib/db/drizzle/0001_nebulous_ezekiel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
CREATE TABLE "community" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"display_name" text NOT NULL,
"description" text,
"creator_id" uuid NOT NULL,
"created_at" timestamp(6) with time zone DEFAULT now(),
"updated_at" timestamp(6) with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "community_member" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"community_id" uuid NOT NULL,
"user_id" uuid NOT NULL,
"joined_at" timestamp(6) with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE "community_moderator" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"community_id" uuid NOT NULL,
"user_id" uuid NOT NULL,
"added_at" timestamp(6) with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "community" ADD CONSTRAINT "community_creator_id_user_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "community_member" ADD CONSTRAINT "community_member_community_id_community_id_fk" FOREIGN KEY ("community_id") REFERENCES "public"."community"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "community_member" ADD CONSTRAINT "community_member_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "community_moderator" ADD CONSTRAINT "community_moderator_community_id_community_id_fk" FOREIGN KEY ("community_id") REFERENCES "public"."community"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "community_moderator" ADD CONSTRAINT "community_moderator_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "community_id_index" ON "community" USING btree ("id");--> statement-breakpoint
CREATE UNIQUE INDEX "community_name_index" ON "community" USING btree ("name");--> statement-breakpoint
CREATE INDEX "community_creator_id_index" ON "community" USING btree ("creator_id");--> statement-breakpoint
CREATE UNIQUE INDEX "community_member_id_index" ON "community_member" USING btree ("id");--> statement-breakpoint
CREATE UNIQUE INDEX "community_member_community_id_user_id_index" ON "community_member" USING btree ("community_id","user_id");--> statement-breakpoint
CREATE INDEX "community_member_community_id_index" ON "community_member" USING btree ("community_id");--> statement-breakpoint
CREATE INDEX "community_member_user_id_index" ON "community_member" USING btree ("user_id");--> statement-breakpoint
CREATE UNIQUE INDEX "community_moderator_id_index" ON "community_moderator" USING btree ("id");--> statement-breakpoint
CREATE UNIQUE INDEX "community_moderator_community_id_user_id_index" ON "community_moderator" USING btree ("community_id","user_id");--> statement-breakpoint
CREATE INDEX "community_moderator_community_id_index" ON "community_moderator" USING btree ("community_id");--> statement-breakpoint
CREATE INDEX "community_moderator_user_id_index" ON "community_moderator" USING btree ("user_id");
16 changes: 16 additions & 0 deletions src/lib/db/drizzle/0002_solid_harrier.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE "comment" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"content" text NOT NULL,
"post_id" uuid NOT NULL,
"author_id" uuid NOT NULL,
"parent_comment_id" uuid,
"created_at" timestamp(6) with time zone DEFAULT now(),
"updated_at" timestamp(6) with time zone DEFAULT now()
);
--> statement-breakpoint
ALTER TABLE "comment" ADD CONSTRAINT "comment_post_id_post_id_fk" FOREIGN KEY ("post_id") REFERENCES "public"."post"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "comment" ADD CONSTRAINT "comment_author_id_user_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "comment_id_index" ON "comment" USING btree ("id");--> statement-breakpoint
CREATE INDEX "comment_post_id_index" ON "comment" USING btree ("post_id");--> statement-breakpoint
CREATE INDEX "comment_author_id_index" ON "comment" USING btree ("author_id");--> statement-breakpoint
CREATE INDEX "comment_parent_comment_id_index" ON "comment" USING btree ("parent_comment_id");
5 changes: 5 additions & 0 deletions src/lib/db/drizzle/0003_solid_sersi.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE "comment" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint
DROP TABLE "comment" CASCADE;--> statement-breakpoint
ALTER TABLE "post" ADD COLUMN "community_id" uuid NOT NULL;--> statement-breakpoint
ALTER TABLE "post" ADD CONSTRAINT "post_community_id_community_id_fk" FOREIGN KEY ("community_id") REFERENCES "public"."community"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "post_community_id_index" ON "post" USING btree ("community_id");
Loading