diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index 57c565d..28d1d15 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -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; \ No newline at end of file diff --git a/app/src/main/java/krusty/Database.java b/app/src/main/java/krusty/Database.java index 6c4a6dc..6f59bbf 100644 --- a/app/src/main/java/krusty/Database.java +++ b/app/src/main/java/krusty/Database.java @@ -165,6 +165,8 @@ public class Database { query.append("status = " + (blocked.get() ? "'blocked'" : "'freezer'")); } + System.out.println(query.toString()); + ResultSet result = stmt.executeQuery(query.toString()); // Rename the columns @@ -267,6 +269,8 @@ public class Database { insertPallet.setString(2, new SimpleDateFormat("yyyy-MM-dd").format(new Date())); insertPallet.setString(3, "freezer"); + System.out.println(insertPallet.toString()); + insertPallet.executeUpdate(); conn.commit(); } catch (SQLException e) {