This repository was archived by the owner on Mar 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathKitchenly.sql
More file actions
73 lines (61 loc) · 1.75 KB
/
Kitchenly.sql
File metadata and controls
73 lines (61 loc) · 1.75 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
CREATE TYPE "recipe_type" AS ENUM (
'snack',
'main',
'side'
);
CREATE TYPE "unit_of_measure" AS ENUM (
'g',
'kg',
'oz',
'lbs',
'tsp',
'tbsp',
'cup'
);
CREATE TABLE "users" (
"id" varchar(255) PRIMARY KEY,
"email" varchar(60) UNIQUE NOT NULL,
"password_has" varchar(255) NOT NULL,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "recipes" (
"id" bigserial PRIMARY KEY,
"user_id" varchar(255) NOT NULL,
"name" varchar(25) NOT NULL,
"image_url" varchar(255),
"description" text NOT NULL,
"servings" smallint NOT NULL,
"calories" smallint,
"fat" smallint,
"carbs" smallint,
"protein" smallint,
"recipe_type" recipe_type NOT NULL,
"created_at" timestamp DEFAULT (now())
);
CREATE TABLE "ingredient_list" (
"id" bigserial PRIMARY KEY,
"recipe_id" bigint NOT NULL,
"ingredient_id" bigint NOT NULL,
"quantity" smallint NOT NULL
);
CREATE TABLE "ingredients" (
"id" bigserial PRIMARY KEY,
"title" varchar NOT NULL,
"unit_of_measure" unit_of_measure NOT NULL,
"food_type" bigint NOT NULL
);
CREATE TABLE "recipe_data" (
"id" bigserial PRIMARY KEY,
"recipe_id" bigint NOT NULL,
"step_order" smallint UNIQUE NOT NULL,
"statement" text NOT NULL
);
CREATE TABLE "food_type" (
"id" bigserial PRIMARY KEY,
"title" varchar NOT NULL
);
ALTER TABLE "recipes" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");
ALTER TABLE "ingredient_list" ADD FOREIGN KEY ("ingredient_id") REFERENCES "ingredients" ("id");
ALTER TABLE "ingredients" ADD FOREIGN KEY ("food_type") REFERENCES "food_type" ("id");
ALTER TABLE "ingredient_list" ADD FOREIGN KEY ("recipe_id") REFERENCES "recipes" ("id") ON DELETE CASCADE;
ALTER TABLE "recipe_data" ADD FOREIGN KEY ("recipe_id") REFERENCES "recipes" ("id") ON DELETE CASCADE;