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
|
order_id INT, -- This should be not null
|
||||||
status VARCHAR(50) NOT NULL CHECK (status IN ('freezer', 'delivered', 'blocked')),
|
status VARCHAR(50) NOT NULL CHECK (status IN ('freezer', 'delivered', 'blocked')),
|
||||||
production_date DATE NOT NULL,
|
production_date DATE NOT NULL,
|
||||||
delivery_date DATE DEFAULT NULL,
|
|
||||||
FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id)
|
FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id)
|
||||||
FOREIGN KEY (order_id) REFERENCES orders(order_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
|
-- Views
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
@ -105,13 +114,14 @@ CREATE TABLE IF NOT EXISTS pallets (
|
||||||
-- Pallet
|
-- Pallet
|
||||||
CREATE VIEW IF NOT EXISTS pallets_view AS
|
CREATE VIEW IF NOT EXISTS pallets_view AS
|
||||||
SELECT
|
SELECT
|
||||||
pallet_id,
|
pallets.pallet_id,
|
||||||
cookie_name,
|
cookie_name,
|
||||||
order_id,
|
pallets.order_id,
|
||||||
status,
|
status,
|
||||||
production_date,
|
production_date,
|
||||||
delivery_date
|
delivery_date
|
||||||
FROM pallets
|
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;
|
PRAGMA foreign_keys = ON;
|
|
@ -165,6 +165,8 @@ public class Database {
|
||||||
query.append("status = " + (blocked.get() ? "'blocked'" : "'freezer'"));
|
query.append("status = " + (blocked.get() ? "'blocked'" : "'freezer'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(query.toString());
|
||||||
|
|
||||||
ResultSet result = stmt.executeQuery(query.toString());
|
ResultSet result = stmt.executeQuery(query.toString());
|
||||||
|
|
||||||
// Rename the columns
|
// Rename the columns
|
||||||
|
@ -267,6 +269,8 @@ public class Database {
|
||||||
insertPallet.setString(2, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
insertPallet.setString(2, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
||||||
insertPallet.setString(3, "freezer");
|
insertPallet.setString(3, "freezer");
|
||||||
|
|
||||||
|
System.out.println(insertPallet.toString());
|
||||||
|
|
||||||
insertPallet.executeUpdate();
|
insertPallet.executeUpdate();
|
||||||
conn.commit();
|
conn.commit();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
Loading…
Reference in a new issue