@biffo/cli 0.329.0 → 0.331.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +318 -207
- package/package.json +1 -1
- package/scripts/pg-test-db.sh +28 -2
package/package.json
CHANGED
package/scripts/pg-test-db.sh
CHANGED
|
@@ -121,7 +121,27 @@
|
|
|
121
121
|
|
|
122
122
|
set -eu
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
# Which repo's schema to build. The script used to always use the directory two
|
|
125
|
+
# levels above ITSELF, which is the template checkout when run from one but the
|
|
126
|
+
# npm package directory when run from the published `@biffo/cli` -- so
|
|
127
|
+
# `biffo plugin verify` in a plugin repo looked for a schema in the package and
|
|
128
|
+
# found none. Resolution order:
|
|
129
|
+
# 1. BIFFO_REPO_ROOT, when a caller (e.g. `plugin verify`) names the repo;
|
|
130
|
+
# 2. the caller's working directory, when it holds a schema (db/imports/*/*.sql
|
|
131
|
+
# or an alembic.ini, here or in services/api);
|
|
132
|
+
# 3. the directory above this script -- the template-checkout behaviour.
|
|
133
|
+
_script_root=$(cd "$(dirname "$0")/.." && pwd)
|
|
134
|
+
_has_schema() {
|
|
135
|
+
[ -n "$(find "$1/db/imports" -mindepth 2 -maxdepth 2 -name '*.sql' 2>/dev/null | head -n 1)" ] ||
|
|
136
|
+
[ -f "$1/services/api/alembic.ini" ] || [ -f "$1/alembic.ini" ]
|
|
137
|
+
}
|
|
138
|
+
if [ -n "${BIFFO_REPO_ROOT:-}" ]; then
|
|
139
|
+
REPO_ROOT=$(cd "$BIFFO_REPO_ROOT" && pwd)
|
|
140
|
+
elif _has_schema "$PWD"; then
|
|
141
|
+
REPO_ROOT=$(pwd -P)
|
|
142
|
+
else
|
|
143
|
+
REPO_ROOT="$_script_root"
|
|
144
|
+
fi
|
|
125
145
|
|
|
126
146
|
# sha256sum is already a dependency of this script (see `fingerprint` below),
|
|
127
147
|
# so reusing it here for a deterministic, cheap per-checkout key adds nothing
|
|
@@ -198,6 +218,12 @@ ALEMBIC_DIR=""
|
|
|
198
218
|
for _d in services/api .; do
|
|
199
219
|
[ -f "$_d/alembic.ini" ] && ALEMBIC_DIR="$_d" && break
|
|
200
220
|
done
|
|
221
|
+
# A caller that has BUILT a schema elsewhere (`plugin verify` generates an Alembic
|
|
222
|
+
# chain from biffo.plugin.json's tables into a scratch directory) names it here.
|
|
223
|
+
# BIFFO_PG_ALEMBIC_PROJECT is the uv project that supplies alembic + the async
|
|
224
|
+
# driver; when unset, uv uses the alembic directory itself, as before.
|
|
225
|
+
[ -n "${BIFFO_PG_ALEMBIC_DIR:-}" ] && ALEMBIC_DIR="$BIFFO_PG_ALEMBIC_DIR"
|
|
226
|
+
ALEMBIC_PROJECT="${BIFFO_PG_ALEMBIC_PROJECT:-}"
|
|
201
227
|
|
|
202
228
|
if [ -z "$DDL_FILES" ] && [ -z "$ALEMBIC_DIR" ]; then
|
|
203
229
|
say "no db/imports/*/ DDL and no alembic.ini - this repo has no schema to build"
|
|
@@ -629,7 +655,7 @@ psql_admin -c "DROP DATABASE IF EXISTS $DB WITH (FORCE)" >/dev/null
|
|
|
629
655
|
psql_admin -c "CREATE DATABASE $DB" >/dev/null
|
|
630
656
|
|
|
631
657
|
if [ -n "$ALEMBIC_DIR" ]; then
|
|
632
|
-
BIFFO_DATABASE_URL="$DSN" uv run --directory "$ALEMBIC_DIR" alembic upgrade head >/dev/null
|
|
658
|
+
BIFFO_DATABASE_URL="$DSN" uv run ${ALEMBIC_PROJECT:+--project "$ALEMBIC_PROJECT"} --directory "$ALEMBIC_DIR" alembic upgrade head >/dev/null
|
|
633
659
|
say "alembic upgrade head"
|
|
634
660
|
fi
|
|
635
661
|
|