2.5 KiB
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
.gitattributesrequired:core.autocrlf=trueon the Windows dev machine would corrupt shell scripts at checkout (turning LF → CRLF →bad interpreter: /usr/bin/env bash^M). Addeddirectus/.gitattributeswith*.sh text eol=lfand*.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 aftergit add(not before — the file must already be indexed). If re-staged after a chmod, the bit is preserved as long as--chmod=+xwas 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 thenode:22-alpinebase image (ships Bash 5.x). Do not use[[ "${ARRAY[$key]+_}" ]]— less readable. set -euo pipefail+|| psql_exit=$?: The||short-circuitsset -efor that single statement, which is correct and idiomatic Bash. This is the approved pattern for capturing psql exit status without disablingset -eglobally.run_psqlwrapper vs inline: The guard-table bootstrap and the record-insert userun_psql/ inline psql respectively. The apply step cannot userun_psqlbecause it needs-v ON_ERROR_STOP=1 -1 --file=which are not generic flags. This duplication is intentional.compgen -Gfor glob check: Used to detect whether any*.sqlfiles exist before callingls | sort. Avoidsls: cannot access ... No such file or directoryerror underset -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". Withset -euo pipefailand 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.