From: Shane Jaroch Date: Thu, 18 Apr 2024 16:06:38 +0000 (-0400) Subject: makefile, readme X-Git-Url: https://git.nutra.tk/v1?a=commitdiff_plain;h=c949dc05b6f18cca41f2224a02b7ba30ec483a7d;p=nutratech%2Fusda-sqlite.git makefile, readme --- diff --git a/Makefile b/Makefile index c07423c..c01090e 100644 --- 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} diff --git a/README.rst b/README.rst index 35fbc09..a3e006e 100644 --- a/README.rst +++ b/README.rst @@ -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)