summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-10-22 10:54:33 +0200
committeralex <alex@pdp7.net>2023-10-22 10:54:45 +0200
commit1bd6cb89f23ad56dea744f54cf469d2acafa0c24 (patch)
treeeb04218db436ebd1d9067c3b251f5bdf63733e3b /sql
parentc363be1794f8578ff27c6b4f0af943092e4519ed (diff)
Add weight zqxjk schema
Diffstat (limited to 'sql')
-rw-r--r--sql/weight.sql44
1 files changed, 44 insertions, 0 deletions
diff --git a/sql/weight.sql b/sql/weight.sql
new file mode 100644
index 00000000..8881bfd7
--- /dev/null
+++ b/sql/weight.sql
@@ -0,0 +1,44 @@
+create table weight.weight (
+ measured_at timestamp with time zone primary key default now(),
+ value numeric(4,1) not null
+);
+
+create table weight.bp (
+ measured_at timestamp with time zone primary key default now(),
+ systolic numeric(3, 0) not null,
+ diastolic numeric(3, 0) not null
+);
+
+create schema zqxjk;
+
+create view zqxjk.weight as (
+ select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
+ measured_at || ' ' || value as _display,
+ value
+ from weight.weight
+);
+
+create view zqxjk.bp as (
+ select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
+ measured_at || ' ' || systolic || '-' || diastolic as _display,
+ systolic,
+ diastolic
+ from weight.bp
+);
+
+create view zqxjk.admin_weight as (
+ select to_char(measured_at, 'YYYY-MM-DD"T"HH24:MI:SSOF') as _id,
+ measured_at || ' ' || value as _display,
+ measured_at,
+ value
+ from weight.weight
+);
+
+create table zqxjk._tables (
+ name text primary key,
+ default_sort text[]
+);
+
+insert into zqxjk._tables(name, default_sort) values ('weight', '{"_id", "desc"}');
+insert into zqxjk._tables(name, default_sort) values ('admin_weight', '{"_id", "desc"}');
+insert into zqxjk._tables(name, default_sort) values ('bp', '{"_id", "desc"}');