diff --git a/src/lib/db/drizzle/0001_nebulous_ezekiel.sql b/src/lib/db/drizzle/0001_nebulous_ezekiel.sql new file mode 100644 index 0000000..f089d7d --- /dev/null +++ b/src/lib/db/drizzle/0001_nebulous_ezekiel.sql @@ -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"); \ No newline at end of file diff --git a/src/lib/db/drizzle/0002_solid_harrier.sql b/src/lib/db/drizzle/0002_solid_harrier.sql new file mode 100644 index 0000000..742a38a --- /dev/null +++ b/src/lib/db/drizzle/0002_solid_harrier.sql @@ -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"); \ No newline at end of file diff --git a/src/lib/db/drizzle/0003_solid_sersi.sql b/src/lib/db/drizzle/0003_solid_sersi.sql new file mode 100644 index 0000000..b88ca7d --- /dev/null +++ b/src/lib/db/drizzle/0003_solid_sersi.sql @@ -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"); \ No newline at end of file diff --git a/src/lib/db/drizzle/meta/0001_snapshot.json b/src/lib/db/drizzle/meta/0001_snapshot.json new file mode 100644 index 0000000..0496c1a --- /dev/null +++ b/src/lib/db/drizzle/meta/0001_snapshot.json @@ -0,0 +1,579 @@ +{ + "id": "2ecb7f9d-3414-4c92-8be1-b828fa2aae53", + "prevId": "cf8684b1-5063-48d0-99ca-22145d0bd1a9", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.community": { + "name": "community", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creator_id": { + "name": "creator_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_id_index": { + "name": "community_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_name_index": { + "name": "community_name_index", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_creator_id_index": { + "name": "community_creator_id_index", + "columns": [ + { + "expression": "creator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_creator_id_user_id_fk": { + "name": "community_creator_id_user_id_fk", + "tableFrom": "community", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_member": { + "name": "community_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_member_id_index": { + "name": "community_member_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_user_id_index": { + "name": "community_member_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_index": { + "name": "community_member_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_user_id_index": { + "name": "community_member_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_member_community_id_community_id_fk": { + "name": "community_member_community_id_community_id_fk", + "tableFrom": "community_member", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_member_user_id_user_id_fk": { + "name": "community_member_user_id_user_id_fk", + "tableFrom": "community_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_moderator": { + "name": "community_moderator", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_moderator_id_index": { + "name": "community_moderator_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_user_id_index": { + "name": "community_moderator_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_index": { + "name": "community_moderator_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_user_id_index": { + "name": "community_moderator_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_moderator_community_id_community_id_fk": { + "name": "community_moderator_community_id_community_id_fk", + "tableFrom": "community_moderator", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_moderator_user_id_user_id_fk": { + "name": "community_moderator_user_id_user_id_fk", + "tableFrom": "community_moderator", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "post_id_index": { + "name": "post_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "post_author_id_index": { + "name": "post_author_id_index", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_author_id_user_id_fk": { + "name": "post_author_id_user_id_fk", + "tableFrom": "post", + "tableTo": "user", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identity_provider_id": { + "name": "identity_provider_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "user_id_index": { + "name": "user_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_identity_provider_id_index": { + "name": "user_identity_provider_id_index", + "columns": [ + { + "expression": "identity_provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_identityProviderId_unique": { + "name": "user_identityProviderId_unique", + "nullsNotDistinct": false, + "columns": [ + "identity_provider_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/db/drizzle/meta/0002_snapshot.json b/src/lib/db/drizzle/meta/0002_snapshot.json new file mode 100644 index 0000000..680ba68 --- /dev/null +++ b/src/lib/db/drizzle/meta/0002_snapshot.json @@ -0,0 +1,725 @@ +{ + "id": "c5999faa-8aaa-485b-93df-7e7254d3af6e", + "prevId": "2ecb7f9d-3414-4c92-8be1-b828fa2aae53", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.comment": { + "name": "comment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "comment_id_index": { + "name": "comment_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "comment_post_id_index": { + "name": "comment_post_id_index", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "comment_author_id_index": { + "name": "comment_author_id_index", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "comment_parent_comment_id_index": { + "name": "comment_parent_comment_id_index", + "columns": [ + { + "expression": "parent_comment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "comment_post_id_post_id_fk": { + "name": "comment_post_id_post_id_fk", + "tableFrom": "comment", + "tableTo": "post", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "comment_author_id_user_id_fk": { + "name": "comment_author_id_user_id_fk", + "tableFrom": "comment", + "tableTo": "user", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community": { + "name": "community", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creator_id": { + "name": "creator_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_id_index": { + "name": "community_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_name_index": { + "name": "community_name_index", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_creator_id_index": { + "name": "community_creator_id_index", + "columns": [ + { + "expression": "creator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_creator_id_user_id_fk": { + "name": "community_creator_id_user_id_fk", + "tableFrom": "community", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_member": { + "name": "community_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_member_id_index": { + "name": "community_member_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_user_id_index": { + "name": "community_member_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_index": { + "name": "community_member_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_user_id_index": { + "name": "community_member_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_member_community_id_community_id_fk": { + "name": "community_member_community_id_community_id_fk", + "tableFrom": "community_member", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_member_user_id_user_id_fk": { + "name": "community_member_user_id_user_id_fk", + "tableFrom": "community_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_moderator": { + "name": "community_moderator", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_moderator_id_index": { + "name": "community_moderator_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_user_id_index": { + "name": "community_moderator_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_index": { + "name": "community_moderator_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_user_id_index": { + "name": "community_moderator_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_moderator_community_id_community_id_fk": { + "name": "community_moderator_community_id_community_id_fk", + "tableFrom": "community_moderator", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_moderator_user_id_user_id_fk": { + "name": "community_moderator_user_id_user_id_fk", + "tableFrom": "community_moderator", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "post_id_index": { + "name": "post_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "post_author_id_index": { + "name": "post_author_id_index", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_author_id_user_id_fk": { + "name": "post_author_id_user_id_fk", + "tableFrom": "post", + "tableTo": "user", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identity_provider_id": { + "name": "identity_provider_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "user_id_index": { + "name": "user_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_identity_provider_id_index": { + "name": "user_identity_provider_id_index", + "columns": [ + { + "expression": "identity_provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_identityProviderId_unique": { + "name": "user_identityProviderId_unique", + "nullsNotDistinct": false, + "columns": [ + "identity_provider_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/db/drizzle/meta/0003_snapshot.json b/src/lib/db/drizzle/meta/0003_snapshot.json new file mode 100644 index 0000000..5ffd973 --- /dev/null +++ b/src/lib/db/drizzle/meta/0003_snapshot.json @@ -0,0 +1,613 @@ +{ + "id": "e732541e-0c6b-47e1-8e5b-1d7e1227d1e3", + "prevId": "c5999faa-8aaa-485b-93df-7e7254d3af6e", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.community": { + "name": "community", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creator_id": { + "name": "creator_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_id_index": { + "name": "community_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_name_index": { + "name": "community_name_index", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_creator_id_index": { + "name": "community_creator_id_index", + "columns": [ + { + "expression": "creator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_creator_id_user_id_fk": { + "name": "community_creator_id_user_id_fk", + "tableFrom": "community", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_member": { + "name": "community_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_member_id_index": { + "name": "community_member_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_user_id_index": { + "name": "community_member_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_community_id_index": { + "name": "community_member_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_member_user_id_index": { + "name": "community_member_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_member_community_id_community_id_fk": { + "name": "community_member_community_id_community_id_fk", + "tableFrom": "community_member", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_member_user_id_user_id_fk": { + "name": "community_member_user_id_user_id_fk", + "tableFrom": "community_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.community_moderator": { + "name": "community_moderator", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "added_at": { + "name": "added_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "community_moderator_id_index": { + "name": "community_moderator_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_user_id_index": { + "name": "community_moderator_community_id_user_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_community_id_index": { + "name": "community_moderator_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "community_moderator_user_id_index": { + "name": "community_moderator_user_id_index", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "community_moderator_community_id_community_id_fk": { + "name": "community_moderator_community_id_community_id_fk", + "tableFrom": "community_moderator", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "community_moderator_user_id_user_id_fk": { + "name": "community_moderator_user_id_user_id_fk", + "tableFrom": "community_moderator", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.post": { + "name": "post", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "community_id": { + "name": "community_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "post_id_index": { + "name": "post_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "post_author_id_index": { + "name": "post_author_id_index", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "post_community_id_index": { + "name": "post_community_id_index", + "columns": [ + { + "expression": "community_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "post_community_id_community_id_fk": { + "name": "post_community_id_community_id_fk", + "tableFrom": "post", + "tableTo": "community", + "columnsFrom": [ + "community_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "post_author_id_user_id_fk": { + "name": "post_author_id_user_id_fk", + "tableFrom": "post", + "tableTo": "user", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identity_provider_id": { + "name": "identity_provider_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp(6) with time zone", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "user_id_index": { + "name": "user_id_index", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_identity_provider_id_index": { + "name": "user_identity_provider_id_index", + "columns": [ + { + "expression": "identity_provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_identityProviderId_unique": { + "name": "user_identityProviderId_unique", + "nullsNotDistinct": false, + "columns": [ + "identity_provider_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/lib/db/drizzle/meta/_journal.json b/src/lib/db/drizzle/meta/_journal.json index 5899eca..9ca17f3 100644 --- a/src/lib/db/drizzle/meta/_journal.json +++ b/src/lib/db/drizzle/meta/_journal.json @@ -8,6 +8,27 @@ "when": 1747753222349, "tag": "0000_grey_spencer_smythe", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1758562690425, + "tag": "0001_nebulous_ezekiel", + "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1758565112364, + "tag": "0002_solid_harrier", + "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1758565425230, + "tag": "0003_solid_sersi", + "breakpoints": true } ] -} +} \ No newline at end of file diff --git a/src/lib/db/schema/community.table.ts b/src/lib/db/schema/community.table.ts new file mode 100644 index 0000000..c1ea1db --- /dev/null +++ b/src/lib/db/schema/community.table.ts @@ -0,0 +1,34 @@ +import { index, pgTable, text, uniqueIndex, uuid } from "drizzle-orm/pg-core"; + +import { userTable } from "lib/db/schema/user.table"; +import { generateDefaultDate, generateDefaultId } from "lib/db/util"; + +import type { InferInsertModel, InferSelectModel } from "drizzle-orm"; + +/** + * Community table. + */ +export const communityTable = pgTable( + "community", + { + id: generateDefaultId(), + name: text().notNull(), + displayName: text().notNull(), + description: text(), + creatorId: uuid() + .notNull() + .references(() => userTable.id, { + onDelete: "cascade", + }), + createdAt: generateDefaultDate(), + updatedAt: generateDefaultDate(), + }, + (table) => [ + uniqueIndex().on(table.id), + uniqueIndex().on(table.name), + index().on(table.creatorId), + ], +); + +export type InsertCommunity = InferInsertModel; +export type SelectCommunity = InferSelectModel; diff --git a/src/lib/db/schema/communityMember.table.ts b/src/lib/db/schema/communityMember.table.ts new file mode 100644 index 0000000..aeb3b7e --- /dev/null +++ b/src/lib/db/schema/communityMember.table.ts @@ -0,0 +1,41 @@ +import { index, pgTable, uniqueIndex, uuid } from "drizzle-orm/pg-core"; + +import { communityTable } from "lib/db/schema/community.table"; +import { userTable } from "lib/db/schema/user.table"; +import { generateDefaultDate, generateDefaultId } from "lib/db/util"; + +import type { InferInsertModel, InferSelectModel } from "drizzle-orm"; + +/** + * Community member junction table. + */ +export const communityMemberTable = pgTable( + "community_member", + { + id: generateDefaultId(), + communityId: uuid() + .notNull() + .references(() => communityTable.id, { + onDelete: "cascade", + }), + userId: uuid() + .notNull() + .references(() => userTable.id, { + onDelete: "cascade", + }), + joinedAt: generateDefaultDate(), + }, + (table) => [ + uniqueIndex().on(table.id), + uniqueIndex().on(table.communityId, table.userId), + index().on(table.communityId), + index().on(table.userId), + ], +); + +export type InsertCommunityMember = InferInsertModel< + typeof communityMemberTable +>; +export type SelectCommunityMember = InferSelectModel< + typeof communityMemberTable +>; diff --git a/src/lib/db/schema/communityModerator.table.ts b/src/lib/db/schema/communityModerator.table.ts new file mode 100644 index 0000000..5d6aec7 --- /dev/null +++ b/src/lib/db/schema/communityModerator.table.ts @@ -0,0 +1,41 @@ +import { index, pgTable, uniqueIndex, uuid } from "drizzle-orm/pg-core"; + +import { communityTable } from "lib/db/schema/community.table"; +import { userTable } from "lib/db/schema/user.table"; +import { generateDefaultDate, generateDefaultId } from "lib/db/util"; + +import type { InferInsertModel, InferSelectModel } from "drizzle-orm"; + +/** + * Community moderator junction table. + */ +export const communityModeratorTable = pgTable( + "community_moderator", + { + id: generateDefaultId(), + communityId: uuid() + .notNull() + .references(() => communityTable.id, { + onDelete: "cascade", + }), + userId: uuid() + .notNull() + .references(() => userTable.id, { + onDelete: "cascade", + }), + addedAt: generateDefaultDate(), + }, + (table) => [ + uniqueIndex().on(table.id), + uniqueIndex().on(table.communityId, table.userId), + index().on(table.communityId), + index().on(table.userId), + ], +); + +export type InsertCommunityModerator = InferInsertModel< + typeof communityModeratorTable +>; +export type SelectCommunityModerator = InferSelectModel< + typeof communityModeratorTable +>; diff --git a/src/lib/db/schema/index.ts b/src/lib/db/schema/index.ts index 79abb35..f147f77 100644 --- a/src/lib/db/schema/index.ts +++ b/src/lib/db/schema/index.ts @@ -1,2 +1,5 @@ +export * from "./community.table"; +export * from "./communityMember.table"; +export * from "./communityModerator.table"; export * from "./post.table"; export * from "./user.table"; diff --git a/src/lib/db/schema/post.table.ts b/src/lib/db/schema/post.table.ts index b5960bd..7b541fc 100644 --- a/src/lib/db/schema/post.table.ts +++ b/src/lib/db/schema/post.table.ts @@ -1,5 +1,6 @@ import { index, pgTable, text, uniqueIndex, uuid } from "drizzle-orm/pg-core"; +import { communityTable } from "lib/db/schema/community.table"; import { userTable } from "lib/db/schema/user.table"; import { generateDefaultDate, generateDefaultId } from "lib/db/util"; @@ -14,6 +15,11 @@ export const postTable = pgTable( id: generateDefaultId(), title: text(), description: text(), + communityId: uuid() + .notNull() + .references(() => communityTable.id, { + onDelete: "cascade", + }), authorId: uuid() .notNull() .references(() => userTable.id, { @@ -22,7 +28,11 @@ export const postTable = pgTable( createdAt: generateDefaultDate(), updatedAt: generateDefaultDate(), }, - (table) => [uniqueIndex().on(table.id), index().on(table.authorId)], + (table) => [ + uniqueIndex().on(table.id), + index().on(table.authorId), + index().on(table.communityId), + ], ); export type InsertPost = InferInsertModel;