2024-05-03 05:30:52 +02:00
|
|
|
--------------------------------------------
|
|
|
|
-- Recipe/Cookie related tables
|
|
|
|
--------------------------------------------
|
|
|
|
|
2024-05-04 13:36:27 +02:00
|
|
|
-- Holds the different types of cookies we can make.
|
2024-05-04 13:37:25 +02:00
|
|
|
CREATE TABLE cookies (
|
2024-05-04 13:36:27 +02:00
|
|
|
cookie_id INT PRIMARY KEY,
|
2024-05-04 13:38:10 +02:00
|
|
|
cookie_name VARCHAR(50) NOT NULL UNIQUE
|
2024-05-04 13:36:27 +02:00
|
|
|
);
|
|
|
|
|
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 (
|
2024-05-04 13:33:24 +02:00
|
|
|
customer_id INT PRIMARY KEY,
|
|
|
|
customer_name VARCHAR(50) NOT NULL,
|
2024-05-04 13:34:22 +02:00
|
|
|
customer_address VARCHAR(50) NOT NULL
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 05:30:52 +02:00
|
|
|
-- Orders from customers.
|
2024-05-03 08:16:21 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS orders (
|
2024-05-04 13:33:24 +02:00
|
|
|
order_id INT PRIMARY KEY,
|
|
|
|
customer_id INT NOT NULL,
|
|
|
|
cookie_id INT NOT NULL,
|
|
|
|
order_date DATE NOT NULL DEFAULT CURRENT_DATE CHECK (order_date >= CURRENT_DATE),
|
|
|
|
FOREIGN KEY (customer_id) REFERENCES customer(customer_id),
|
|
|
|
FOREIGN KEY (cookie_id) REFERENCES cookie(cookie_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 05:30:52 +02:00
|
|
|
--------------------------------------------
|
|
|
|
-- Recipe/Cookie related tables
|
|
|
|
--------------------------------------------
|
|
|
|
|
|
|
|
-- Describes ingredients and stock.
|
2024-05-04 13:33:24 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS raw_materials (
|
|
|
|
ingredient_id INT PRIMARY KEY,
|
|
|
|
ingredient_name VARCHAR(50) NOT NULL UNIQUE,
|
|
|
|
ingredient_quantity INT NOT NULL,
|
|
|
|
unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml'))
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-04 13:33:24 +02:00
|
|
|
-- When did we get the ingredients?
|
|
|
|
CREATE TABLE IF NOT EXISTS raw_materials_deliveries (
|
|
|
|
delivery_id INT PRIMARY KEY,
|
|
|
|
ingredient_id INT NOT NULL,
|
|
|
|
delivery_date DATE NOT NULL,
|
|
|
|
delivery_quantity INT NOT NULL,
|
|
|
|
unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml')),
|
|
|
|
FOREIGN KEY (ingredient_id) REFERENCES raw_materials(ingredient_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 05:30:52 +02:00
|
|
|
--------------------------------------------
|
|
|
|
-- Pallet related tables
|
|
|
|
--------------------------------------------
|
|
|
|
|
|
|
|
-- Pallets are used to store cookies for delivery
|
|
|
|
CREATE TABLE IF NOT EXISTS pallets (
|
2024-05-04 13:33:24 +02:00
|
|
|
pallet_id INT PRIMARY KEY,
|
|
|
|
cookie_id INT NOT NULL,
|
|
|
|
order_id INT NOT NULL,
|
|
|
|
status VARCHAR(50) NOT NULL CHECK (status IN ('freezer', 'delivered', 'blocked')),
|
|
|
|
production_date DATE NOT NULL,
|
|
|
|
FOREIGN KEY (cookie_id) REFERENCES cookie(cookie_id)
|
|
|
|
FOREIGN KEY (order_id) REFERENCES orders(order_id)
|
2024-04-22 13:27:42 +02:00
|
|
|
);
|
|
|
|
|
2024-05-03 05:30:52 +02:00
|
|
|
-- Has an order been delivered?
|
2024-05-04 13:33:24 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS deliveries (
|
|
|
|
delivery_id INT PRIMARY KEY,
|
|
|
|
pallet_id INT NOT NULL,
|
|
|
|
customer_name VARCHAR(50) NOT NULL,
|
|
|
|
delivery_date DATE NOT NULL DEFAULT CURRENT_DATE CHECK (delivery_date >= CURRENT_DATE),
|
|
|
|
FOREIGN KEY (pallet_id) REFERENCES pallets(pallet_id)
|
2024-05-03 05:30:52 +02:00
|
|
|
);
|