+++ /dev/null
-# 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`
--- /dev/null
+***********
+ 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``
.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
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
-
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,
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,
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,
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
);
--
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,
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 ( ... );
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
);
--
-- 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
);
--
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 (
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
);