]> Nutra Git (v1) - nutratech/nt-sqlite.git/commitdiff
wip tables 10/head
authorShane Jaroch <chown_tee@proton.me>
Mon, 11 Jul 2022 23:18:27 +0000 (19:18 -0400)
committerShane Jaroch <chown_tee@proton.me>
Tue, 12 Jul 2022 18:23:32 +0000 (14:23 -0400)
use rst for changelog, no plural tables, wip other

fix test, in Makefile

tweak changelog

CHANGELOG.md [deleted file]
CHANGELOG.rst [new file with mode: 0644]
Makefile
sql/data/bf_eq.csv [moved from sql/data/bf_eqs.csv with 100% similarity]
sql/data/bmr_eq.csv [moved from sql/data/bmr_eqs.csv with 100% similarity]
sql/format.sh
sql/tables.sql

diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644 (file)
index b77c00a..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-# Changelog
-
-All notable changes to this project will be documented in this file.
-
-The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
-and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-
-## [Unreleased]
-
-### Changed
-
-- Replace grams with `msre_id` and `amt` in `food_log` table
-- Rename to use `.sqlite3` extension, instead of `nt.sqlite`
-
-### Development
-
-- Enhance lint tools
-- Use `__main__.py` & `python -m sql` to package and build sqlite3 file
-
-### Added
-
-- SQL tables `bug` and `msg`, for bug reports & pushed message queue
-
-## [0.0.4] - 2021-06-17
-
-### Added
-
-- Empty `__init__.py` file to make packageable with `cli` repo (as a `git submodule`)
-- SQL table `custom_foods` and respective `cf_dat`
-
-### Changed
-
-- Build with `python sql/__init__.py` (removed root-level script `build.py`)
-- Rename pre-populated `meals` table to `meal_name`
-
-### Fixed
-
-- Slight bash inconvenience when using `export.sh`
-
-### Removed
-
-- `food_costs` table
-- `biometrics` ad related tables
-
-## [0.0.3] - 2021-05-24
-
-### Added
-
-- More dummy CSV data (not production ready)
-- `tagname` column to `recipes` table
-
-### Changed
-
-- `date` column uses `INT` type now, instead of `date`
-- Drop `created` and `updated` fields off of `rda` table, add them to `biometrics`
-
-### Removed
-
-- `last_sync` column (future release? Feature is planned, but not allotted)
-- `guid` parameter from `functions.sql`
-
-## [0.0.2] - 2021-05-24
-
-### Added
-
-`SCRIPT_DIR` in `sql/__init__.py` to help track `cwd`
-
-### Removed
-
-- `guid` columns (may return in a future release)
-
-## [0.0.1] - 2021-05-21
-
-### Added
-
-- Version table
-- Travis CI configuration file `.travis.yml`
-- `functions.sql` for use in Python client
-- [TODO] Placeholder for initial upgrade script (`sql/upgrade_scripts/0.0.1.sql`)
-- `food_costs` table (lone table, functionality not yet implemented)
-
-### Changed
-
-- Use Python for import script (`build.py` replaced `import.sql`)
-
-## [0.0.0] - 2020-09-22
-
-### Added
-
-- Initial release of table schema design
-- Import script `import.sql` (SQL)
-- Export script `export.sh` (Shell)
-- Rudimentary dummy data in CSV files
-    (e.g. `food_log.csv`, `biometric_log.csv`, `profiles.csv`)
-- Database diagram generated via `docs/sqleton.sh`
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644 (file)
index 0000000..36478bb
--- /dev/null
@@ -0,0 +1,138 @@
+***********
+ Changelog
+***********
+
+All notable changes to this project will be documented in this file.
+
+The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.1.0/>`_,
+and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
+
+
+
+`[Unreleased] <https://github.com/nutratech/nt-sqlite/compare/0.0.5...HEAD>`_
+##############################################################################
+
+
+
+`[0.0.5] - 2022-07-11 <https://github.com/nutratech/nt-sqlite/compare/0.0.4...0.0.5>`_
+######################################################################################
+
+Changed
+~~~~~~~
+
+- Replace grams with ``msre_id`` and ``amt`` in ``food_log`` table
+- Rename to use ``.sqlite3`` extension, instead of ``nt.sqlite``
+
+Development
+~~~~~~~~~~~
+
+- Enhance lint tools
+- Use ``__main__.py`` & ``python -m sql`` to package and build sqlite3 file
+
+Added
+~~~~~
+
+- SQL tables ``bug`` and ``msg``, for bug reports & pushed message queue
+
+
+
+`[0.0.4] - 2021-06-17 <https://github.com/nutratech/nt-sqlite/compare/0.0.3...0.0.4>`_
+######################################################################################
+
+Added
+~~~~~
+
+- Empty ``__init__.py`` file to make packageable with ``cli`` repo
+  (as a ``git submodule``)
+- SQL table ``custom_foods`` and respective ``cf_dat``
+
+Changed
+~~~~~~~
+
+- Build with ``python sql/__init__.py`` (removed top-level script ``build.py``)
+- Rename pre-populated ``meals`` table to ``meal_name``
+
+Fixed
+~~~~~
+
+- Slight bash inconvenience when using ``export.sh``
+
+Removed
+~~~~~~~
+
+- ``food_costs`` table
+- ``biometrics`` ad related tables
+
+
+
+`[0.0.3] - 2021-05-24 <https://github.com/nutratech/nt-sqlite/compare/0.0.2...0.0.3>`_
+######################################################################################
+
+Added
+~~~~~
+
+- More dummy CSV data (not production ready)
+- ``tagname`` column to ``recipes`` table
+
+Changed
+~~~~~~~
+
+- ``date`` column uses ``INT`` type now, instead of ``date``
+- Drop ``created`` and ``updated`` fields off of ``rda`` table,
+  add them to ``biometrics``
+
+Removed
+~~~~~~~
+
+- ``last_sync`` column (future release? Feature is planned, but not allotted)
+- ``guid`` parameter from ``functions.sql``
+
+
+
+`[0.0.2] - 2021-05-24 <https://github.com/nutratech/nt-sqlite/compare/0.0.1...0.0.2>`_
+######################################################################################
+
+Added
+~~~~~
+
+``SCRIPT_DIR`` in ``sql/__init__.py`` to help track ``cwd``
+
+Removed
+~~~~~~~
+
+- ``guid`` columns (may return in a future release)
+
+
+
+`[0.0.1] - 2021-05-21 <https://github.com/nutratech/nt-sqlite/compare/0.0.0...0.0.1>`_
+######################################################################################
+
+Added
+~~~~~
+
+- Version table
+- Travis CI configuration file ``.travis.yml``
+- ``functions.sql`` for use in Python client
+- [TODO] Placeholder for initial upgrade script
+  (``sql/upgrade_scripts/0.0.1.sql``)
+- ``food_costs`` table (lone table, functionality not yet implemented)
+
+Changed
+~~~~~~~
+
+- Use Python for import script (``build.py`` replaced ``import.sql``)
+
+
+
+`[0.0.0] - 2020-09-22 <https://github.com/nutratech/nt-sqlite/tree/0.0.0>`_
+###########################################################################
+
+Added
+~~~~~
+
+- Initial release of table schema design
+- Import script ``import.sql`` (SQL)
+- Export script ``export.sh`` (Shell)
+- Rudimentary dummy data in CSV files
+    (e.g. ``food_log.csv``, ``biometric_log.csv``, ``profiles.csv``)
+- Database diagram generated via ``docs/sqleton.sh``
index c52a3afebd338f11a580c6daf39a91cfa9ccc60c..14b0c7d001db0342c69354d6fd1aabb54847d501 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,15 +15,16 @@ clean:      ## Clean up build intermediates
 
 .PHONY: build
 build: ## Build sqlite image
