Files

2.5 KiB

name, description, type
name description type
Phase 1 task 1.2 — db-init runner decisions Implementation decisions and gotchas from writing apply-db-init.sh project

Phase 1 task 1.2 — db-init runner decisions

Key decisions

  • .gitattributes required: core.autocrlf=true on the Windows dev machine would corrupt shell scripts at checkout (turning LF → CRLF → bad interpreter: /usr/bin/env bash^M). Added directus/.gitattributes with *.sh text eol=lf and *.sql text eol=lf. This is a non-negotiable requirement for any new shell script in the directus service.
  • git update-index --chmod=+x: The only way to set executable bit on Windows without WSL. Must be done after git add (not before — the file must already be indexed). If re-staged after a chmod, the bit is preserved as long as --chmod=+x was called on the indexed file.
  • Filename collision detection uses [[ -v "ARRAY[key]" ]]: The Bash 4.2+ idiom for checking associative array key existence. Safe in the node:22-alpine base image (ships Bash 5.x). Do not use [[ "${ARRAY[$key]+_}" ]] — less readable.
  • set -euo pipefail + || psql_exit=$?: The || short-circuits set -e for that single statement, which is correct and idiomatic Bash. This is the approved pattern for capturing psql exit status without disabling set -e globally.
  • run_psql wrapper vs inline: The guard-table bootstrap and the record-insert use run_psql / inline psql respectively. The apply step cannot use run_psql because it needs -v ON_ERROR_STOP=1 -1 --file= which are not generic flags. This duplication is intentional.
  • compgen -G for glob check: Used to detect whether any *.sql files exist before calling ls | sort. Avoids ls: cannot access ... No such file or directory error under set -e.
  • Filename quoting in SQL: Basenames are passed directly into SQL strings with single quotes. This is safe for filenames matching [0-9]+_[a-z0-9_]+.sql (the project convention). If someone introduces a filename with a single quote, it would break. Acceptable for now — document if it becomes a concern.

What was NOT done (and why)

  • No trap ERR — the spec says "if it adds clarity". With set -euo pipefail and explicit exit codes on every failure path, ERR trapping would only add noise.
  • No lock file for concurrent-boot safety — the task spec acknowledges this risk and defers it to Phase 3+.

Acceptance testing status

Docker was not available in the agent's shell environment. Acceptance tests must be run manually — see the task report for the exact commands.