]> git.ekhem.eu.org Git - payments.git/commitdiff
Stop tracking units for purchases.
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 13 Jan 2024 23:16:53 +0000 (00:16 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Sat, 13 Jan 2024 23:36:22 +0000 (00:36 +0100)
create.sql
drop.sql
payment.sh
payments.sh

index f677b48864166d35cb0f106510b49230f46ffe72..9e1a4628ade7c2111402ab246f00554d3f8555bf 100644 (file)
@@ -21,11 +21,6 @@ CREATE TABLE IF NOT EXISTS currencies (
     name VARCHAR(128) NOT NULL UNIQUE
 );
 
-CREATE TABLE IF NOT EXISTS units (
-    id SERIAL PRIMARY KEY,
-    name VARCHAR(128) NOT NULL UNIQUE
-);
-
 CREATE TABLE IF NOT EXISTS purchases (
     id SERIAL PRIMARY KEY,
     shop_id INTEGER REFERENCES shops (id),
@@ -34,7 +29,6 @@ CREATE TABLE IF NOT EXISTS purchases (
     date DATE DEFAULT CURRENT_DATE,
     price DECIMAL(12,2) NOT NULL,
     currency_id INTEGER REFERENCES currencies (id),
-    unit_id INTEGER REFERENCES units (id),
     discount BOOLEAN DEFAULT FALSE
 );
 
@@ -45,19 +39,19 @@ BEGIN
         CREATE ROLE payments_tracker LOGIN;
 
         GRANT SELECT
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         TO payments_tracker;
 
         GRANT INSERT
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         TO payments_tracker;
 
         GRANT UPDATE
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         TO payments_tracker;
 
         GRANT USAGE, SELECT
-        ON SEQUENCE shops_id_seq, products_id_seq, payment_methods_id_seq, currencies_id_seq , units_id_seq, purchases_id_seq
+        ON SEQUENCE shops_id_seq, products_id_seq, payment_methods_id_seq, currencies_id_seq , purchases_id_seq
         TO payments_tracker;
 
         /* Execute for the current database. */
index f8bb488f8558cf9969ccda49516c906308a2ceb3..339bbfecdf7f029728bef0a6c6d2866a3b5014da 100644 (file)
--- a/drop.sql
+++ b/drop.sql
@@ -6,19 +6,19 @@ BEGIN
     IF EXISTS (SELECT * FROM pg_user WHERE usename = 'payments_tracker')
     THEN
         REVOKE SELECT
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         FROM payments_tracker;
 
         REVOKE INSERT
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         FROM payments_tracker;
 
         REVOKE UPDATE
-        ON TABLE shops, products, payment_methods, currencies, units, purchases
+        ON TABLE shops, products, payment_methods, currencies, purchases
         FROM payments_tracker;
 
         REVOKE USAGE, SELECT
-        ON SEQUENCE shops_id_seq, products_id_seq, payment_methods_id_seq, currencies_id_seq, units_id_seq, purchases_id_seq
+        ON SEQUENCE shops_id_seq, products_id_seq, payment_methods_id_seq, currencies_id_seq, purchases_id_seq
         FROM payments_tracker;
 
         EXECUTE
@@ -35,4 +35,3 @@ DROP TABLE IF EXISTS shops;
 DROP TABLE IF EXISTS products;
 DROP TABLE IF EXISTS payment_methods;
 DROP TABLE IF EXISTS currencies;
-DROP TABLE IF EXISTS units;
index 5804a729a02df514423f8849dd736296ee544c30..0e5c2d1f6293863d37496831dc9c2be955e8c274 100644 (file)
@@ -47,9 +47,6 @@ price=$(get_query_param "price")
 currency=$(get_query_param "currency")
 currency_id=$(insert_into "currencies" "${currency}")
 
-unit=$(get_query_param "unit")
-unit_id=$(insert_into "units" "${unit}")
-
 payment_method=$(get_query_param "payment_method")
 payment_method_id=$(insert_into "payment_methods" "${payment_method}")
 
@@ -69,7 +66,6 @@ WITH new_purchase_id AS (
     date,
     price,
     currency_id,
-    unit_id,
     discount
   )
   VALUES (
@@ -79,7 +75,6 @@ WITH new_purchase_id AS (
     '${purchase_date}',
     ${price},
     ${currency_id},
-    ${unit_id},
     ${discount}
   )
   RETURNING id
@@ -103,8 +98,8 @@ PAGE="
 <body>
 Recorded new purchase (id=${purchase_id}) of ${product} \
 (id=${product_id}) on ${purchase_date} in ${shop} (id=${shop_id}). Payed \
-${price} ${currency} (id=${currency_id}) for ${unit} (id=${unit_id}) with \
-${payment_method} (id=${payment_method_id}) (discount=${discount}).
+${price} ${currency} (id=${currency_id}) with ${payment_method} \
+(id=${payment_method_id}) (discount=${discount}).
 </body>
 </html>"
 
index c1034f4b61d3e20692f5184cc3d4ca66566719b7..0a31e5c49a3315f038ce127da77a5a01ad7ea80d 100644 (file)
@@ -70,11 +70,6 @@ PAGE="
         $(query_db "SELECT name FROM currencies" | as_options)
       </datalist>
 
-      <input list='units' id='unit' name='unit' placeholder='Unit' required />
-      <datalist id='units'>
-        $(query_db "SELECT name FROM units" | as_options)
-      </datalist>
-
       <input list='payment_methods' id='payment_method' name='payment_method'
         placeholder='Payment method' />
       <datalist id='payment_methods'>