movie-service/drizzle/0000_mixed_the_watchers.sql

27 lines
1022 B
SQL

CREATE TABLE "categories" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"title" varchar(255) NOT NULL,
"slug" varchar(255),
CONSTRAINT "categories_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "movies" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"title" varchar(255) NOT NULL,
"slug" varchar(255),
"description" text NOT NULL,
"poster" text,
"duration" integer DEFAULT 0 NOT NULL,
"release_year" integer,
"release_date" timestamp,
"rating_age" integer DEFAULT 0,
"country" varchar(255),
"category_id" uuid,
CONSTRAINT "movies_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
ALTER TABLE "movies" ADD CONSTRAINT "movies_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action;