CrustyCookiesAPI/app/Migrations/create-schema.sql

113 lines
3.1 KiB
MySQL
Raw Normal View History

2024-05-03 05:30:52 +02:00
--------------------------------------------
2024-05-03 18:10:32 +02:00
-- Logistics/orders related tables
2024-05-03 05:30:52 +02:00
--------------------------------------------
-- Our known customers, may need more fields
2024-05-03 01:59:07 +02:00
CREATE TABLE IF NOT EXISTS customers (
customer_id int PRIMARY KEY,
2024-05-03 05:30:52 +02:00
customer_name varchar(100),
customer_address varchar(255)
);
2024-05-03 05:30:52 +02:00
-- Orders from customers.
-- Keep in mind that the delivery_date may be NULL
2024-05-03 08:16:21 +02:00
CREATE TABLE IF NOT EXISTS orders (
2024-05-03 05:30:52 +02:00
order_id int PRIMARY KEY,
customer_id int,
2024-05-03 18:10:32 +02:00
order_datetime datetime DEFAULT NOW,
preferred_delivery_date DATE, --the table Delivery tells when the delivery is arrived
2024-05-03 05:30:52 +02:00
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
2024-05-03 18:10:32 +02:00
CREATE TABLE IF NOT EXISTS delivery (
order_id INT,
truck_id INT,
delivery_datetime DATETIME,
PRIMARY KEY (order_id, truck_id),
FOREIGN KEY (order_id) REFERENCES orders(order_id)
);
CREATE TABLE OrderSpec (
order_id INT,
cookie_id INT,
quantity INT,
PRIMARY KEY (orderID, cookieID),
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (cookie_id) REFERENCES Cookies(cookie_id)
);
CREATE TABLE IF NOT EXISTS pallet (
pallet_id INT PRIMARY KEY,
order_id INT,
cookie_id INT,
production_datetime DATETIME,
is_blocked BOOLEAN,
pallet_location VARCHAR(255),
FOREIGN KEY (order_id) REFERENCES Orders(order_id),
FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id)
);
2024-05-03 05:30:52 +02:00
--------------------------------------------
-- Recipe/Cookie related tables
--------------------------------------------
2024-05-03 18:10:32 +02:00
CREATE TABLE IF NOT EXISTS cookies (
cookie_id INT PRIMARY KEY,
recipe_id INT,
cookie_name VARCHAR(255),
price INT,
FOREIGN KEY (recipeID) REFERENCES Recipe(recipeID)
);
2024-05-03 05:30:52 +02:00
-- Recipes for all the cookies (essentially a list of cookies)
2024-05-03 01:59:07 +02:00
CREATE TABLE IF NOT EXISTS recipes (
2024-05-03 05:30:52 +02:00
recipe_id int PRIMARY KEY,
2024-05-03 18:10:32 +02:00
cookie_id int,
recipe_name varchar(100) UNIQUE, -- Cookie name
FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id)
);
--weak table which descirbies the amout of the ingredient
--needed for a recipe
CREATE TABLE RecipeIngredients (
ingredient_id INT,
recipe_id INT,
quantity FLOAT,
PRIMARY KEY (ingredientID, recipeID),
FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id),
FOREIGN KEY (recipe_id) REFERENCES recipes(recipe_id)
);
2024-05-03 05:30:52 +02:00
-- "The company has a raw materials warehouse in which
-- all ingredients used in their production are stored."
-- Describes ingredients and stock.
-- Each ingredient has 'amount' of 'unit' in stock
2024-05-03 01:59:07 +02:00
CREATE TABLE IF NOT EXISTS ingredients (
ingredient_id int PRIMARY KEY,
2024-05-03 05:30:52 +02:00
ingredient_name varchar(100),
2024-05-03 18:10:32 +02:00
in_stock float,
unit varchar(50),
amout_purchase float,
last_delivery DATETIME
);
2024-05-03 18:10:32 +02:00
-- use this table instead of amount_purchase and last_delivery attributes
-- in ingrdients table if the assigment want us to have a purchase history
-- for every ingredient order.
/*
CREATE TABLE IF NOT EXISTS ingredient_purchase(
ingredientOrder_id
2024-05-03 05:30:52 +02:00
ingredient_id int,
2024-05-03 18:10:32 +02:00
amout_purchase float,
delivery_datetime DATETIME,
FOREIGN KEY(ingreident_id) REFERENCES ingridients(ingridient_id)
);
2024-05-03 18:10:32 +02:00
*/