Notra/drizzle/0000_cold_odin.sql

26 lines
1.1 KiB
SQL

CREATE TABLE "blocks" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"tag" varchar(100) DEFAULT '' NOT NULL,
"lines" json DEFAULT '["","","",""]'::json NOT NULL,
"isLocked" boolean DEFAULT false NOT NULL,
"order" integer DEFAULT 1 NOT NULL,
"noteId" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE "notes" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"title" varchar(50) DEFAULT 'Untitled' NOT NULL,
"creationTime" timestamp DEFAULT now() NOT NULL,
"lastEdited" timestamp DEFAULT now() NOT NULL,
"authorId" uuid NOT NULL
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"username" varchar(50) NOT NULL,
"password" varchar NOT NULL,
CONSTRAINT "users_username_unique" UNIQUE("username")
);
--> statement-breakpoint
ALTER TABLE "blocks" ADD CONSTRAINT "blocks_noteId_notes_id_fk" FOREIGN KEY ("noteId") REFERENCES "public"."notes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notes" ADD CONSTRAINT "notes_authorId_users_id_fk" FOREIGN KEY ("authorId") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;