Add sqlc configuration and core queries
CI / ci (push) Successful in 1m25s
Independent review Codex gpt-6-sol high: APPROVED (0 findings)
CI / ci (pull_request) Successful in 1m25s

sqlc.yaml (sqlite, schema migrations/, queries migrations/queries/)
generates internal/db with emit_interface. Queries cover dinners (create,
get, list by status, update, archive, set favorite), recipes with
ingredients and steps (upsert by source_url, get, replace children),
photos (insert, get by sha256) and get/upsert for the five settings
singletons. Repository tests run every query against a migrated temp
database.

make sqlc regenerates with the pinned sqlc v1.31.1 (dev tool only, not in
go.mod); make sqlc-check regenerates and fails on any drift in
internal/db, and CI runs it after make test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-03 09:11:18 -04:00
co-authored by Claude Opus 5.5
parent fa7c6b7218
commit 85ea9c5da4
15 changed files with 2421 additions and 2 deletions
+29 -1
View File
@@ -5,6 +5,9 @@
# make test gofmt check, go vet, go test -race, npm typecheck and test.
# make build Build the PWA, embed it, build the static binary bin/mealquest.
# make docker Build the container image from ./Dockerfile.
# make sqlc Regenerate internal/db from sqlc.yaml with the pinned sqlc.
# make sqlc-check Regenerate; fail if internal/db differs from the commit.
# make sqlc-install Install the pinned sqlc into the Go bin directory.
FRONTEND_DIST := internal/frontend/dist
# Dirty means a tracked change outside the generated embed output, which
@@ -14,7 +17,13 @@ VERSION ?= $(shell git describe --tags --always 2>/dev/null || echo dev)$(if $(G
IMAGE ?= mealquest:$(VERSION)
LDFLAGS := -s -w -X main.version=$(VERSION)
.PHONY: dev test go-test web-test build web embed check-embed-clean docker
# sqlc is a dev tool only, never a go.mod dependency. Generated code records
# the version that wrote it, so every run must use exactly this one.
SQLC_VERSION := v1.31.1
SQLC ?= sqlc
SQLC_OUT := internal/db
.PHONY: dev test go-test web-test build web embed check-embed-clean docker sqlc sqlc-check sqlc-install
# Run both servers; Ctrl-C (or either exiting) stops both. The binary is built
# first and run directly because `go run` would orphan its child on kill.
@@ -58,3 +67,22 @@ check-embed-clean:
docker:
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE) .
# sqlc $(SQLC_VERSION) needs Go 1.26 to build; GOTOOLCHAIN=auto lets go fetch
# it for this install only, even where the environment pins the local Go.
sqlc-install:
GOTOOLCHAIN=auto go install github.com/sqlc-dev/sqlc/cmd/sqlc@$(SQLC_VERSION)
# Previously generated files are removed first so a dropped query file does
# not leave its stale output behind; hand-written files are kept.
sqlc:
@v="$$($(SQLC) version)"; \
if [ "$$v" != "$(SQLC_VERSION)" ]; then echo "sqlc $(SQLC_VERSION) required, $(SQLC) is $$v"; exit 1; fi
find $(SQLC_OUT) -maxdepth 1 -name '*.go' -exec grep -l -x '// Code generated by sqlc. DO NOT EDIT.' {} + | xargs -r rm --
$(SQLC) generate
# Fails on any difference from the committed generated code, including new
# or deleted files.
sqlc-check: sqlc
@drift="$$(git status --porcelain --untracked-files=all -- $(SQLC_OUT))"; \
if [ -n "$$drift" ]; then echo "internal/db is stale; run make sqlc and commit:"; echo "$$drift"; git diff -- $(SQLC_OUT); exit 1; fi