From 678579e933abd0cc662d74d86e76b2f22c249de9 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Fri, 3 Aug 2018 08:26:59 +0200 Subject: [PATCH] Don't use ORDER BY in VIEWS (as this is invalid SQL, why does this even work sometimes in SQLite) (fixes #33) --- migrations/0012.sql | 1 - migrations/0015.sql | 1 - migrations/0032.sql | 20 ++++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 migrations/0032.sql diff --git a/migrations/0012.sql b/migrations/0012.sql index 330da61b..2831e080 100644 --- a/migrations/0012.sql +++ b/migrations/0012.sql @@ -3,4 +3,3 @@ AS SELECT habit_id, MAX(tracked_time) AS last_tracked_time FROM habits_log GROUP BY habit_id -ORDER BY MAX(tracked_time) DESC diff --git a/migrations/0015.sql b/migrations/0015.sql index d6643b11..fc5e9867 100644 --- a/migrations/0015.sql +++ b/migrations/0015.sql @@ -3,4 +3,3 @@ AS SELECT battery_id, MAX(tracked_time) AS last_tracked_time FROM battery_charge_cycles GROUP BY battery_id -ORDER BY MAX(tracked_time) DESC diff --git a/migrations/0032.sql b/migrations/0032.sql new file mode 100644 index 00000000..6cee7070 --- /dev/null +++ b/migrations/0032.sql @@ -0,0 +1,20 @@ +DROP VIEW stock_current; +CREATE VIEW stock_current +AS +SELECT product_id, SUM(amount) AS amount, MIN(best_before_date) AS best_before_date +FROM stock +GROUP BY product_id; + +DROP VIEW habits_current; +CREATE VIEW habits_current +AS +SELECT habit_id, MAX(tracked_time) AS last_tracked_time +FROM habits_log +GROUP BY habit_id; + +DROP VIEW batteries_current; +CREATE VIEW batteries_current +AS +SELECT battery_id, MAX(tracked_time) AS last_tracked_time +FROM battery_charge_cycles +GROUP BY battery_id;