From eb38c47af7600a7470bd4348a720b2cdb7a3e722 Mon Sep 17 00:00:00 2001 From: Ivan Bogosavljevic <136277150+Nuvve@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:19:16 +0200 Subject: [PATCH 1/3] Uppdaterad sqlkod --- sqlCode | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/sqlCode b/sqlCode index 2205047..9a1dfff 100644 --- a/sqlCode +++ b/sqlCode @@ -1,8 +1,8 @@ DROP TABLE IF EXISTS OrderSpec; DROP TABLE IF EXISTS Recipe; DROP TABLE IF EXISTS Ingredient; -DROP TABLE IF EXISTS Cookie; DROP TABLE IF EXISTS Pallet; +DROP TABLE IF EXISTS Cookie; DROP TABLE IF EXISTS Orders; DROP TABLE IF EXISTS Customer; @@ -20,34 +20,32 @@ CREATE TABLE Orders ( FOREIGN KEY (customer_id) REFERENCES Customer(customer_id) ); +CREATE TABLE Cookie ( + name VARCHAR(255) PRIMARY KEY +); + CREATE TABLE Pallet ( pallet_id INT AUTO_INCREMENT PRIMARY KEY, order_id INT, - manufacture_date DATE, + manufacture_date DATETIME, delivery_date DATE, - blocked BOOLEAN, + blocked VARCHAR(255) DEFAULT 'no', + cookie_name VARCHAR(255), + FOREIGN KEY(cookie_name) REFERENCES Cookie(name), FOREIGN KEY (order_id) REFERENCES Orders(order_id) ); -CREATE TABLE Cookie ( - cookie_id INT AUTO_INCREMENT PRIMARY KEY, - pallet_id INT, - name VARCHAR(255), - FOREIGN KEY (pallet_id) REFERENCES Pallet(pallet_id) -); - CREATE TABLE OrderSpec ( order_id INT, - cookie_id INT, + cookie_name VARCHAR(255), quantity INT, - PRIMARY KEY (order_id, cookie_id), + PRIMARY KEY (order_id, cookie_name), FOREIGN KEY (order_id) REFERENCES Orders(order_id), - FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id) + FOREIGN KEY (cookie_name) REFERENCES Cookie(name) ); CREATE TABLE Ingredient ( - ingredient_id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255), + ingredient_name VARCHAR(255) PRIMARY KEY, stock INT, unit VARCHAR(50), delivery_date DATE, @@ -55,10 +53,10 @@ CREATE TABLE Ingredient ( ); CREATE TABLE Recipe ( - ingredient_id INT, - cookie_id INT, + ingredient_name VARCHAR(255), + cookie_name VARCHAR(255), amount FLOAT, - PRIMARY KEY (ingredient_id, cookie_id), - FOREIGN KEY (ingredient_id) REFERENCES Ingredient(ingredient_id), - FOREIGN KEY (cookie_id) REFERENCES Cookie(cookie_id) + PRIMARY KEY (ingredient_name, cookie_name), + FOREIGN KEY (ingredient_name) REFERENCES Ingredient(ingredient_name), + FOREIGN KEY (cookie_name) REFERENCES Cookie(name) ); From b4851455ddb520dd43ad33fb317545d0c68fee93 Mon Sep 17 00:00:00 2001 From: Ivan Bogosavljevic <136277150+Nuvve@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:19:51 +0200 Subject: [PATCH 2/3] Update initialdata --- initialdata | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/initialdata b/initialdata index 70e21a7..a127a07 100644 --- a/initialdata +++ b/initialdata @@ -16,7 +16,7 @@ INSERT INTO Cookie(name) VALUES ('Almond delight'), ('Berliner'); -INSERT INTO Ingredient(name, stock, unit) VALUES +INSERT INTO Ingredient(ingredient_name, stock, unit) VALUES ('Bread crumbs', 500000, 'g'), ('Butter', 500000, 'g'), ('Chocolate', 500000, 'g'), @@ -37,10 +37,11 @@ INSERT INTO Ingredient(name, stock, unit) VALUES ('Vanilla', 500000, 'g'), ('Wheat flour', 500000, 'g'); -INSERT INTO Recipe (ingredient_id, cookie_id, amount) VALUES - (2, 1, 450),(9, 1, 450),(11, 1, 190),(14, 1, 225), - (2, 2, 125),(3, 2, 50),(6, 2, 350),(8, 2, 750),(10, 2, 625),(16, 2, 375), - (2, 3, 250),(7, 3, 250),(12, 3, 750),(13, 3, 25),(19, 3, 25), - (2, 4, 200),(9, 4, 300),(15, 4, 4),(16, 4, 250),(18, 4, 2), - (2, 5, 400),(4, 5, 279),(5, 5, 10),(9, 5, 400),(16, 5, 270), - (2, 6, 250),(3, 6, 50),(7, 6, 50),(9, 6, 350),(11, 6, 100),(17, 6, 5); +INSERT INTO Recipe (ingredient_name, cookie_name, amount) VALUES + ('Butter', 'Nut ring', 450),('Flour', 'Nut ring', 450),('Icing sugar', 'Nut ring', 190),('Roasted, chopped nuts', 'Nut ring', 225), + ('Bread crumbs', 'Nut cookie', 125),('Chocolate', 'Nut cookie', 50),('Egg whites', 'Nut cookie', 350),('Fine-ground nuts', 'Nut cookie', 750),('Ground, roasted nuts', 'Nut cookie', 625),('Sugar', 'Nut cookie', 375), + ('Butter', 'Amneris', 250),('Eggs', 'Amneris', 250),('Marzipan', 'Amneris', 750),('Potato starch', 'Amneris', 25),('Wheat flour', 'Amneris', 25), + ('Butter', 'Tango', 200),('Flour', 'Tango', 300),('Sodium bicarbonate', 'Tango', 4),('Sugar', 'Tango', 250),('Vanilla', 'Tango', 2), + ('Butter', 'Almond delight', 400),('Chopped almonds', 'Almond delight', 279),('Cinnamon', 'Almond delight', 10),('Flour', 'Almond delight', 400),('Sugar', 'Almond delight', 270), + ('Butter', 'Berliner', 250),('Chocolate', 'Berliner', 50),('Eggs', 'Berliner', 50),('Flour', 'Berliner', 350),('Icing sugar', 'Berliner', 100),('Vanilla sugar', 'Berliner', 5); + From e241613a151ea438a2e6faaa3cf141ed5f1ef76f Mon Sep 17 00:00:00 2001 From: Ivan Bogosavljevic <136277150+Nuvve@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:30:01 +0200 Subject: [PATCH 3/3] Update sqlCode --- sqlCode | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sqlCode b/sqlCode index 9a1dfff..26d3a9f 100644 --- a/sqlCode +++ b/sqlCode @@ -7,17 +7,16 @@ DROP TABLE IF EXISTS Orders; DROP TABLE IF EXISTS Customer; CREATE TABLE Customer ( - customer_id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255), + name VARCHAR(255) PRIMARY KEY, address VARCHAR(255) ); CREATE TABLE Orders ( order_id INT AUTO_INCREMENT PRIMARY KEY, - customer_id INT, + customer_name VARCHAR(255), delivery_date DATE, order_date DATE, - FOREIGN KEY (customer_id) REFERENCES Customer(customer_id) + FOREIGN KEY (customer_name) REFERENCES Customer(name) ); CREATE TABLE Cookie (