diff options
Diffstat (limited to 'db/migrations/0177_fresh_the_captain.sql')
| -rw-r--r-- | db/migrations/0177_fresh_the_captain.sql | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/db/migrations/0177_fresh_the_captain.sql b/db/migrations/0177_fresh_the_captain.sql new file mode 100644 index 00000000..5b3ac2b5 --- /dev/null +++ b/db/migrations/0177_fresh_the_captain.sql @@ -0,0 +1,44 @@ +CREATE TABLE "qna" ( + "id" serial PRIMARY KEY NOT NULL, + "title" varchar(255) NOT NULL, + "content" text NOT NULL, + "author" integer NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "is_deleted" boolean DEFAULT false NOT NULL, + "deleted_at" timestamp +); +--> statement-breakpoint +CREATE TABLE "qna_answer" ( + "id" serial PRIMARY KEY NOT NULL, + "qna_id" integer NOT NULL, + "content" text NOT NULL, + "author" integer NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "is_deleted" boolean DEFAULT false NOT NULL, + "deleted_at" timestamp +); +--> statement-breakpoint +CREATE TABLE "qna_comments" ( + "id" serial PRIMARY KEY NOT NULL, + "content" text NOT NULL, + "author" integer NOT NULL, + "answer_id" integer NOT NULL, + "parent_comment_id" integer, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "is_deleted" boolean DEFAULT false NOT NULL, + "deleted_at" timestamp +); +--> statement-breakpoint +ALTER TABLE "qna" ADD CONSTRAINT "qna_author_users_id_fk" FOREIGN KEY ("author") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "qna_answer" ADD CONSTRAINT "qna_answer_qna_id_qna_id_fk" FOREIGN KEY ("qna_id") REFERENCES "public"."qna"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "qna_answer" ADD CONSTRAINT "qna_answer_author_users_id_fk" FOREIGN KEY ("author") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "qna_comments" ADD CONSTRAINT "qna_comments_author_users_id_fk" FOREIGN KEY ("author") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "qna_comments" ADD CONSTRAINT "qna_comments_answer_id_qna_answer_id_fk" FOREIGN KEY ("answer_id") REFERENCES "public"."qna_answer"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "idx_qna_author" ON "qna" USING btree ("author");--> statement-breakpoint +CREATE INDEX "idx_answer_qna" ON "qna_answer" USING btree ("qna_id");--> statement-breakpoint +CREATE INDEX "idx_answer_author" ON "qna_answer" USING btree ("author");--> statement-breakpoint +CREATE INDEX "idx_comment_answer" ON "qna_comments" USING btree ("answer_id");--> statement-breakpoint +CREATE INDEX "idx_comment_parent" ON "qna_comments" USING btree ("parent_comment_id");
\ No newline at end of file |