-       python -m sql
+       python3 -m sql
 
 .PHONY: test
 test:  ## Cursory sanity check
        sqlite3 -csv -header \
                sql/nt.sqlite3 \
-               'SELECT * FROM bf_eqs;' \
-               'SELECT * FROM bmr_eqs;' \
+               'SELECT * FROM bf_eq;' \
+               'SELECT * FROM bmr_eq;' \
                'SELECT * FROM meal_name;' \
+               'SELECT * FROM rda;' \
                'SELECT * FROM version;' \
 
 .PHONY: install
similarity index 100%
rename from sql/data/bf_eqs.csv
rename to sql/data/bf_eq.csv
similarity index 100%
rename from sql/data/bmr_eqs.csv
rename to sql/data/bmr_eq.csv
index ac6058e18d1a04be1186604d7f017624250fe10b..d7126ee5df5cc3bc0853cd62defd4dec027849ee 100755 (executable)
@@ -3,9 +3,8 @@
 cd "$(dirname "$0")"
 
 # Format
-pg_format -L -s 2 -w 80 tables.sql >tables.fmt.sql
+pg_format -L -s 2 -w 100 tables.sql >tables.fmt.sql
 mv tables.fmt.sql tables.sql
 
-pg_format -L -s 2 -w 80 functions.sql >functions.fmt.sql
+pg_format -L -s 2 -w 100 functions.sql >functions.fmt.sql
 mv functions.fmt.sql functions.sql
