feat(legacy): helpers: allow HECTIC_NAMESPACE be empty

This commit is contained in:
2025-11-16 16:56:26 +00:00
parent bb99ef9a8a
commit 00f05cc3db
8 changed files with 37 additions and 22 deletions

View File

@@ -20,11 +20,11 @@
# When you use NC to reset terminal colors inside log output,
# it resets back to the log levels color instead of the terminal default.
: "${HLOG_NAMESPACE:="$(basename "$0")"}"
: "${HLOG_LEVEL:=trace}" # e.g. "info;ns1=debug;ns2=trace"
: "${HECTIC_NAMESPACE="$(basename "$0")"}"
: "${HECTIC_LOG:=trace}" # e.g. "info;ns1=debug;ns2=trace"
validate_log_level_spec() {
spec=$HLOG_LEVEL
spec=$HECTIC_LOG
levels="trace debug info notice warn error"
@@ -58,7 +58,7 @@ validate_log_level_spec() {
return 0
}
validate_log_level_spec || { printf "%b%b\n" "${BBLACK}${HLOG_NAMESPACE}> " "${color}invalid HLOG_LEVEL syntax${NC}" "$@" >&2; exit 1; }
validate_log_level_spec || { printf "%b%b\n" "${BBLACK}${HECTIC_NAMESPACE}> " "${color}invalid HECTIC_LOG syntax${NC}" "$@" >&2; exit 1; }
log_level_num() {
case $1 in
@@ -74,8 +74,8 @@ log_level_num() {
log_effective_level() {
spec=$HLOG_LEVEL
ns=$HLOG_NAMESPACE
spec=$HECTIC_LOG
ns=$HECTIC_NAMESPACE
default_level=
ns_level=
@@ -133,5 +133,5 @@ log() {
# shellcheck disable=SC1003
fmt="$(printf "%s$delimetr" "$@" | sed 's/\\033\[0m/''\'"$color"'/g')"
shift
printf "%b%b\n" "${BBLACK}${HLOG_NAMESPACE}> " "$color$fmt$NC" >&2
printf "%b%b\n" "${BBLACK}${HECTIC_NAMESPACE}> " "$color$fmt$NC" >&2
}

View File

@@ -1,5 +1,7 @@
#!/bin/dash
set -eu
if ! command -v psql >/dev/null; then
log error "Required tool (psql) are not installed."
exit 127
@@ -17,6 +19,8 @@ sha256sum() {
cksum --algorithm=sha256 --untagged "$file" | awk '{printf $1}'
}
INHERITS_LIST=
while [ $# -gt 0 ]; do
log debug "$1"
case $1 in

View File

@@ -3,6 +3,9 @@
# $out - nix derivation output
# $test - test and assertion file
HECTIC_NAMESPACE=test-laucher
export HECTIC_LOG=trace
test_derivation="$(basename "$test")"
test_name="${test_derivation#*-*-}"
@@ -61,6 +64,8 @@ log info "run test ${WHITE}${test_name}${NC}"
# run test
. "${test}/run.sh"
HECTIC_NAMESPACE=test-laucher
log info "finish test pipeline"
# success marker for Nix

View File

@@ -1,7 +1,8 @@
#
# first migration
#
#!/bin/dash
HECTIC_NAMESPACE=test-create-migration
log notice "case: ${WHITE}first migration"
if ! migrator create; then
log error "test failed: error on migration creation"
exit 1
@@ -17,10 +18,7 @@ if [ "$(find ./migration -maxdepth 1 -type f | wc -l)" -eq 0 ]; then
exit 1
fi
#
# next migration
#
log notice "case: ${WHITE}next migration"
if ! migrator create; then
log error "test failed: error on migration creation"
exit 1
@@ -31,10 +29,7 @@ if [ "$(find ./migration -maxdepth 1 -type f | wc -l)" -eq 1 ]; then
exit 1
fi
#
# migration with custom name
#
log notice "case: ${WHITE}migration with custom name"
if ! migrator create --name test; then
log error "test failed: error on migration creation"
exit 1
@@ -50,10 +45,7 @@ if ! find ./migration -maxdepth 1 -type f -name '*test.sql' \
log eror "test failed: migration have unexpected name"
fi
#
# migration with custom name that contains space
#
log notice "case: ${WHITE}migration with custom name that contains space"
if ! migrator create --name 'test name'; then
log error "test failed: error on migration creation"
exit 1

View File

@@ -1,5 +1,7 @@
#!/bin/dash
HECTIC_NAMESPACE=test-init-migrator
log info "hectic.migration table inheritance"
if ! migration_table_sql="$(migrator --inherits tablename --inherits 'table name' init --dry-run)"; then
log error "test failed: error on migration table init dry run"

View File

@@ -1,3 +1,7 @@
#!/bin/dash
HECTIC_NAMESPACE=test-migration-list
psql "$DATABASE_URL" 'CREATE TABLE profile (
id INTEGER,
username TEXT

View File

@@ -1 +1,5 @@
#!/bin/dash
HECTIC_NAMESPACE=test-migration-list
#migrator list

View File

@@ -1,3 +1,7 @@
#!/bin/dash
HECTIC_NAMESPACE=test-missing-psql
# remove psql from $PATH
dir=$(dirname -- "$(command -v psql)")
PATH=$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: -v d="$dir" '$0!=d{print}')