From eaeda911614e50f62cf3ca88611aad05f93cb0c9 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 9 Feb 2024 15:19:48 +0100 Subject: [PATCH 1/5] Added check for extension --- bindings/sirius/src/sirius.rs | 35 +++++++++++++------ .../up.sql | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/bindings/sirius/src/sirius.rs b/bindings/sirius/src/sirius.rs index 8c8314f2..aaff62c6 100644 --- a/bindings/sirius/src/sirius.rs +++ b/bindings/sirius/src/sirius.rs @@ -93,16 +93,15 @@ impl Sirius { })?; // We check that the provided sirius username and password are not empty - // if sirius_username.is_empty() { - // return Err(format!( - // concat!( - // "The sirius username provided in the environment variable SIRIUS_USERNAME is empty. ", - // "We expected there to exist a .env file in the current directory ", - // "with the SIRIUS_USERNAME variable set to the username of the sirius account. ", - // "The variable may also be set in the environment directly, for instance ", - // "in the .bashrc file." - // ))); - // } + if sirius_username.is_empty() { + return Err(format!(concat!( + "The sirius username provided in the environment variable SIRIUS_USERNAME is empty. ", + "We expected there to exist a .env file in the current directory ", + "with the SIRIUS_USERNAME variable set to the username of the sirius account. ", + "The variable may also be set in the environment directly, for instance ", + "in the .bashrc file." + ))); + } if sirius_password.clone().is_empty() { return Err(format!( @@ -155,6 +154,22 @@ impl Sirius { )); } + // We check that the extension of the input file is MGF, in either upper or lower case + let input_file_extension = input_file_path + .extension() + .ok_or_else(|| format!(concat!( + "The input file {:?} does not have an extension. ", + "We expected the input file to have the extension .mgf" + ), input_file_path))?; + + if input_file_extension.to_string_lossy().to_lowercase() != "mgf" { + return Err(format!( + "The input file {:?} does not have the extension .mgf", + input_file_path + )); + } + + // Prepare the command let mut command = Command::new(sirius_path); diff --git a/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql b/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql index dac55ce3..93aeb6bf 100644 --- a/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql +++ b/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql @@ -12,4 +12,4 @@ CREATE TABLE procedure_item_requirements ( updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (procedure_id, item_category_id), FOREIGN KEY (item_category_id, unit_id) REFERENCES item_units(item_id, unit_id) -); \ No newline at end of file +); \ No newline at end of file From e06f94c7b62bbd2751cc40ec5cc243da2623eae2 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 9 Feb 2024 16:18:46 +0100 Subject: [PATCH 2/5] Added more tables for weights and discrete quantities --- .../up.sql | 20 +++++++++++++++++- .../down.sql | 1 + .../up.sql | 18 ++++++++++++++++ .../down.sql | 1 + .../up.sql | 21 +++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql create mode 100644 web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql create mode 100644 web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql create mode 100644 web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql diff --git a/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql b/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql index 8bed5e6d..06923d5b 100644 --- a/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql +++ b/web/backend/migrations/2024-02-06-144906_create_items_table/up.sql @@ -6,4 +6,22 @@ -- items. This table defines the items that are tracked and managed by the system. -- An item can be movable or immovable. -- An example of an Item may be a measurement device, a tube potentially containing a sample, --- or a sample itself. \ No newline at end of file +-- or a sample itself. +CREATE TABLE items ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + description TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by UUID NOT NULL, + updated_by UUID NOT NULL, + project_id UUID NOT NULL, + parent_id UUID, + location_id UUID, + FOREIGN KEY (created_by) REFERENCES users(id), + FOREIGN KEY (updated_by) REFERENCES users(id), + FOREIGN KEY (project_id) REFERENCES projects(id), + FOREIGN KEY (parent_id) REFERENCES items(id), + FOREIGN KEY (item_type_id) REFERENCES item_types(id), + FOREIGN KEY (location_id) REFERENCES locations(id) +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql new file mode 100644 index 00000000..7bac0bef --- /dev/null +++ b/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql @@ -0,0 +1,18 @@ +-- SQL defining the item_weights table. +-- Each item, being a physical object, has a weight. This table defines the weights of items. +-- The weight of an item may change over time, and be measured using different scales and by +-- different people. +CREATE TABLE item_weights ( + id SERIAL PRIMARY KEY, + item_id INTEGER REFERENCES items(id), + weight DECIMAL(10, 2) NOT NULL, + weight_unit_id INTEGER REFERENCES weight_units(id), + sensor_id INTEGER REFERENCES items(id), + measured_at TIMESTAMPTZ NOT NULL DEFAULT now(), + measured_by INTEGER REFERENCES users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by INTEGER NOT NULL REFERENCES users(id), + updated_by INTEGER NOT NULL REFERENCES users(id), + FOREIGN KEY (item_id, weight_unit_id) REFERENCES items(item_id, weight_unit_id), +); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql new file mode 100644 index 00000000..946d8ce9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql @@ -0,0 +1,21 @@ +-- SQL defining the item_quantities table. +-- Some items may be counted discretely, as opposed to a weight in grams. +-- This table defines the discrete quantities of items that we have in stock. +-- The quantity of an item may change over time, so multiple quantity entries +-- may be inserted for the same item. +-- While these quantities are discrete, in order to facilitate the semantics of +-- the system, we will still allow for the user to specify the counter unit for +-- the item. For example, a counter unit may be a box, a tube, or a vial. +CREATE TABLE item_quantities ( + id SERIAL PRIMARY KEY, + item_id INTEGER REFERENCES items(id), + quantity INTEGER NOT NULL, + unit_id INTEGER REFERENCES weight_units(id), + measured_at TIMESTAMPTZ NOT NULL DEFAULT now(), + measured_by INTEGER REFERENCES users(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + created_by INTEGER NOT NULL REFERENCES users(id), + updated_by INTEGER NOT NULL REFERENCES users(id), + FOREIGN KEY (item_id, unit_id) REFERENCES item_units(item_id, unit_id), +); \ No newline at end of file From 58edf55b3303466a84499ffd25c7fce62a72a177 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 9 Feb 2024 16:41:08 +0100 Subject: [PATCH 3/5] Generalized tables --- .../down.sql | 0 .../up.sql | 8 ++++---- .../down.sql | 0 .../up.sql | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename web/backend/migrations/{2024-02-09-143242_create_item_weights_table => 2024-02-09-143242_create_item_real_quantities_table}/down.sql (100%) rename web/backend/migrations/{2024-02-09-143242_create_item_weights_table => 2024-02-09-143242_create_item_real_quantities_table}/up.sql (76%) rename web/backend/migrations/{2024-02-09-144314_create_item_quantities_table => 2024-02-09-144314_create_item_discrete_quantities_table}/down.sql (100%) rename web/backend/migrations/{2024-02-09-144314_create_item_quantities_table => 2024-02-09-144314_create_item_discrete_quantities_table}/up.sql (96%) diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql b/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/down.sql similarity index 100% rename from web/backend/migrations/2024-02-09-143242_create_item_weights_table/down.sql rename to web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/down.sql diff --git a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql b/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql similarity index 76% rename from web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql rename to web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql index 7bac0bef..d759f5fe 100644 --- a/web/backend/migrations/2024-02-09-143242_create_item_weights_table/up.sql +++ b/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql @@ -1,12 +1,12 @@ --- SQL defining the item_weights table. +-- SQL defining the item_real_quantities table. -- Each item, being a physical object, has a weight. This table defines the weights of items. -- The weight of an item may change over time, and be measured using different scales and by -- different people. -CREATE TABLE item_weights ( +CREATE TABLE item_real_quantities ( id SERIAL PRIMARY KEY, item_id INTEGER REFERENCES items(id), weight DECIMAL(10, 2) NOT NULL, - weight_unit_id INTEGER REFERENCES weight_units(id), + unit_id INTEGER REFERENCES units(id), sensor_id INTEGER REFERENCES items(id), measured_at TIMESTAMPTZ NOT NULL DEFAULT now(), measured_by INTEGER REFERENCES users(id), @@ -14,5 +14,5 @@ CREATE TABLE item_weights ( updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), created_by INTEGER NOT NULL REFERENCES users(id), updated_by INTEGER NOT NULL REFERENCES users(id), - FOREIGN KEY (item_id, weight_unit_id) REFERENCES items(item_id, weight_unit_id), + FOREIGN KEY (item_id, unit_id) REFERENCES items(item_id, unit_id), ); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql b/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/down.sql similarity index 100% rename from web/backend/migrations/2024-02-09-144314_create_item_quantities_table/down.sql rename to web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/down.sql diff --git a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql b/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql similarity index 96% rename from web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql rename to web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql index 946d8ce9..73ec4944 100644 --- a/web/backend/migrations/2024-02-09-144314_create_item_quantities_table/up.sql +++ b/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql @@ -6,7 +6,7 @@ -- While these quantities are discrete, in order to facilitate the semantics of -- the system, we will still allow for the user to specify the counter unit for -- the item. For example, a counter unit may be a box, a tube, or a vial. -CREATE TABLE item_quantities ( +CREATE TABLE item_discrete_quantities ( id SERIAL PRIMARY KEY, item_id INTEGER REFERENCES items(id), quantity INTEGER NOT NULL, From e733769e5dc31263094c8a37b5f4339b8c3d8870 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 9 Feb 2024 17:02:59 +0100 Subject: [PATCH 4/5] Added table marker for discrete units --- .../down.sql | 0 .../up.sql | 0 .../2024-02-09-155933_create_discrete_units_table/down.sql | 1 + .../2024-02-09-155933_create_discrete_units_table/up.sql | 7 +++++++ 4 files changed, 8 insertions(+) rename web/backend/migrations/{2024-02-09-102550_create_procedure_item_requirements_table => 2024-02-09-102550_create_procedure_item_discrete_requirements_table}/down.sql (100%) rename web/backend/migrations/{2024-02-09-102550_create_procedure_item_requirements_table => 2024-02-09-102550_create_procedure_item_discrete_requirements_table}/up.sql (100%) create mode 100644 web/backend/migrations/2024-02-09-155933_create_discrete_units_table/down.sql create mode 100644 web/backend/migrations/2024-02-09-155933_create_discrete_units_table/up.sql diff --git a/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/down.sql b/web/backend/migrations/2024-02-09-102550_create_procedure_item_discrete_requirements_table/down.sql similarity index 100% rename from web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/down.sql rename to web/backend/migrations/2024-02-09-102550_create_procedure_item_discrete_requirements_table/down.sql diff --git a/web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql b/web/backend/migrations/2024-02-09-102550_create_procedure_item_discrete_requirements_table/up.sql similarity index 100% rename from web/backend/migrations/2024-02-09-102550_create_procedure_item_requirements_table/up.sql rename to web/backend/migrations/2024-02-09-102550_create_procedure_item_discrete_requirements_table/up.sql diff --git a/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/down.sql b/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/up.sql b/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/up.sql new file mode 100644 index 00000000..8e8ef004 --- /dev/null +++ b/web/backend/migrations/2024-02-09-155933_create_discrete_units_table/up.sql @@ -0,0 +1,7 @@ +-- SQL describing the discrete_units table. +-- The discrete_units table is used as the finite set of units that can be used to measure +-- the discrete quantities of items. For example, a box, a tube, or a vial. +CREATE TABLE discrete_units ( + id INTEGER PRIMARY KEY, + FOREIGN KEY (id) REFERENCES units(id) +); \ No newline at end of file From 7839d8e7761e035157755e13a139fb7444b2061c Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 9 Feb 2024 17:04:59 +0100 Subject: [PATCH 5/5] Added table marker for real units --- .../up.sql | 1 + .../up.sql | 1 + .../2024-02-09-160358_create_real_units_table/down.sql | 1 + .../2024-02-09-160358_create_real_units_table/up.sql | 7 +++++++ 4 files changed, 10 insertions(+) create mode 100644 web/backend/migrations/2024-02-09-160358_create_real_units_table/down.sql create mode 100644 web/backend/migrations/2024-02-09-160358_create_real_units_table/up.sql diff --git a/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql b/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql index d759f5fe..2003cf7d 100644 --- a/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql +++ b/web/backend/migrations/2024-02-09-143242_create_item_real_quantities_table/up.sql @@ -15,4 +15,5 @@ CREATE TABLE item_real_quantities ( created_by INTEGER NOT NULL REFERENCES users(id), updated_by INTEGER NOT NULL REFERENCES users(id), FOREIGN KEY (item_id, unit_id) REFERENCES items(item_id, unit_id), + FOREIGN KEY (unit_id) REFERENCES real_units(id) ); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql b/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql index 73ec4944..afa2572d 100644 --- a/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql +++ b/web/backend/migrations/2024-02-09-144314_create_item_discrete_quantities_table/up.sql @@ -18,4 +18,5 @@ CREATE TABLE item_discrete_quantities ( created_by INTEGER NOT NULL REFERENCES users(id), updated_by INTEGER NOT NULL REFERENCES users(id), FOREIGN KEY (item_id, unit_id) REFERENCES item_units(item_id, unit_id), + FOREIGN KEY (unit_id) REFERENCES discrete_units(id) ); \ No newline at end of file diff --git a/web/backend/migrations/2024-02-09-160358_create_real_units_table/down.sql b/web/backend/migrations/2024-02-09-160358_create_real_units_table/down.sql new file mode 100644 index 00000000..d9a93fe9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-160358_create_real_units_table/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` diff --git a/web/backend/migrations/2024-02-09-160358_create_real_units_table/up.sql b/web/backend/migrations/2024-02-09-160358_create_real_units_table/up.sql new file mode 100644 index 00000000..94a058a9 --- /dev/null +++ b/web/backend/migrations/2024-02-09-160358_create_real_units_table/up.sql @@ -0,0 +1,7 @@ +-- SQL describing the real_units table. +-- The real_units table is used as the finite set of units that can be used to measure +-- the real quantities of items. For example, a box, a tube, or a vial. +CREATE TABLE real_units ( + id INTEGER PRIMARY KEY, + FOREIGN KEY (id) REFERENCES units(id) +); \ No newline at end of file