Skip to content

Commit

Permalink
makefile, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesguru committed Apr 18, 2024
1 parent 810083f commit c949dc0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
51 changes: 27 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,14 @@ _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
# ---------------------------------------

.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\

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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}



Expand Down
29 changes: 18 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -44,7 +45,7 @@ Building the database

4. i. (Optional) Enforce foreign keys with your ``~/.sqliterc`` file,

::
.. code-block:: text
.headers on
.mode column
Expand All @@ -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)
Expand Down

0 comments on commit c949dc0

Please sign in to comment.