-# ---------------------------------------
-# Install requirements
-# ---------------------------------------
-
-.PHONY: init
-init: ## Install requirements (w/o --frozen-lockfile)
- # Check version
- [[ "$(shell pnpm --version)" =~ "8." ]]
- # Remove old install
- rm -rf node_modules/
- # Install requirements
- pnpm install
- # Sync svelte kit (optional)
- pnpm svelte-kit sync
-
-
-
# ---------------------------------------
# Format
# ---------------------------------------
.PHONY: format
format: ## format SQL with pg_format
# TODO: what about import.sql? It gets formatted too ugly
+ # TODO: what about Python files?
pg_format -L -s 2 -w 100 sql/tables.sql >sql/tables.fmt.sql
mv sql/tables.fmt.sql sql/tables.sql\
# ---------------------------------------
DB_VERSION ?= $(shell python3 sql/latest_version.py)
-DB_FILE ?= sql/dist/usda.sqlite3-${DB_VERSION}.tar.xz
+DB_FILE ?= sql/usda.sqlite3
+DB_XZ_FILE ?= sql/dist/usda.sqlite3-${DB_VERSION}.tar.xz
.PHONY: build
build: clean
-build: ## Build the release
+build: ## Build the release (compressed XZ file)
./sql/build.sh ${DB_VERSION}
- du -h ${DB_FILE}
+ du -h ${DB_XZ_FILE}
+
+.PHONY: test
+test: ## Test the SQL database with basic queries
+ test -f ${DB_FILE}
+ sqlite3 ${DB_FILE} ".tables"
+ sqlite3 ${DB_FILE} "\
+ SELECT * FROM nutr_def WHERE id=328; \
+ SELECT long_desc FROM food_des WHERE id=9050; \
+ SELECT * FROM version; \
+ "
.PHONY: deploy/get-current-db-version
.PHONY: deploy/upload
deploy/upload: ## Upload to GitHub releases
test -n "${DB_VERSION}"
- test -f ${DB_FILE}
+ test -f ${DB_XZ_FILE}
gh release create v${DB_VERSION} --generate-notes
- gh release upload v${DB_VERSION} ${DB_FILE}
+ gh release upload v${DB_VERSION} ${DB_XZ_FILE}
.PHONY: deploy/delete
deploy/delete:
REMOTE_HEAD ?= origin/master
PROJECT_NAME ?= usda-sqlite
+.PHONY: _check-git-up-to-date
+_check-git-up-to-date:
+ git branch --show-current
+ git fetch
+ # Check that we are in sync with ${REMOTE_HEAD}
+ git diff --quiet ${REMOTE_HEAD}
+
+
.PHONY: deploy/install-prod
deploy/install-prod: _check-git-up-to-date
deploy/install-prod: ## Install (on prod VPS)
# Check the version string was extracted from package.json
test -n "${DB_VERSION}"
# Download ${DB_VERSION}
- curl -sSLO https://github.com/nutratech/${PROJECT_NAME}/releases/download/${DB_VERSION}/${DB_FILE}
- tar xf ${DB_FILE}
+ curl -sSLO https://github.com/nutratech/${PROJECT_NAME}/releases/download/${DB_VERSION}/${DB_XZ_FILE}
+ tar xf ${DB_XZ_FILE}
bash setup.sh
python3 process.py
-3. If you are committing database changes, add a line to :code:`sql/version.csv` (e.g. :code:`id=3` is the latest in this case),
+3. If you are committing database changes, add a line to
+ :code:`sql/version.csv` (e.g. :code:`id=3` is the latest in this case).
+-----+----------+-----------------------------------+
| id | version | created |
4. i. (Optional) Enforce foreign keys with your ``~/.sqliterc`` file,
-::
+.. code-block:: text
.headers on
.mode column
.. code-block:: bash
- cd ../sql
- ./build.sh X.X.X # e.g. 0.0.8
+ make build
-5. Verify the tables (again inside the SQL shell :code:`sqlite3 usda.sqlite3`),
+5. Verify the tables (inside an SQL shell: :code:`sqlite3 sql/usda.sqlite3`),
.. code-block:: sql
- .tables
- SELECT * FROM nutr_def WHERE id=328;
- SELECT long_desc FROM food_des WHERE id=9050;
- SELECT * FROM version;
- .exit
+ .tables
-6. If everything looks good, upload compressed :code:`dist/nutra-X.X.X.db.tar.xz` file to binary host (bitbucket files).
+ SELECT * FROM nutr_def WHERE id=328;
+ SELECT long_desc FROM food_des WHERE id=9050;
+ SELECT * FROM version;
+
+ .exit
+
+6. If everything looks good, upload compressed
+ :code:`dist/nutra-X.X.X.db.tar.xz` file to binary host.
+
+.. code-block:: bash
+
+ make deploy/upload
Tables (Relational Design)