--------------------------------
SELECT
- users.name,
+ profiles.name,
date,
- ROUND(bio_log_entry.value * 2.204, 1) AS weight,
- tags,
- notes
+ ROUND(bio_log_entry.value * 2.204, 1) AS weight
FROM
biometric_log
- INNER JOIN users ON user_id = users.id
+ INNER JOIN profiles ON profile_id = profiles.id
INNER JOIN bio_log_entry ON biometric_id = 2
AND log_id = biometric_log.id
WHERE
- users.name = 'Mark';
+ profiles.name = 'Mark';
--------------------------------
-- Pulse and blood pressure
SELECT DISTINCT
date,
- users.name,
+ profiles.name,
tags,
notes,
CAST(sys.value AS int) || '/' || CAST(dia.value AS int) AS pressure,
CAST(pulse.value AS int) AS pulse
FROM
biometric_log
- INNER JOIN users ON user_id = users.id
+ INNER JOIN profiles ON profile_id = profiles.id
INNER JOIN bio_log_entry pulse ON pulse.biometric_id = 22
AND pulse.log_id = biometric_log.id
INNER JOIN bio_log_entry sys ON sys.biometric_id = 23
INNER JOIN bio_log_entry dia ON dia.biometric_id = 24
AND dia.log_id = biometric_log.id
WHERE
- users.name = 'Mark';
+ profiles.name = 'Mark';
--------------------------------
-- Height, wrist, ankle
SELECT
date,
- users.name,
+ profiles.name,
height.value AS height,
wrist.value AS wrist,
ankle.value AS ankle
FROM
biometric_log
- INNER JOIN users ON user_id = users.id
+ INNER JOIN profiles ON profile_id = profiles.id
LEFT JOIN bio_log_entry height ON height.biometric_id = 1
AND height.log_id = biometric_log.id
LEFT JOIN bio_log_entry wrist ON wrist.biometric_id = 3
SELECT
date,
- users.name,
+ profiles.name,
chest.value / 2.54 AS chest,
arm.value / 2.54 AS arm,
thigh.value / 2.54 AS thigh,
forearm.value / 2.54 AS forearm
FROM
biometric_log
- INNER JOIN users ON user_id = users.id
+ INNER JOIN profiles ON profile_id = profiles.id
LEFT JOIN bio_log_entry chest ON chest.biometric_id = 5
AND chest.log_id = biometric_log.id
LEFT JOIN bio_log_entry arm ON arm.biometric_id = 6
SELECT
date,
- users.name,
+ profiles.name,
CAST(pectoral.value AS int) AS pec,
CAST(abdominal.value AS int) AS ab,
CAST(quadricep.value AS int) AS quad,
CAST(suprailiac.value AS int) AS supra
FROM
biometric_log
- INNER JOIN users ON user_id = users.id
+ INNER JOIN profiles ON profile_id = profiles.id
LEFT JOIN bio_log_entry pectoral ON pectoral.biometric_id = 14
AND pectoral.log_id = biometric_log.id
LEFT JOIN bio_log_entry abdominal ON abdominal.biometric_id = 15
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
+PRAGMA foreign_keys = 1;
+-- PRAGMA integrity_check = 1;
+
+
.mode csv
-.nullvalue NULL
+-- .nullvalue NULL
.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/meals.csv' meals
.import '| tail -n +2 ./data/biometrics.csv' biometrics
-.import '| tail -n +2 ./data/users.csv' users
+.import '| tail -n +2 ./data/profiles.csv' profiles
.import '| tail -n +2 ./data/rda.csv' rda
.import '| tail -n +2 ./data/recipes.csv' recipes
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
-PRAGMA foreign_keys = 1;
-
CREATE TABLE version( id integer PRIMARY KEY AUTOINCREMENT, version text NOT NULL, created date NOT NULL, notes text
);
--
--------------------------------
--- Users table
+-- Profiles table
--------------------------------
-CREATE TABLE users (
+CREATE TABLE profiles (
id integer PRIMARY KEY AUTOINCREMENT,
name text NOT NULL UNIQUE,
guid text NOT NULL DEFAULT (lower(hex (randomblob (16)))) UNIQUE,
CREATE TABLE biometric_log (
id integer PRIMARY KEY AUTOINCREMENT,
guid text NOT NULL DEFAULT (lower(hex (randomblob (16)))) UNIQUE,
- user_id int NOT NULL,
+ profile_id int NOT NULL,
created int DEFAULT (strftime ('%s', 'now')),
updated int DEFAULT (strftime ('%s', 'now')),
synced int DEFAULT -1,
date int DEFAULT (strftime ('%s', 'now')),
tags text,
notes text,
- FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
+ FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE
);
CREATE TABLE bio_log_entry (
CREATE TABLE food_log (
id integer PRIMARY KEY AUTOINCREMENT,
guid text NOT NULL DEFAULT (lower(hex (randomblob (16)))) UNIQUE,
- user_id int NOT NULL,
+ profile_id int NOT NULL,
date date DEFAULT CURRENT_DATE,
meal_id int NOT NULL,
food_id int NOT NULL, -- TODO: enforce FK constraint across two DBs?
grams real NOT NULL,
- FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE,
+ FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE,
FOREIGN KEY (meal_id) REFERENCES meals (id) ON UPDATE CASCADE
);
CREATE TABLE recipe_log (
id integer PRIMARY KEY AUTOINCREMENT,
guid text NOT NULL DEFAULT (lower(hex (randomblob (16)))) UNIQUE,
- user_id int NOT NULL,
+ profile_id int NOT NULL,
date date DEFAULT CURRENT_DATE,
meal_id int NOT NULL,
recipe_id int NOT NULL,
grams real NOT NULL,
- FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE,
+ FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE,
FOREIGN KEY (meal_id) REFERENCES meals (id) ON UPDATE CASCADE,
FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
);
--------------------------------
CREATE TABLE rda (
- user_id int NOT NULL,
+ profile_id int NOT NULL,
-- TODO: enforce FK constraint across two DBs?
nutr_id int NOT NULL,
rda real NOT NULL,
synced int DEFAULT 0,
- PRIMARY KEY (user_id, nutr_id),
- FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE
+ PRIMARY KEY (profile_id, nutr_id),
+ FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE
);
CREATE TRIGGER rda_sync
BEGIN
UPDATE rda SET synced = 0
WHERE
- NEW.user_id = user_id AND NEW.nutr_id = nutr_id;
+ NEW.profile_id = profile_id AND NEW.nutr_id = nutr_id;
END;