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
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';
11 changes: 11 additions & 0 deletions Week4/homework/task1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exercise 3.1 - folder task 1
exercise 3.1 (part 1) import - file import_csv.js
exercises 3.1 (parts 2 and 3)- file aggregations.js


exercises 3.2 - folder taks 2


## Why two containers?
1. Exercise 1: Simple MongoDB on port 27018
2. Exercise 2: MongoDB with a replica set on port 27017 (required for transactions)
Loading