tidy stuff
authorgamesguru <mathmuncher11@gmail.com>
Fri, 25 Sep 2020 15:05:45 +0000 (11:05 -0400)
committergamesguru <mathmuncher11@gmail.com>
Sat, 26 Sep 2020 11:36:54 +0000 (07:36 -0400)
sql/data/bf_eqs.csv [new file with mode: 0644]
sql/data/biometrics.csv
sql/data/bmr_eqs.csv [new file with mode: 0644]
sql/data/users.csv [new file with mode: 0644]
sql/import.sql
sql/tables.sql
sql/upgrade_scripts/2.sql [new file with mode: 0644]

diff --git a/sql/data/bf_eqs.csv b/sql/data/bf_eqs.csv
new file mode 100644 (file)
index 0000000..69afd99
--- /dev/null
@@ -0,0 +1,4 @@
+id,bf_eq
+1,NAVY
+2,3SITE
+3,7SITE
index 643c26a82012b1bec56a2b10470dd70269e6785b..bea9ae1bba271e8957aa6adadb0eec842a000371 100644 (file)
@@ -1,21 +1,30 @@
-id,user_id,name,units,created
-1,,Weight,"kg,lbs",1580336088
-2,,Height,"cm,in",1580336088
-3,,Pulse,bpm,1580336088
-4,,Systolic Blood Pressure,mmHg,1580336088
-5,,Diastolic Blood Pressure,mmHg,1580336088
-6,,Blood Glucose,"mmol/L,mg/dL",1580336088
-7,,Body Temperature,"C,F",1580336088
-8,,Body Fat,%,1580336088
-9,,Waist Size,"cm,in",1580336088
-10,,Total Cholesterol,"mmol/L,mg/dL",1580336088
-11,,LDL Cholesterol,"mmol/L,mg/dL",1580336088
-12,,HDL Cholesterol,"mmol/L,mg/dL",1580336088
-13,,Triglycerides,"mmol/L,mg/dL",1580336088
-14,,Ketones (Blood),"mmol/L,mg/dL",1580336088
-15,,Ketones (Urine),"mmol/L,mg/dL",1580336088
-16,,Ketones (Breath),"mmol/L,mg/dL,ppm",1580336088
-17,,Sleep,"min,hr",1580336088
-18,,25-Hydroxy Vitamin D,"ng/mL,nmol/L",1580336088
-19,,Ferritin,"ng/mL,pmol/L",1580336088
-20,,Pulsewave Velocity,PWV,1580336088
+id,tag,name,unit,created
+1,ht,Height,cm,1580336088
+2,wt,Weight,kg,1580336088
+3,wrist,Wrist,cm,1580336088
+4,ankle,Ankle,cm,1580336088
+5,chest,Chest,cm,1580336088
+6,arm,Upper Arm,cm,1580336088
+7,thigh,Thigh,cm,1580336088
+8,calf,Calf,cm,1580336088
+9,shoulders,Shoulders,cm,1580336088
+10,waist,Waist,cm,1580336088
+11,hips,Hips,cm,1580336088
+12,neck,Neck,cm,1580336088
+13,forearm,Forearm,cm,1580336088
+14,pectoral,Pectoral,mm,1580336088
+15,abdominal,Abdominal,mm,1580336088
+16,quadricep,Quadricep,mm,1580336088
+17,midaxillary,Midaxillary,mm,1580336088
+18,subscapular,Subscapular,mm,1580336088
+19,tricep,Tricep,mm,1580336088
+20,suprailiac,Suprailiac,mm,1580336088
+21,custom_bf,Body Fat,,1580336088
+22,pulse,Pulse,bpm,1580336088
+23,systolic,Systolic Blood Pressure,mmHg,1580336088
+24,diastolic,Diastolic Blood Pressure,mmHg,1580336088
+25,glucose,Blood Glucose,mg/dL,1580336088
+26,cholest_tot,Total Cholesterol,mg/dL,1580336088
+27,cholest_ldl,LDL Cholesterol,mg/dL,1580336088
+28,cholest_hdl,HDL Cholesterol,mg/dL,1580336088
+29,triglycerides,Triglycerides,mg/dL,1580336088
diff --git a/sql/data/bmr_eqs.csv b/sql/data/bmr_eqs.csv
new file mode 100644 (file)
index 0000000..fed6d75
--- /dev/null
@@ -0,0 +1,5 @@
+id,bmr_eq
+1,HARRIS_BENEDICT
+2,KATCH_MACARDLE
+3,MIFFLIN_ST_JEOR
+4,CUNNINGHAM
diff --git a/sql/data/users.csv b/sql/data/users.csv
new file mode 100644 (file)
index 0000000..7fe04d8
--- /dev/null
@@ -0,0 +1,4 @@
+id,name,eula,email,gender,dob,act_lvl,goal_wt,goal_bf,bmr_id,bf_id,created
+1,Shane,1,nutratracker@gmail.com,MALE,1993-01-01,2,78,0.12,1,1,1601067725
+2,Mark,1,kinomark6@gmail.com,MALE,1957-01-01,2,72,0.14,1,1,1601068574
+3,Rocky,1,,DOG,2007-08-01,2,7.3,,1,1,1601068718
index 1c5e385232899fe2438e967718f18f221b2ea34f..5f402c981316c268f63834de25b30a7fd744daab 100644 (file)
 
 .mode csv
 