-
index 3a95eda5316945aa90b826d2e135e5b656c1cb25..ef7e773edb3c7ba062ce0b0d468cf7d1bbdca268 100644 (file)
@@ -20,27 +20,28 @@ CREATE TABLE `version` (
   notes text
 );
 
+-- NOTE: INSERT INTO statements for version, bmr_eq, bf_eq? Don't maintain as CSV?
 -- TODO: enforce FK constraint across two DBs?
 --
 ---------------------------------
 -- Equations
 ---------------------------------
-CREATE TABLE bmr_eqs (
+CREATE TABLE bmr_eq (
   id integer PRIMARY KEY AUTOINCREMENT,
   name text NOT NULL UNIQUE
 );
 
-CREATE TABLE bf_eqs (
+CREATE TABLE bf_eq (
   id integer PRIMARY KEY AUTOINCREMENT,
   name text NOT NULL UNIQUE
 );
 
 --
 --------------------------------
--- Profiles table
+-- Profile table
 --------------------------------
 -- TODO: active profile? Decide what belongs here, vs. in prefs.json (if at all)
-CREATE TABLE profiles (
+CREATE TABLE profile (
   id integer PRIMARY KEY AUTOINCREMENT,
   name text NOT NULL UNIQUE,
   gender text,
@@ -51,15 +52,15 @@ CREATE TABLE profiles (
   bmr_eq_id int DEFAULT 1,
   bf_eq_id int DEFAULT 1,
   created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (bmr_eq_id) REFERENCES bmr_eqs (id) ON UPDATE CASCADE,
-  FOREIGN KEY (bf_eq_id) REFERENCES bf_eqs (id) ON UPDATE CASCADE
+  FOREIGN KEY (bmr_eq_id) REFERENCES bmr_eq (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (bf_eq_id) REFERENCES bf_eq (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 --
 --------------------------------
--- Recipes
+-- Recipe
 --------------------------------
-CREATE TABLE recipes (
+CREATE TABLE recipe (
   id integer PRIMARY KEY AUTOINCREMENT,
   tagname text NOT NULL UNIQUE,
   name text NOT NULL UNIQUE,
@@ -73,14 +74,14 @@ CREATE TABLE recipe_dat (
   notes text,
   created int DEFAULT (strftime ('%s', 'now')),
   PRIMARY KEY (recipe_id, food_id),
-  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
+  FOREIGN KEY (recipe_id) REFERENCES recipe (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 --
 --------------------------------
 -- Custom foods
 --------------------------------
-CREATE TABLE custom_foods (
+CREATE TABLE custom_food (
   id integer PRIMARY KEY AUTOINCREMENT,
   tagname text NOT NULL UNIQUE,
   name text NOT NULL UNIQUE,
@@ -94,7 +95,7 @@ CREATE TABLE cf_dat (
   notes text,
   created int DEFAULT (strftime ('%s', 'now')),
   PRIMARY KEY (cf_id, nutr_id),
-  FOREIGN KEY (cf_id) REFERENCES custom_foods (id) ON UPDATE CASCADE
+  FOREIGN KEY (cf_id) REFERENCES custom_food (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 --
@@ -112,15 +113,18 @@ CREATE TABLE food_log (
   profile_id int NOT NULL,
   date int DEFAULT (strftime ('%s', 'now')),
   meal_id int NOT NULL,
-  food_id int NOT NULL,
+  -- NOTE: do we want separate tables for logging `food_id` vs. `custom_food_id`?
+  food_id int,
+  custom_food_id int,
   msre_id int NOT NULL,
   amt real NOT NULL,
   created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE,
-  FOREIGN KEY (meal_id) REFERENCES meal_name (id) ON UPDATE CASCADE
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (meal_id) REFERENCES meal_name (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (custom_food_id) REFERENCES custom_food (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
--- TODO: support msre_id for recipes
+-- TODO: support msre_id for recipe
 CREATE TABLE recipe_log (
   id integer PRIMARY KEY AUTOINCREMENT,
   profile_id int NOT NULL,
@@ -129,9 +133,9 @@ CREATE TABLE recipe_log (
   recipe_id int NOT NULL,
   grams real NOT NULL,
   created int DEFAULT (strftime ('%s', 'now')),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE,
-  FOREIGN KEY (meal_id) REFERENCES meal_name (id) ON UPDATE CASCADE,
-  FOREIGN KEY (recipe_id) REFERENCES recipes (id) ON UPDATE CASCADE
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (meal_id) REFERENCES meal_name (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (recipe_id) REFERENCES recipe (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 -- TODO: CREATE TABLE custom_food_log ( ... );
@@ -144,7 +148,7 @@ CREATE TABLE rda (
   nutr_id int NOT NULL,
   rda real NOT NULL,
   PRIMARY KEY (profile_id, nutr_id),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 --
@@ -155,11 +159,13 @@ CREATE TABLE rda (
 -- Leave edge cases potentially dangling (should never happen)
 -- Does this simplify imports with a potential `guid` column?
 CREATE TABLE food_cost (
-  food_id int NOT NULL,
+  food_id int,
+  custom_food_id int,
   profile_id int NOT NULL,
   cost real NOT NULL,
-  PRIMARY KEY (food_id, profile_id),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE ON DELETE CASCADE
+  PRIMARY KEY (food_id, custom_food_id, profile_id),
+  FOREIGN KEY (custom_food_id) REFERENCES custom_food (id) ON UPDATE CASCADE ON DELETE CASCADE,
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 --
@@ -172,13 +178,16 @@ CREATE TABLE bug (
   profile_id int,
   created int DEFAULT (strftime ('%s', 'now')),
   arguments text,
+  activity text,
   stack text,
-  os text,
-  py_ver text,
-  user_details text,
+  -- e.g. OS, Python / Android version
+  client_info json,
+  -- e.g. app version
+  app_info json,
+  user_details json,
   submitted tinyint DEFAULT 0,
   UNIQUE (arguments, stack),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE ON DELETE CASCADE
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE
 );
 
 CREATE TABLE msg (
@@ -190,5 +199,5 @@ CREATE TABLE msg (
   header text,
   body text,
   UNIQUE (profile_id, msg_id),
-  FOREIGN KEY (profile_id) REFERENCES profiles (id) ON UPDATE CASCADE ON DELETE CASCADE
+  FOREIGN KEY (profile_id) REFERENCES profile (id) ON UPDATE CASCADE ON DELETE CASCADE
 );