-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-tables.sql
More file actions
49 lines (46 loc) · 1.7 KB
/
create-tables.sql
File metadata and controls
49 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Create product table first
CREATE TABLE IF NOT EXISTS "product" (
"id" serial PRIMARY KEY NOT NULL,
"slug" varchar(100) NOT NULL,
"name" text NOT NULL,
"name_en" text,
"name_fr" text,
"description" text NOT NULL,
"description_en" text,
"description_fr" text,
"is_active" boolean DEFAULT true NOT NULL,
"sort_order" integer DEFAULT 0 NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "product_slug_unique" UNIQUE("slug")
);
-- Create product_size table
CREATE TABLE IF NOT EXISTS "product_size" (
"id" serial PRIMARY KEY NOT NULL,
"product_id" integer NOT NULL,
"slug" varchar(100) NOT NULL,
"name" text NOT NULL,
"name_en" text,
"name_fr" text,
"dimensions" varchar(50) NOT NULL,
"price_amount" integer NOT NULL,
"sort_order" integer DEFAULT 0 NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
-- Create product_frame table
CREATE TABLE IF NOT EXISTS "product_frame" (
"id" serial PRIMARY KEY NOT NULL,
"product_id" integer NOT NULL,
"slug" varchar(100) NOT NULL,
"name" text NOT NULL,
"name_en" text,
"name_fr" text,
"price_amount" integer NOT NULL,
"sort_order" integer DEFAULT 0 NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
-- Add foreign keys
ALTER TABLE "product_frame" ADD CONSTRAINT "product_frame_product_id_product_id_fk" FOREIGN KEY ("product_id") REFERENCES "public"."product"("id") ON DELETE cascade ON UPDATE no action;
ALTER TABLE "product_size" ADD CONSTRAINT "product_size_product_id_product_id_fk" FOREIGN KEY ("product_id") REFERENCES "public"."product"("id") ON DELETE cascade ON UPDATE no action;