Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/
**/*-secret.json
**/*.sh
.idea
.env
.env
test.js
96 changes: 96 additions & 0 deletions Week1/prep/prep-exe.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
-- Очищаем существующие таблицы (для повторного запуска)
DROP TABLE IF EXISTS recipe_methods;
DROP TABLE IF EXISTS recipe_ingredients;
DROP TABLE IF EXISTS recipe_categories;
DROP TABLE IF EXISTS recipes;
DROP TABLE IF EXISTS cooking_methods;
DROP TABLE IF EXISTS ingredients;
DROP TABLE IF EXISTS main_ingredients;
DROP TABLE IF EXISTS categories;
DROP TABLE IF EXISTS cuisines;

---------------------------------------------------------
-- 1. Таблица кухонь (Italian, Chinese, Japanese…)
---------------------------------------------------------
CREATE TABLE cuisines (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 2. Таблица основных ингредиентов (мясо, рыба, овощи)
---------------------------------------------------------
CREATE TABLE main_ingredients (
id SERIAL PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 3. Таблица всех возможных ингредиентов (морковь, масло, соль)
---------------------------------------------------------
CREATE TABLE ingredients (
id SERIAL PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 4. Таблица категорий (суп, салат, десерт, завтрак)
---------------------------------------------------------
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 5. Таблица методов приготовления (жарка, запекание, варка)
---------------------------------------------------------
CREATE TABLE cooking_methods (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 6. Главная таблица рецептов
---------------------------------------------------------
CREATE TABLE recipes (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
cuisine_id INT,
main_ingredient_id INT,
FOREIGN KEY (cuisine_id) REFERENCES cuisines(id),
FOREIGN KEY (main_ingredient_id) REFERENCES main_ingredients(id)
);

---------------------------------------------------------
-- 7. Связь рецепт ↔ категории (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_categories (
recipe_id INT NOT NULL,
category_id INT NOT NULL,
PRIMARY KEY (recipe_id, category_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);

---------------------------------------------------------
-- 8. Связь рецепт ↔ ингредиенты (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_ingredients (
recipe_id INT NOT NULL,
ingredient_id INT NOT NULL,
amount VARCHAR(50), -- например "200 г", "1 ст.л."
PRIMARY KEY (recipe_id, ingredient_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)
);

---------------------------------------------------------
-- 9. Связь рецепт ↔ методы приготовления (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_methods (
recipe_id INT NOT NULL,
method_id INT NOT NULL,
PRIMARY KEY (recipe_id, method_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (method_id) REFERENCES cooking_methods(id)
);
Binary file added Week2/prep/Database ER diagram (crow's foot).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week2/prep/Lucid connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions Week2/prep/w1-prep-exe.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- Очищаем существующие таблицы (для повторного запуска) -- Drop existing tables (for re-running the script)
DROP TABLE IF EXISTS cuisines CASCADE;
DROP TABLE IF EXISTS main_ingredients CASCADE;
DROP TABLE IF EXISTS ingredients CASCADE;
DROP TABLE IF EXISTS categories CASCADE;
DROP TABLE IF EXISTS cooking_methods CASCADE;
DROP TABLE IF EXISTS recipes CASCADE;
DROP TABLE IF EXISTS recipe_categories CASCADE;
DROP TABLE IF EXISTS recipe_ingredients CASCADE;
DROP TABLE IF EXISTS recipe_methods CASCADE;
DROP TABLE IF EXISTS recipe_ingredient_amounts CASCADE;



---------------------------------------------------------
-- 1. Таблица кухонь (Italian, Chinese, Japanese…) -- Table of Cuisines (Italian, Chinese, Japanese…)
---------------------------------------------------------
CREATE TABLE cuisines (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 2. Таблица основных ингредиентов (мясо, рыба, овощи) -- Table of Main Ingredients (meat, fish, vegetables)
---------------------------------------------------------
CREATE TABLE main_ingredients (
id SERIAL PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 3. Таблица всех возможных ингредиентов (морковь, масло, соль) -- Table of All Possible Ingredients (carrot, oil, salt)
---------------------------------------------------------
CREATE TABLE ingredients (
id SERIAL PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 4. Таблица категорий (суп, салат, десерт, завтрак) -- Table of Categories (soup, salad, dessert, breakfast)
---------------------------------------------------------
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 5. Таблица методов приготовления (жарка, запекание, варка) -- Table of Cooking Methods (frying, baking, boiling)
---------------------------------------------------------
CREATE TABLE cooking_methods (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE
);

---------------------------------------------------------
-- 6. Главная таблица рецептов -- Main Recipes Table
---------------------------------------------------------
CREATE TABLE recipes (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
cuisine_id INT,
main_ingredient_id INT,
FOREIGN KEY (cuisine_id) REFERENCES cuisines(id),
FOREIGN KEY (main_ingredient_id) REFERENCES main_ingredients(id)
);

---------------------------------------------------------
-- 7. Связь рецепт ↔ категории (many-to-many) -- Recipe ↔ Categories Relationship (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_categories (
recipe_id INT NOT NULL,
category_id INT NOT NULL,
PRIMARY KEY (recipe_id, category_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);

---------------------------------------------------------
-- 8. Связь рецепт ↔ ингредиенты (many-to-many) -- Recipe ↔ Ingredients Relationship (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_ingredients (
recipe_id INT NOT NULL,
ingredient_id INT NOT NULL,
amount VARCHAR(50), -- например "200 г", "1 ст.л."
PRIMARY KEY (recipe_id, ingredient_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)
);

---------------------------------------------------------
-- 9. Связь рецепт ↔ методы приготовления (many-to-many) -- Recipe ↔ Cooking Methods Relationship (many-to-many)
---------------------------------------------------------
CREATE TABLE recipe_methods (
recipe_id INT NOT NULL,
method_id INT NOT NULL,
PRIMARY KEY (recipe_id, method_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (method_id) REFERENCES cooking_methods(id)
);

---------------------------------------------------------
-- 10. кол-во ингредиентов в рецепте -- Quantity of Ingredients in Recipe
---------------------------------------------------------
CREATE TABLE recipe_ingredient_amounts (
recipe_id INT NOT NULL,
ingredient_id INT NOT NULL,
amount VARCHAR(50) NOT NULL, -- например "200 г", "1 ст.л."
PRIMARY KEY (recipe_id, ingredient_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(id),
FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)
);
98 changes: 98 additions & 0 deletions Week2/prep/w2-prep-insert-mok-data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
-- ==========================================
-- Mock data inserts for Week 2 Prep Exercise
-- ==========================================

-- 1. Cuisines
INSERT INTO cuisines (name) VALUES
('Japanese')
ON CONFLICT (name) DO NOTHING;

-- 2. Main ingredients
INSERT INTO main_ingredients (name) VALUES
('Cheese'),
('Vegetables'),
('Pasta'),
('Eggs')
ON CONFLICT (name) DO NOTHING;

-- 3. Categories
INSERT INTO categories (name) VALUES
('Cake'),
('No-Bake'),
('Vegetarian'),
('Vegan'),
('Gluten-Free'),
('Japanese')
ON CONFLICT (name) DO NOTHING;

-- 4. Ingredients
INSERT INTO ingredients (name) VALUES
('Cheese'),
('Vegetables'),
('Pasta'),
('Eggs'),
('Condensed milk'),
('Cream Cheese'),
('Lemon Juice'),
('Pie Crust'),
('Cherry Jam'),
('Brussels Sprouts'),
('Sesame seeds'),
('Pepper'),
('Salt'),
('Olive oil'),
('Macaroni'),
('Butter'),
('Flour'),
('Milk'),
('Shredded Cheddar cheese'),
('Soy sauce'),
('Sugar')
ON CONFLICT (name) DO NOTHING;

-- 5. Recipes
INSERT INTO recipes (name, cuisine_id, main_ingredient_id) VALUES
('No-Bake Cheesecake', NULL, 1),
('Roasted Brussels Sprouts', NULL, 2),
('Mac & Cheese', NULL, 3),
('Tamagoyaki Japanese Omelette', 1, 4)
ON CONFLICT DO NOTHING;

-- 6. Recipe ↔ Categories
INSERT INTO recipe_categories (recipe_id, category_id) VALUES
(1, 1), (1, 2), (1, 3),
(2, 4), (2, 5),
(3, 3),
(4, 3), (4, 6)
ON CONFLICT DO NOTHING;

-- 7. Recipe ↔ Ingredients
INSERT INTO recipe_ingredients (recipe_id, ingredient_id, amount) VALUES
-- No-Bake Cheesecake
(1, 5, '200 ml'),
(1, 6, '250 g'),
(1, 7, '1 tbsp'),
(1, 8, '1 crust'),
(1, 9, '2 tbsp'),
-- Roasted Brussels Sprouts
(2, 10, '500 g'),
(2, 7, '1 tbsp'),
(2, 11, '1 tsp'),
(2, 12, '1 tsp'),
(2, 13, '1 tsp'),
(2, 14, '2 tbsp'),
-- Mac & Cheese
(3, 15, '200 g'),
(3, 16, '50 g'),
(3, 17, '2 tbsp'),
(3, 13, '1 tsp'),
(3, 12, '1 tsp'),
(3, 18, '200 ml'),
(3, 19, '150 g'),
-- Tamagoyaki Japanese Omelette
(4, 4, '4'),
(4, 20, '1 tbsp'),
(4, 21, '1 tsp'),
(4, 13, '1 tsp'),
(4, 14, '1 tbsp')
ON CONFLICT DO NOTHING;
24 changes: 24 additions & 0 deletions Week2/prep/w2-request.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- 1. All vegetarian recipes with potatoes (но картошки нет в данных)
SELECT r.name AS recipe_name
FROM recipes r
JOIN recipe_categories rc ON r.id = rc.recipe_id
JOIN categories c ON rc.category_id = c.id
WHERE c.name = 'Vegetarian';

-- 2. All cakes that do not need baking
SELECT r.name AS recipe_name
FROM recipes r
JOIN recipe_categories rc1 ON r.id = rc1.recipe_id
JOIN categories c1 ON rc1.category_id = c1.id
JOIN recipe_categories rc2 ON r.id = rc2.recipe_id
JOIN categories c2 ON rc2.category_id = c2.id
WHERE c1.name = 'Cake' AND c2.name = 'No-Bake';

-- 3. All vegan and Japanese recipes
SELECT r.name AS recipe_name
FROM recipes r
JOIN recipe_categories rc1 ON r.id = rc1.recipe_id
JOIN categories c1 ON rc1.category_id = c1.id
JOIN recipe_categories rc2 ON r.id = rc2.recipe_id
JOIN categories c2 ON rc2.category_id = c2.id
WHERE c1.name = 'Vegan' AND c2.name = 'Japanese';
34 changes: 34 additions & 0 deletions Week3/assignment/3.1.md

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! Makes sense!

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
QUESTIONS:
1 - What columns violate 1NF?
2 - What entities do you recognize that could be extracted?
3 - Name all the tables and columns that would make a 3NF compliant solution.

ANSWERS:
1 - colums "food_code" and "food_description" - have the same problem. They have differebt data separated by comas
2 - Members - Club members
Dinners - Dinners (events)
Venues - Venues
Foods - Foods

Of cource for the real entities extraction we need more tables and info. HoweverHowever, for me personally, this is a tricky question,
because in my experience (outside of programming), we can manipulate data and play with definitions. So, theoretically.
I'd classify the member address in the task as a property rather than an entity (based solely on the column names).
However, this isn't explicitly stated, so I can assume that an address is also an entity, just in a different context.

3 - table: Members
columns: Member_id, Member_name, Member_address

tables: Venues
columns: Venue_code, Venue_description,

tables: Foods
columns: Food_code, Food_description

tables: Dinners
columns: Dinner_id, Dinner_date, venue_code

tables: dinner_attendees
columns: Dinner_id, member_id

tables: dinner_foods
columns: Dinner_id, food_code
Loading