Update ddl

This commit is contained in:
2024-08-09 16:24:42 +02:00
parent a23ada9bb0
commit a29213f35f

View File

@@ -5,17 +5,6 @@ create table weight (
weight real not null weight real not null
); );
-- begin TRANSACTION;
-- drop table if exists weight2;
-- create table weight2 (
-- date datetime default (datetime('now', '+2 hours')),
-- weight real not null
-- );
-- insert into weight2(date, weight)
-- select date, weight from weight;
-- drop table weight;
-- alter table weight2 rename to weight;
-- commit;
create index weightDateIdx on weight(date); create index weightDateIdx on weight(date);
create index weightDailyIdx on weight(strftime('%Y-%m-%d', date)); create index weightDailyIdx on weight(strftime('%Y-%m-%d', date));
@@ -36,7 +25,6 @@ select rowid,
from weight from weight
order by date desc; order by date desc;
-- Daily Summary View
create view weightDaily as create view weightDaily as
select strftime('%Y-%m-%d', date) as period, select strftime('%Y-%m-%d', date) as period,
round(avg(weight), 2) as amount round(avg(weight), 2) as amount
@@ -44,7 +32,6 @@ select strftime('%Y-%m-%d', date) as period,
group by strftime('%Y-%m-%d', date) group by strftime('%Y-%m-%d', date)
order by date desc; order by date desc;
-- Weekly Summary View
create view weightWeekly as create view weightWeekly as
select strftime('%Y-%W', date) as period, select strftime('%Y-%W', date) as period,
round(avg(weight), 2) as amount round(avg(weight), 2) as amount
@@ -52,7 +39,6 @@ select strftime('%Y-%W', date) as period,
group by strftime('%Y-%W', date) group by strftime('%Y-%W', date)
order by date desc; order by date desc;
-- Monthly Summary View
create view weightMonthly as create view weightMonthly as
select strftime('%Y-%m', date) as period, select strftime('%Y-%m', date) as period,
round(avg(weight), 2) as amount round(avg(weight), 2) as amount
@@ -60,7 +46,6 @@ select strftime('%Y-%m', date) as period,
group by strftime('%Y-%m', date) group by strftime('%Y-%m', date)
order by date desc; order by date desc;
-- Yearly Summary View
create view weightYearly as create view weightYearly as
select strftime('%Y', date) as period, select strftime('%Y', date) as period,
round(avg(weight), 2) as amount round(avg(weight), 2) as amount
@@ -77,21 +62,6 @@ create table food(
energy generated always as (coalesce(amount, 0) * coalesce(per100, 0) / 100) stored energy generated always as (coalesce(amount, 0) * coalesce(per100, 0) / 100) stored
); );
-- begin transaction;
-- drop table if exists food2;
-- create table food2(
-- date datetime default (datetime('now', '+2 hours')),
-- food varchar not null,
-- description varchar,
-- amount real not null,
-- per100 real default 0,
-- energy generated always as (coalesce(amount, 0) * coalesce(per100, 0) / 100) stored
-- );
-- insert into food2(date, food, description, amount, per100)
-- select date, food, description, amount, per100 from food;
-- drop table food;
-- alter table food2 rename to food;
-- commit;
create index dailyIdx on food(strftime('%Y-%m-%d', date)); create index dailyIdx on food(strftime('%Y-%m-%d', date));
create index weeklyIdx on food(strftime('%Y-%W', date)); create index weeklyIdx on food(strftime('%Y-%W', date));
create index monthlyIdx on food(strftime('%Y-%m', date)); create index monthlyIdx on food(strftime('%Y-%m', date));
@@ -100,11 +70,11 @@ create index dateIdx on food(date);
create index foodIdx on food(food); create index foodIdx on food(food);
drop view if exists foodView; drop view if exists foodView;
drop view if exists daily; drop view if exists foodDaily;
drop view if exists weekly; drop view if exists foodWeekly;
drop view if exists monthly; drop view if exists foodMonthly;
drop view if exists yearly; drop view if exists foodYearly;
drop view if exists recent; drop view if exists foodRecent;
create view foodView as create view foodView as
select rowid, select rowid,
@@ -116,8 +86,7 @@ select rowid,
round(energy, 2) as energy round(energy, 2) as energy
from food; from food;
-- Daily Summary View create view foodDaily as
create view daily as
select strftime('%Y-%m-%d', date) as period, select strftime('%Y-%m-%d', date) as period,
round(sum(amount), 2) as amount, round(sum(amount), 2) as amount,
round(avg(per100), 2) as avgPer100, round(avg(per100), 2) as avgPer100,
@@ -126,8 +95,7 @@ from food
group by strftime('%Y-%m-%d', date) group by strftime('%Y-%m-%d', date)
order by date desc; order by date desc;
-- Weekly Summary View create view foodWeekly as
create view weekly as
select strftime('%Y-%W', date) as period, select strftime('%Y-%W', date) as period,
round(sum(amount), 2) as amount, round(sum(amount), 2) as amount,
round(avg(per100), 2) as avgPer100, round(avg(per100), 2) as avgPer100,
@@ -136,8 +104,7 @@ from food
group by strftime('%Y-%W', date) group by strftime('%Y-%W', date)
order by date desc; order by date desc;
-- Monthly Summary View create view foodMonthly as
create view monthly as
select strftime('%Y-%m', date) as period, select strftime('%Y-%m', date) as period,
round(sum(amount), 2) as amount, round(sum(amount), 2) as amount,
round(avg(per100), 2) as avgPer100, round(avg(per100), 2) as avgPer100,
@@ -146,8 +113,7 @@ from food
group by strftime('%Y-%m', date) group by strftime('%Y-%m', date)
order by date desc; order by date desc;
-- Yearly Summary View create view foodYearly as
create view yearly as
select strftime('%Y', date) as period, select strftime('%Y', date) as period,
round(sum(amount), 2) as amount, round(sum(amount), 2) as amount,
round(avg(per100), 2) as avgPer100, round(avg(per100), 2) as avgPer100,
@@ -156,8 +122,7 @@ from food
group by strftime('%Y', date) group by strftime('%Y', date)
order by date desc; order by date desc;
-- Recent create view foodRecent as
create view recent as
select rowid, select rowid,
* *
from food from food
@@ -183,5 +148,4 @@ set per100 = coalesce(
where rowid = new .rowid; where rowid = new .rowid;
end; end;
create table settings (key text, value text) --rollback;
commit; commit;