Skip to content

store: create the database directory on Open, not via make run

Aiho Tehisaru requested to merge fix/store-create-db-dir into trunk

Summary

Fresh-clone run (make run / go run ./cmd/rax, no pre-existing ./data) failed on first start:

store: store: migrating ./data/rax.db: executing "CREATE TABLE ...":
unable to open database file (14)

store.Open never created its own database directory — it only worked because the Makefile's run target papered over the gap with mkdir -p data. Anyone launching the binary any other way (Docker, a built ./rax, a custom RAX_DB_PATH) hit the same failure on first start.

  • internal/store/store.go: Open now os.MkdirAlls the target directory before sql.Open (skipped for the :memory: test path, and for a bare filename with no directory component).
  • Makefile: dropped the now-redundant mkdir -p data from run.
  • README.md: updated the "Running locally" note accordingly.

Test plan

  • gofmt -s -w . && gofmt -l . && go build ./... && go vet ./... && go test ./... — clean
  • Built the binary and ran it with RAX_DB_PATH=./freshdata/rax.db against a directory with no freshdata/ present — confirmed it creates the directory and rax.db on startup with no error

🤖 Generated with Claude Code

https://claude.ai/code/session_01U9buZPRQy7YXLodkSPFFik

Merge request reports

Loading