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),
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
);
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. */
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
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS payment_methods;
DROP TABLE IF EXISTS currencies;
-DROP TABLE IF EXISTS units;
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}")
date,
price,
currency_id,
- unit_id,
discount
)
VALUES (
'${purchase_date}',
${price},
${currency_id},
- ${unit_id},
${discount}
)
RETURNING id
<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>"
$(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'>