-PRAGMA foreign_keys = 0;
+.import '| tail -n +2 ./data/bmr_eqs.csv' bmr_eqs
+.import '| tail -n +2 ./data/bf_eqs.csv' bf_eqs
+
 .import '| tail -n +2 ./data/biometrics.csv' biometrics
-PRAGMA foreign_keys = 1;
+.import '| tail -n +2 ./data/users.csv' users
 
 .header on
 .mode column
index bf19f3db2192da550000810ed25b60de540e6fd7..24095bef43b36c70323734788e6c91fece89fac8 100644 (file)
 
 PRAGMA foreign_keys = 1;
 
-CREATE TABLE table_versions (
-  tablename text PRIMARY KEY,
-  version int NOT NULL
+CREATE TABLE test (
+  id blob text UNIQUE
 );
 
-INSERT INTO table_versions
-  VALUES ('table_versions', 1);
+CREATE TABLE version( id integer PRIMARY KEY AUTOINCREMENT, version text NOT NULL, created date NOT NULL, notes text
+);
+
+INSERT INTO version(version, created, notes)
+  VALUES ('0.0.0', '2020-09-22', 'initial release');
 
 --
 ---------------------------------
 -- Goals, equations, & statics
 ---------------------------------
 
-INSERT INTO table_versions
-  VALUES ('goals', 1), ('bmr_eqs', 1), ('bf_eqs', 1), ('lbm_eqs', 1);
-
-CREATE TABLE goals (
-  id integer PRIMARY KEY AUTOINCREMENT,
-  goal_desc text
-);
-
 CREATE TABLE bmr_eqs (
   id integer PRIMARY KEY AUTOINCREMENT,
   bmr_eq text
@@ -44,89 +38,29 @@ CREATE TABLE bmr_eqs (
 
 CREATE TABLE bf_eqs (
   id integer PRIMARY KEY AUTOINCREMENT,
-  bf_eq text DEFAULT 'NAVY' -- ['NAVY', '3SITE', '7SITE']
-);
-
-CREATE TABLE lbm_eqs (
-  id integer PRIMARY KEY AUTOINCREMENT,
-  lbm_eq text
+  bf_eq text DEFAULT 'NAVY'
 );
 
-INSERT INTO goals (goal_desc)
-  VALUES ('LOSE'), ('GAIN'), ('MAINTAIN'), ('TRANSFORM');
-
-INSERT INTO bmr_eqs (bmr_eq)
-  VALUES ('HARRIS_BENEDICT'), ('KATCH_MACARDLE'), ('MIFFLIN_ST_JEOR'), ('CUNNINGHAM');
-
-INSERT INTO bf_eqs (bf_eq)
-  VALUES ('NAVY'), ('3SITE'), ('7SITE');
-
-INSERT INTO lbm_eqs (lbm_eq)
-  VALUES ('MARTIN_BERKHAN'), ('ERIC_HELMS'), ('CASEY_BUTT');
-
 --
 --------------------------------
--- Users and biometrics
+-- Users table
 --------------------------------
 
-INSERT INTO table_versions
-  VALUES ('users', 1), ('measurements', 1);
-
 CREATE TABLE users (
   id integer PRIMARY KEY AUTOINCREMENT,
-  name text NOT NULL,
+  name text NOT NULL UNIQUE,
   eula int DEFAULT 0,
-  email text,
+  email text UNIQUE,
   gender text,
   dob date,
   act_lvl int DEFAULT 2, -- [1, 2, 3, 4, 5]
-  goal_id int DEFAULT 3,
   goal_wt real,
   goal_bf real,
   bmr_id int DEFAULT 1,
   bf_id int DEFAULT 1,
-  lbm_id int DEFAULT 1,
   created int DEFAULT (strftime ('%s', 'now')),
-  UNIQUE (name),
-  UNIQUE (email),
-  FOREIGN KEY (goal_id) REFERENCES goals (id) ON UPDATE CASCADE,
   FOREIGN KEY (bmr_id) REFERENCES bmr_eqs (id) ON UPDATE CASCADE,
-  FOREIGN KEY (bf_id) REFERENCES bf_eqs (id) ON UPDATE CASCADE,
-  FOREIGN KEY (lbm_id) REFERENCES lbm_eqs (id) ON UPDATE CASCADE
-);
-
-CREATE TABLE measurements (
-  id integer PRIMARY KEY AUTOINCREMENT,
-  user_id int NOT NULL,
-  -- Mass (kg)
-  weight real,
-  -- Kinostatics (cm)
-  height int,
-  wrist real,
-  ankle real,
-  -- Tape Measurements (cm)
-  chest real,
-  arm real,
-  thigh real,
-  calf real,
-  shoulders real,
-  waist real,
-  hips real,
-  neck real,
-  forearm real,
-  -- Skin Manifolds (mm)
-  pectoral int,
-  abdominal int,
-  quadricep int,
-  midaxillary int,
-  subscapular int,
-  tricep int,
-  suprailiac int,
-  -- Times
-  date date DEFAULT CURRENT_DATE,
-  created int DEFAULT (strftime ('%s', 'now')),
-  updated int,
-  FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
+  FOREIGN KEY (bf_id) REFERENCES bf_eqs (id) ON UPDATE CASCADE
 );
 
 --
@@ -134,25 +68,21 @@ CREATE TABLE measurements (
 -- Biometrics
 --------------------------------
 
-INSERT INTO table_versions
-  VALUES ('biometrics', 1), ('biometric_log', 1);
-
 CREATE TABLE biometrics (
   id integer PRIMARY KEY AUTOINCREMENT,
-  user_id int,
-  name text NOT NULL,
-  units text NOT NULL,
-  created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
+  tag text NOT NULL UNIQUE,
+  name text NOT NULL UNIQUE,
+  unit text,
+  created int DEFAULT (strftime ('%s', 'now'))
 );
 
 CREATE TABLE biometric_log (
   id integer PRIMARY KEY AUTOINCREMENT,
   user_id int NOT NULL,
+  date date DEFAULT CURRENT_DATE,
   biometric_id int NOT NULL,
   value real NOT NULL,
-  created int DEFAULT (strftime ('%s', 'now')),
-  updated int,
+  UNIQUE (user_id, date, biometric_id),
   FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE,
   FOREIGN KEY (biometric_id) REFERENCES biometrics (id) ON UPDATE CASCADE
 );
@@ -162,27 +92,11 @@ CREATE TABLE biometric_log (
 -- Recipes
 --------------------------------
 
-INSERT INTO table_versions
-  VALUES ('recipes', 1), ('recipe_dat', 1), ('recipe_serv', 1);
-
 CREATE TABLE recipes (
   id integer PRIMARY KEY AUTOINCREMENT,
   name text NOT NULL,
-  user_id int NOT NULL,
   shared int DEFAULT 1,
-  created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
-);
-
-CREATE TABLE recipe_dat (
-  id integer PRIMARY KEY AUTOINCREMENT,
-  recipe_id int NOT NULL,
-  -- TODO: enforce FK constraint across two DBs?
-  food_id int NOT NULL,
-  msre_id int NOT NULL,
-  amount real NOT NULL,
-  created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
+  created int DEFAULT (strftime ('%s', 'now'))
 );
 
 CREATE TABLE recipe_serv (
@@ -190,31 +104,63 @@ CREATE TABLE recipe_serv (
   recipe_id int NOT NULL,
   msre_desc text NOT NULL,
   grams real NOT NULL,
-  created int DEFAULT (strftime ('%s', 'now')),
   FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
 );
 
+CREATE TABLE recipe_dat (
+  recipe_id int NOT NULL,
+  -- TODO: enforce FK constraint across two DBs?
+  food_id int NOT NULL,
+  msre_id int NOT NULL,
+  amount real NOT NULL,
+  UNIQUE (recipe_id, food_id),
+  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE,
+  FOREIGN KEY (msre_id) REFERENCES recipe_serv (id) ON UPDATE CASCADE
+);
+
 --
 --------------------------------
 -- Food logs
 --------------------------------
 
-INSERT INTO table_versions
-  VALUES ('food_log', 1);
+CREATE TABLE meal_names (
+  id integer PRIMARY KEY AUTOINCREMENT,
+  name text NOT NULL
+);
+
+INSERT INTO meal_names (name)
+  VALUES ('BREAKFAST'), ('LUNCH'), ('DINNER'), ('SNACK');
 
 CREATE TABLE food_log (
   id integer PRIMARY KEY AUTOINCREMENT,
   user_id int,
   date date DEFAULT CURRENT_DATE,
-  meal_name text,
+  meal_id int,
   amount real NOT NULL,
   recipe_id int,
+  rec_msre_id int,
   -- TODO: enforce FK constraint across two DBs?
-  msre_id int,
   food_id int,
-  created int DEFAULT (strftime ('%s', 'now')),
-  updated int,
+  food_msre_id int,
+  UNIQUE (user_id, date, meal_id, recipe_id),
+  UNIQUE (user_id, date, meal_id, food_id),
   FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE,
-  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
+  FOREIGN KEY (meal_id) REFERENCES meal_names (id) ON UPDATE CASCADE,
+  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE,
+  FOREIGN KEY (rec_msre_id) REFERENCES recipe_serv (id) ON UPDATE CASCADE
+);
+
+--
+--------------------------------
+-- Custom RDAs
+--------------------------------
+
+CREATE TABLE rda (
+  id integer PRIMARY KEY,
+  user_id integer NOT NULL,
+  -- TODO: enforce FK constraint across two DBs?
+  nutr_id integer NOT NULL,
+  rda real NOT NULL,
+  FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
 );
 
diff --git a/sql/upgrade_scripts/2.sql b/sql/upgrade_scripts/2.sql
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+