From 09765fdb24583884a76c5eed0af4befa83fff77f Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 11:39:28 +0200 Subject: [PATCH 01/10] Some more tables and using views in query --- app/Migrations/create-schema.sql | 41 ++++++++++++++++++++++++-- app/src/main/java/krusty/Database.java | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index b0aee90..5c6664a 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -38,6 +38,27 @@ CREATE TABLE IF NOT EXISTS orders ( -------------------------------------------- -- Recipe/Cookie related tables -------------------------------------------- +-- Notes: the unit type can be defined in terms +-- of volume or weight instead. Here we choose +-- to use static si-prefixes in relevant tables. + +-- What types of ingredients do we handle +CREATE TABLE IF NOT EXISTS ingredients ( + ingredient_id INTEGER PRIMARY KEY, + ingredient_name VARCHAR(50) NOT NULL UNIQUE, + preferred_unit VARCHAR(50) NOT NULL CHECK (preferred_unit IN ('g', 'ml')) +); + +-- What ingredients are in what cookies +CREATE TABLE IF NOT EXISTS recipe_contents ( + cookie_id INT NOT NULL, + ingredient_id INT NOT NULL, + quantity INT NOT NULL, + unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml')), + PRIMARY KEY (cookie_id, ingredient_id), + FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id), + FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id) +); -- Describes ingredients and stock. CREATE TABLE IF NOT EXISTS raw_materials ( @@ -66,12 +87,28 @@ CREATE TABLE IF NOT EXISTS raw_materials_deliveries ( CREATE TABLE IF NOT EXISTS pallets ( pallet_id INTEGER PRIMARY KEY, cookie_id INT NOT NULL, - -- order_id INT NOT NULL, + 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) + FOREIGN KEY (order_id) REFERENCES orders(order_id) ); +-------------------------------------------- +-- Views +-------------------------------------------- + +-- Pallet +CREATE VIEW IF NOT EXISTS pallets_view AS +SELECT + pallet_id, + cookie_name, + order_id, + status, + production_date, + delivery_date +FROM pallets +JOIN cookies ON pallets.cookie_id = cookies.cookie_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 8ccc97f..67c1a93 100644 --- a/app/src/main/java/krusty/Database.java +++ b/app/src/main/java/krusty/Database.java @@ -127,7 +127,7 @@ public class Database { try { Statement stmt = conn.createStatement(); StringBuilder query = new StringBuilder( - "SELECT cookie_name, status FROM pallets JOIN cookies ON pallets.cookie_id = cookies.cookie_id"); + "SELECT cookie_name, status FROM pallets_view"); // r is validated here if (r.isPresent()) { From 72d03800238775e565f53f24d096df2e9ad271e6 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 11:47:26 +0200 Subject: [PATCH 02/10] Cleaning --- app/src/main/java/krusty/Database.java | 124 ++++++++++--------------- 1 file changed, 49 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/krusty/Database.java b/app/src/main/java/krusty/Database.java index 67c1a93..6c4a6dc 100644 --- a/app/src/main/java/krusty/Database.java +++ b/app/src/main/java/krusty/Database.java @@ -69,53 +69,56 @@ public class Database { Optional from = Optional.empty(); // Holds the from date Optional to = Optional.empty(); // Holds the to date - // First we need the cookie parameter - String cookie = req.queryParams("cookie"); + // Parameter validation block + { + // First we need the cookie parameter + String cookie = req.queryParams("cookie"); - // And the blocked parameter - String blocked_str = req.queryParams("blocked"); + // And the blocked parameter + String blocked_str = req.queryParams("blocked"); - // Then we need the date parameters - String from_str = req.queryParams("from"); - String to_str = req.queryParams("to"); + // Then we need the date parameters + String from_str = req.queryParams("from"); + String to_str = req.queryParams("to"); - // Fancy functional one-liner to get the recipe if the cookie is present - if (cookie != null) { - r = Optional.ofNullable(DefaultRecipes.recipes.stream() - .filter(recipe -> recipe.name.equals(cookie)) - .findFirst().orElse(null)); - } - - if (blocked_str != null) { - blocked = switch (blocked_str) { - case "yes" -> Optional.of(true); - case "no" -> Optional.of(false); - default -> Optional.empty(); - }; - } - - if(from_str != null) { - try { - from = Optional.of(new SimpleDateFormat("yyyy-MM-dd").parse(from_str)); - } catch (Exception e) { - from = Optional.empty(); + // Fancy functional one-liner to get the recipe if the cookie is present + if (cookie != null) { + r = Optional.ofNullable(DefaultRecipes.recipes.stream() + .filter(recipe -> recipe.name.equals(cookie)) + .findFirst().orElse(null)); } - } - if(to_str != null) { - try { - to = Optional.of(new SimpleDateFormat("yyyy-MM-dd").parse(to_str)); - } catch (Exception e) { + if (blocked_str != null) { + blocked = switch (blocked_str) { + case "yes" -> Optional.of(true); + case "no" -> Optional.of(false); + default -> Optional.empty(); + }; + } + + if (from_str != null) { + try { + from = Optional.of(new SimpleDateFormat("yyyy-MM-dd").parse(from_str)); + } catch (Exception e) { + from = Optional.empty(); + } + } + + if (to_str != null) { + try { + to = Optional.of(new SimpleDateFormat("yyyy-MM-dd").parse(to_str)); + } catch (Exception e) { + to = Optional.empty(); + } + } + + // If the interval is negative, reset the dates + if (from.isPresent() && to.isPresent() && from.get().after(to.get())) { + from = Optional.empty(); to = Optional.empty(); } } - // If the interval is negative, reset the dates - if(from.isPresent() && to.isPresent() && from.get().after(to.get())) { - from = Optional.empty(); - to = Optional.empty(); - } - // This type of code is unreadable, error prone and hard to maintain. // The fact that im responsible for this code makes my soul hurt. // This part almost made me write a simple query factory to handle this. @@ -134,7 +137,6 @@ public class Database { query.append(" WHERE cookie_name = '" + r.get().name + "'"); } - // If both from and to are present if (from.isPresent()) { String query_from = new SimpleDateFormat("yyyy-MM-dd").format(from.get()); @@ -144,7 +146,7 @@ public class Database { query.append(clause + "production_date >= '" + query_from + "'"); } - if(to.isPresent()) { + if (to.isPresent()) { String query_to = new SimpleDateFormat("yyyy-MM-dd").format(to.get()); // Super hacky, low quality code @@ -153,17 +155,7 @@ public class Database { query.append(clause + "production_date <= '" + query_to + "'"); } - // if (from.isPresent() && to.isPresent()) { - // String query_from = new SimpleDateFormat("yyyy-MM-dd").format(from.get()); - // String query_to = new SimpleDateFormat("yyyy-MM-dd").format(to.get()); - - // // Super hacky, low quality code - // String clause = query.toString().contains("WHERE") ? " AND " : " WHERE "; - - // query.append(clause + "production_date BETWEEN '" + query_from + "' AND '" + query_to + "'"); - // } - - if(blocked.isPresent()) { + if (blocked.isPresent()) { // This again String clause = query.toString().contains("WHERE") ? " AND " : " WHERE "; query.append(clause); @@ -173,10 +165,6 @@ public class Database { query.append("status = " + (blocked.get() ? "'blocked'" : "'freezer'")); } - query.append(";"); - - System.out.println(query.toString()); - ResultSet result = stmt.executeQuery(query.toString()); // Rename the columns @@ -226,13 +214,10 @@ public class Database { } if (r.isEmpty()) { - // Return 404 res.status(404); return "{}"; } - // System.out.println(r.get()); - try (PreparedStatement getRawMaterials = conn .prepareStatement("SELECT * FROM raw_materials WHERE ingredient_name = ?"); PreparedStatement decrementRawMaterials = conn.prepareStatement( @@ -248,23 +233,21 @@ public class Database { getRawMaterials.setString(1, i.name); ResultSet result = getRawMaterials.executeQuery(); if (!result.next()) { - // Rollback transaction conn.rollback(); - // Return 500 res.status(500); return "{}"; } + int amount_per_pallet = i.amount * 54; // 54 * 100 + // Check if we have enough raw materials - if (result.getInt("ingredient_quantity") < i.amount) { - // Rollback transaction + if (result.getInt("ingredient_quantity") < amount_per_pallet) { conn.rollback(); - // Return 500 res.status(500); return "{}"; } - decrementRawMaterials.setInt(1, i.amount * 54); // 5400 / 100 + decrementRawMaterials.setInt(1, amount_per_pallet); decrementRawMaterials.setString(2, i.name); decrementRawMaterials.executeUpdate(); } @@ -273,9 +256,7 @@ public class Database { getCookieId.setString(1, cookie); ResultSet cookie_rs = getCookieId.executeQuery(); if (!cookie_rs.next()) { - // Rollback transaction conn.rollback(); - // Return 500 res.status(500); return "{}"; } @@ -292,15 +273,7 @@ public class Database { System.out.printf("Error starting transaction: \n%s", e); } - // TODO: NOT DONE - - // 1. Get query param - // 2. Check if cookie exists (is in DefaultRecipes) - // 3. Start transaction - // 3. Check with db if raw materials are available -> decrement if so - // 4. Insert into pallets - // 5. Commit transaction - // 6. Return pallet id + res.status(201); return "{}"; } @@ -347,6 +320,7 @@ public class Database { // The script location is relative to the gradle // build script ("build.gradle.kts", in this case). + // Assumes every statement ends with a semicolon. (notably broken for triggers) /** Reads an sql script into the database */ public void migrateScript(String filename) throws IOException, SQLException { try (Stream lines = Files.lines(Paths.get(filename))) { From 1969d2f98f1195ef653eb77ba9de3f94a63e8e65 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 11:52:55 +0200 Subject: [PATCH 03/10] Some more cleaning in tables --- app/Migrations/create-schema.sql | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index 5c6664a..57c565d 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -36,20 +36,22 @@ CREATE TABLE IF NOT EXISTS orders ( ); -------------------------------------------- --- Recipe/Cookie related tables +-- Raw materials, ingredients and recipes -------------------------------------------- -- Notes: the unit type can be defined in terms -- of volume or weight instead. Here we choose -- to use static si-prefixes in relevant tables. --- What types of ingredients do we handle +-- What types of ingredients do we handle. +-- Not currently used, but kept as an example. CREATE TABLE IF NOT EXISTS ingredients ( ingredient_id INTEGER PRIMARY KEY, ingredient_name VARCHAR(50) NOT NULL UNIQUE, preferred_unit VARCHAR(50) NOT NULL CHECK (preferred_unit IN ('g', 'ml')) ); --- What ingredients are in what cookies +-- What ingredients are in what cookies? +-- Glues together the cookies and ingredients, a 'recipe'. CREATE TABLE IF NOT EXISTS recipe_contents ( cookie_id INT NOT NULL, ingredient_id INT NOT NULL, @@ -61,6 +63,7 @@ CREATE TABLE IF NOT EXISTS recipe_contents ( ); -- Describes ingredients and stock. +-- This should reference the ingredients table, but we'll keep it simple for now. CREATE TABLE IF NOT EXISTS raw_materials ( ingredient_id INTEGER PRIMARY KEY, ingredient_name VARCHAR(50) NOT NULL UNIQUE, From b4b12b31a2c90e1ebd5a80a9726b7ed58f8802de Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 12:51:01 +0200 Subject: [PATCH 04/10] New table for deliveries --- app/Migrations/create-schema.sql | 18 ++++++++++++++---- app/src/main/java/krusty/Database.java | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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) { From d0f2bd944d2a6d583faf49c61c97fcf78996a015 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:25:49 +0200 Subject: [PATCH 05/10] Final touches to sql --- app/Migrations/create-schema.sql | 69 +++++++++++++++----------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index 28d1d15..d5561ef 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -9,15 +9,9 @@ DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS cookies; -------------------------------------------- --- Recipe/Cookie related tables +-- Orders, deliveries and customers -------------------------------------------- --- Holds the different types of cookies we can make. -CREATE TABLE IF NOT EXISTS cookies ( - cookie_id INTEGER PRIMARY KEY, - cookie_name VARCHAR(50) NOT NULL UNIQUE -); - -- Our known customers, may need more fields CREATE TABLE IF NOT EXISTS customers ( customer_id INTEGER PRIMARY KEY, @@ -29,41 +23,35 @@ CREATE TABLE IF NOT EXISTS customers ( CREATE TABLE IF NOT EXISTS orders ( order_id INTEGER 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 customers(customer_id), - FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id) + expected_delivery_date DATE NOT NULL, + FOREIGN KEY (customer_id) REFERENCES customers(customer_id) +); + +CREATE TABLE IF NOT EXISTS order_spec ( + nbr_pallets INTEGER NOT NULL, + order_id INTEGER NOT NULL, + cookie_id INTEGER NOT NULL, + FOREIGN KEY (order_id) REFERENCES orders(order_id), + FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id), + PRIMARY KEY (order_id, cookie_id) ); -------------------------------------------- --- Raw materials, ingredients and recipes +-- Cookies, raw_materials and recipes -------------------------------------------- -- Notes: the unit type can be defined in terms -- of volume or weight instead. Here we choose -- to use static si-prefixes in relevant tables. --- What types of ingredients do we handle. --- Not currently used, but kept as an example. -CREATE TABLE IF NOT EXISTS ingredients ( - ingredient_id INTEGER PRIMARY KEY, - ingredient_name VARCHAR(50) NOT NULL UNIQUE, - preferred_unit VARCHAR(50) NOT NULL CHECK (preferred_unit IN ('g', 'ml')) +-- Holds the different types of cookies we can make. +CREATE TABLE IF NOT EXISTS cookies ( + cookie_id INTEGER PRIMARY KEY, + cookie_name VARCHAR(50) NOT NULL UNIQUE ); --- What ingredients are in what cookies? --- Glues together the cookies and ingredients, a 'recipe'. -CREATE TABLE IF NOT EXISTS recipe_contents ( - cookie_id INT NOT NULL, - ingredient_id INT NOT NULL, - quantity INT NOT NULL, - unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml')), - PRIMARY KEY (cookie_id, ingredient_id), - FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id), - FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id) -); - --- Describes ingredients and stock. --- This should reference the ingredients table, but we'll keep it simple for now. +-- What types of raw_materials do we handle. +-- raw_materials quantity tells us amount in stock CREATE TABLE IF NOT EXISTS raw_materials ( ingredient_id INTEGER PRIMARY KEY, ingredient_name VARCHAR(50) NOT NULL UNIQUE, @@ -71,7 +59,19 @@ CREATE TABLE IF NOT EXISTS raw_materials ( unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml')) ); --- When did we get the ingredients? +-- What raw_materials are in what cookies? +-- Glues together the cookies and raw_materials, a 'recipe'. +CREATE TABLE IF NOT EXISTS recipe_contents ( + cookie_id INT NOT NULL, + ingredient_id INT NOT NULL, + quantity INT NOT NULL, + unit VARCHAR(50) NOT NULL CHECK (unit IN ('g', 'ml')), + PRIMARY KEY (cookie_id, ingredient_id), + FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id), + FOREIGN KEY (ingredient_id) REFERENCES raw_materials(ingredient_id) +); + +-- When did we get the raw_materials? CREATE TABLE IF NOT EXISTS raw_materials_deliveries ( delivery_id INTEGER PRIMARY KEY, ingredient_id INT NOT NULL, @@ -90,11 +90,9 @@ CREATE TABLE IF NOT EXISTS raw_materials_deliveries ( CREATE TABLE IF NOT EXISTS pallets ( pallet_id INTEGER PRIMARY KEY, cookie_id INT NOT NULL, - order_id INT, -- This should be not null status VARCHAR(50) NOT NULL CHECK (status IN ('freezer', 'delivered', 'blocked')), - production_date DATE NOT NULL, + production_date DATE NOT NULL DEFAULT NOW, FOREIGN KEY (cookie_id) REFERENCES cookies(cookie_id) - FOREIGN KEY (order_id) REFERENCES orders(order_id) ); -- Connects pallets to orders @@ -116,7 +114,6 @@ CREATE VIEW IF NOT EXISTS pallets_view AS SELECT pallets.pallet_id, cookie_name, - pallets.order_id, status, production_date, delivery_date From 625b5874b15322337a1837eced3f1da93bd4c86c Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:28:08 +0200 Subject: [PATCH 06/10] Zip target --- .gitignore | 1 + makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 151a90e..0dbaa06 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ krusty.sqlite3 *.sqlite3 *.db *.tar.gz +*.zip *.minisig *.jpg *.pdf diff --git a/makefile b/makefile index a6ea063..90fb2e4 100644 --- a/makefile +++ b/makefile @@ -28,6 +28,9 @@ release: scp krusty-imbus_$(GITHASH).tar.gz server:/public/krusty/krusty-imbus_$(GITHASH).tar.gz scp krusty-imbus_$(GITHASH).tar.gz.minisig server:/public/krusty/krusty-imbus_$(GITHASH).tar.gz.minisig +zip: + git archive --format=zip --output=krusty-imbus_$(GITHASH).zip HEAD + # Generate ERD. Requires eralchemy2 (pip install eralchemy2) erd: eralchemy2 -i sqlite:///app/krusty.db -o erd.jpg From de0d667d7962bda71088de07a1793f6b7c6e0ad1 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:29:06 +0200 Subject: [PATCH 07/10] ... --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 90fb2e4..fffb908 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,7 @@ run: clean: ./gradlew clean - rm -f *.tar.gz *.tar.gz.minisig + rm -f *.tar.gz *.tar.gz.minisig *.zip rm -f app/krusty.db test: From 50f86a1682dd42e3579eb546fbcf73933abd30ff Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:30:43 +0200 Subject: [PATCH 08/10] Zip target final --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index fffb908..8d19e50 100644 --- a/makefile +++ b/makefile @@ -29,7 +29,7 @@ release: scp krusty-imbus_$(GITHASH).tar.gz.minisig server:/public/krusty/krusty-imbus_$(GITHASH).tar.gz.minisig zip: - git archive --format=zip --output=krusty-imbus_$(GITHASH).zip HEAD + git archive --format=zip --prefix krusty11/ --output=krusty11-$(GITHASH).zip HEAD # Generate ERD. Requires eralchemy2 (pip install eralchemy2) erd: From eb3b594aaa218e52bd085c53ded5e7dfe77406a5 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:32:20 +0200 Subject: [PATCH 09/10] ERD target proper dependencies in make --- makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 8d19e50..30db587 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,7 @@ run: clean: ./gradlew clean - rm -f *.tar.gz *.tar.gz.minisig *.zip + rm -f *.tar.gz *.tar.gz.minisig *.zip *.jpg rm -f app/krusty.db test: @@ -32,7 +32,7 @@ zip: git archive --format=zip --prefix krusty11/ --output=krusty11-$(GITHASH).zip HEAD # Generate ERD. Requires eralchemy2 (pip install eralchemy2) -erd: +erd: migrate eralchemy2 -i sqlite:///app/krusty.db -o erd.jpg .PHONY: run clean test build dbdump migrate release erd From d69a9dca2d4076493ae972cfa3c5e612ab4e9362 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 13:59:43 +0200 Subject: [PATCH 10/10] Zip target and build instructions --- README.md | 18 ++++++++++++++++++ makefile | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f1ac04..017c7d0 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,26 @@ > Krusty Kookies is a bakery which specializes in cookies, and they need a database to keep track of their production and deliveries. +## Building and testing + +This project uses sqlite3 as a database. Migrations happens automatically on launch. +Migrations drop all tables and recreate them, so all data is lost on restart. +By default jdbc connects sqlite to an in-memory database, so all data is lost on restart anyway. + +```bash +./gradlew build +./gradlew test +``` + +The gradle environment is bumped to a recent version, and it is configured with kotlin and junit5. +The syntax for junit4 was ported to junit5. +**Most** of the pre-configured deps in the handout contained CVEs of varying severity, so they were updated to newer versions. +No tests were changed, some helper classes were implemented. + ## Base tables +**This description is no longer consistent with the current state of the project.** + Unsuprisingly, we will need a cookie table. ```sql diff --git a/makefile b/makefile index 30db587..1459c69 100644 --- a/makefile +++ b/makefile @@ -29,7 +29,8 @@ release: scp krusty-imbus_$(GITHASH).tar.gz.minisig server:/public/krusty/krusty-imbus_$(GITHASH).tar.gz.minisig zip: - git archive --format=zip --prefix krusty11/ --output=krusty11-$(GITHASH).zip HEAD + git archive --format=zip --prefix Rest11/ --output=Rest11.zip HEAD + 7za a -tzip CourseProject11.zip ./app/Migrations/*.sql # Generate ERD. Requires eralchemy2 (pip install eralchemy2) erd: migrate