-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
632 additions
and
451 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
DO $$ BEGIN | ||
CREATE TYPE "public"."member_role" AS ENUM('member', 'admin', 'owner'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "groups" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now(), | ||
"name" varchar(50) NOT NULL, | ||
"owner_id" bigint NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "members" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now(), | ||
"user_id" bigint NOT NULL, | ||
"group_id" bigint NOT NULL, | ||
"role" "member_role" DEFAULT 'member' NOT NULL, | ||
CONSTRAINT "members_user_id_group_id_unique" UNIQUE("user_id","group_id") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "message_recipients" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now(), | ||
"message_id" bigint NOT NULL, | ||
"recipient_id" bigint NOT NULL, | ||
CONSTRAINT "message_recipients_message_id_recipient_id_unique" UNIQUE("message_id","recipient_id") | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "messages" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now(), | ||
"sender_id" bigint NOT NULL, | ||
"receiver_id" bigint, | ||
"group_id" bigint, | ||
"content" text NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "users" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now(), | ||
"username" varchar(40) NOT NULL, | ||
"password" varchar NOT NULL, | ||
"full_name" varchar NOT NULL, | ||
CONSTRAINT "users_username_unique" UNIQUE("username") | ||
); | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "groups" ADD CONSTRAINT "groups_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "members" ADD CONSTRAINT "members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "members" ADD CONSTRAINT "members_group_id_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."groups"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "message_recipients" ADD CONSTRAINT "message_recipients_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "message_recipients" ADD CONSTRAINT "message_recipients_recipient_id_users_id_fk" FOREIGN KEY ("recipient_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "messages" ADD CONSTRAINT "messages_sender_id_users_id_fk" FOREIGN KEY ("sender_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "messages" ADD CONSTRAINT "messages_receiver_id_users_id_fk" FOREIGN KEY ("receiver_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "messages" ADD CONSTRAINT "messages_group_id_groups_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."groups"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "members_user_id_index" ON "members" USING btree ("user_id");--> statement-breakpoint | ||
CREATE INDEX IF NOT EXISTS "members_group_id_index" ON "members" USING btree ("group_id"); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.