DATABASE SCHEMA
This commit is contained in:
parent
cbed41abb3
commit
e693a67b73
25 changed files with 222 additions and 41 deletions
|
|
@ -1,5 +1,5 @@
|
|||
--------------------------------------------
|
||||
-- Recipe/Cookie related tables
|
||||
-- Logistics/orders related tables
|
||||
--------------------------------------------
|
||||
|
||||
-- Our known customers, may need more fields
|
||||
|
|
@ -14,19 +14,71 @@ CREATE TABLE IF NOT EXISTS customers (
|
|||
CREATE TABLE IF NOT EXISTS orders (
|
||||
order_id int PRIMARY KEY,
|
||||
customer_id int,
|
||||
order_date date DEFAULT NOW,
|
||||
delivery_date date, -- Set when the order hits the truck
|
||||
order_datetime datetime DEFAULT NOW,
|
||||
preferred_delivery_date DATE, --the table Delivery tells when the delivery is arrived
|
||||
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
|
||||
--------------------------------------------
|
||||
-- Recipe/Cookie related tables
|
||||
--------------------------------------------
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
|
||||
-- Recipes for all the cookies (essentially a list of cookies)
|
||||
CREATE TABLE IF NOT EXISTS recipes (
|
||||
recipe_id int PRIMARY KEY,
|
||||
recipe_name varchar(100) UNIQUE -- Cookie name
|
||||
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)
|
||||
);
|
||||
|
||||
-- "The company has a raw materials warehouse in which
|
||||
|
|
@ -37,47 +89,24 @@ CREATE TABLE IF NOT EXISTS recipes (
|
|||
CREATE TABLE IF NOT EXISTS ingredients (
|
||||
ingredient_id int PRIMARY KEY,
|
||||
ingredient_name varchar(100),
|
||||
amount int,
|
||||
unit varchar(50)
|
||||
in_stock float,
|
||||
unit varchar(50),
|
||||
amout_purchase float,
|
||||
last_delivery DATETIME
|
||||
);
|
||||
|
||||
-- Describes what ingredients goes into what recipe
|
||||
-- Each recipe requires 'amount' of 'ingredient'
|
||||
CREATE TABLE IF NOT EXISTS recipe_contents (
|
||||
recipe_id int,
|
||||
-- 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
|
||||
ingredient_id int,
|
||||
amount int,
|
||||
PRIMARY KEY (recipe_id, ingredient_id)
|
||||
amout_purchase float,
|
||||
delivery_datetime DATETIME,
|
||||
FOREIGN KEY(ingreident_id) REFERENCES ingridients(ingridient_id)
|
||||
);
|
||||
*/
|
||||
|
||||
--------------------------------------------
|
||||
-- Pallet related tables
|
||||
--------------------------------------------
|
||||
|
||||
-- Pallets are used to store cookies for delivery
|
||||
CREATE TABLE IF NOT EXISTS pallets (
|
||||
pallet_id int PRIMARY KEY,
|
||||
recipe_id int,
|
||||
order_id int,
|
||||
FOREIGN KEY (recipe_id) REFERENCES recipes(recipe_id),
|
||||
FOREIGN KEY (order_id) REFERENCES Orders(order_id)
|
||||
);
|
||||
|
||||
-- What does the pallet contain?
|
||||
CREATE TABLE IF NOT EXISTS pallet_contents (
|
||||
pallet_id int,
|
||||
ingredient_id int,
|
||||
amount int,
|
||||
PRIMARY KEY (pallet_id, ingredient_id),
|
||||
FOREIGN KEY (pallet_id) REFERENCES pallets(pallet_id),
|
||||
FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id)
|
||||
);
|
||||
|
||||
-- Has an order been delivered?
|
||||
-- When the truck is loaded, a delivery is considered done
|
||||
CREATE TABLE IF NOT EXISTS delivery_bill (
|
||||
delivery_id int PRIMARY KEY,
|
||||
order_id int,
|
||||
delivery_date date DEFAULT NOW,
|
||||
FOREIGN KEY (order_id) REFERENCES Orders(order_id)
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue