Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

0000_outstanding_silvermane.sql

43 lines1.5 KB

1CREATE TABLE "boards" (
2 "id" text PRIMARY KEY NOT NULL,
3 "name" text NOT NULL,
4 "description" text,
5 "created_at" date NOT NULL,
6 "project_id" text NOT NULL
7);
8--> statement-breakpoint
9CREATE TABLE "projects" (
10 "id" text PRIMARY KEY NOT NULL,
11 "name" text NOT NULL,
12 "description" text NOT NULL,
13 "created_at" date NOT NULL,
14 CONSTRAINT "projects_name_unique" UNIQUE("name")
15);
16--> statement-breakpoint
17CREATE TABLE "seed_script_runs" (
18 "id" text PRIMARY KEY NOT NULL,
19 "created_at" date NOT NULL,
20 "state" text
21);
22--> statement-breakpoint
23CREATE TABLE "todo_items" (
24 "id" text PRIMARY KEY NOT NULL,
25 "title" text NOT NULL,
26 "description" text,
27 "created_at" date NOT NULL,
28 "board_id" text NOT NULL,
29 "priority" integer DEFAULT 0,
30 "position" text NOT NULL
31);
32--> statement-breakpoint
33CREATE TABLE "users" (
34 "id" text PRIMARY KEY NOT NULL,
35 "name" text NOT NULL,
36 "age" integer NOT NULL,
37 "email" text NOT NULL,
38 CONSTRAINT "users_email_unique_tempdbid" UNIQUE("email")
39);
40--> statement-breakpoint
41ALTER TABLE "boards" ADD CONSTRAINT "boards_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
42ALTER TABLE "todo_items" ADD CONSTRAINT "todo_items_board_id_boards_id_fk" FOREIGN KEY ("board_id") REFERENCES "public"."boards"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
43CREATE INDEX "todo_items_board_id_position_idx" ON "todo_items" USING btree ("board_id","position");