]> Nutra Git (v2) - nutratech/usda-sqlite.git/commitdiff
makefile, readme
authorShane Jaroch <chown_tee@proton.me>
Thu, 18 Apr 2024 16:06:38 +0000 (12:06 -0400)
committerShane Jaroch <chown_tee@proton.me>
Thu, 18 Apr 2024 16:06:38 +0000 (12:06 -0400)
Makefile
README.rst

index c07423c86507932d7ee09b2d7c72c152585996e4..c01090e74efba6524009891dc561e635c9282779 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,23 +9,6 @@ _help:
 
 
 
-# ---------------------------------------
-# 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
 # ---------------------------------------
@@ -33,6 +16,7 @@ init: ## Install requirements (w/o --frozen-lockfile)
 .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\
 
@@ -43,13 +27,24 @@ format:     ## format SQL with pg_format
 # ---------------------------------------
 
 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
@@ -61,9 +56,9 @@ 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:
@@ -76,14 +71,22 @@ 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}
 
 
 
index 35fbc09f69ea22c9dfc684bd060755d74b916416..a3e006ef9b2d3ee4f1b578d6f1d7ae3744c8dffc 100644 (file)
@@ -30,7 +30,8 @@ Building the database
     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                           |
@@ -44,7 +45,7 @@ Building the database
 
 4. i. (Optional) Enforce foreign keys with your ``~/.sqliterc`` file,
 
-::
+.. code-block:: text
 
     .headers on
     .mode column
@@ -54,21 +55,27 @@ Building the database
 
 .. 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)