New table for deliveries
This commit is contained in:
parent
1969d2f98f
commit
b4b12b31a2
2 changed files with 18 additions and 4 deletions
|
@ -93,11 +93,20 @@ CREATE TABLE IF NOT EXISTS pallets (
|
|||
order_id INT, -- This should be not null
|
||||
status VARCHAR(50) NOT NULL CHECK (status IN ('freezer', 'delivered', 'blocked')),
|
||||
production_date DATE NOT NULL,
|
||||
delivery_date DATE DEFAULT NULL,
|
||||
FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id)
|
||||
FOREIGN KEY (order_id) REFERENCES orders(order_id)
|
||||
);
|
||||
|
||||
-- Connects pallets to orders
|
||||
CREATE TABLE IF NOT EXISTS deliveries (
|
||||
delivery_date DATE DEFAULT NOW,
|
||||
order_id INT NOT NULL,
|
||||
pallet_id INT NOT NULL,
|
||||
FOREIGN KEY (order_id) REFERENCES orders(order_id),
|
||||
FOREIGN KEY (pallet_id) REFERENCES pallets(pallet_id),
|
||||
PRIMARY KEY (order_id, pallet_id)
|
||||
);
|
||||
|
||||
--------------------------------------------
|
||||
-- Views
|
||||
--------------------------------------------
|
||||
|
@ -105,13 +114,14 @@ CREATE TABLE IF NOT EXISTS pallets (
|
|||
-- Pallet
|
||||
CREATE VIEW IF NOT EXISTS pallets_view AS
|
||||
SELECT
|
||||
pallet_id,
|
||||
pallets.pallet_id,
|
||||
cookie_name,
|
||||
order_id,
|
||||
pallets.order_id,
|
||||
status,
|
||||
production_date,
|
||||
delivery_date
|
||||
FROM pallets
|
||||
JOIN cookies ON pallets.cookie_id = cookies.cookie_id;
|
||||
LEFT JOIN cookies ON pallets.cookie_id = cookies.cookie_id
|
||||
LEFT JOIN deliveries ON pallets.pallet_id = deliveries.pallet_id;
|
||||
|
||||
PRAGMA foreign_keys = ON;
|
Loading…
Add table
Add a link
Reference in a new issue