Files
crewli/Makefile
bert.hausmans a24fa18982 perf(test): make schema-dump target + opt-in fast-path docs (WS-6)
Session 2.6's per-test migrate:fresh in 4 backfill test classes
replays ~120 migrations. Laravel's schema:dump produces a single
SQL file that migrate:fresh loads atomically when present —
significantly faster on environments where the host has the
\`mysql\` CLI available for Laravel's load step.

Changes:
- New Makefile target \`schema-dump\` runs mysqldump INSIDE the
  bm_mysql Docker container (no host mysqldump dependency to
  GENERATE the dump). Outputs api/database/schema/mysql-schema.sql.
- api/database/schema/.gitignore added: mysql-schema.sql is NOT
  committed by default. Laravel's auto-load on migrate:fresh
  shells out to the host's \`mysql\` CLI; on hosts without it,
  the presence of the dump file actively breaks migrate (exit 127).
  Treat the dump as opt-in per dev environment.
- CLAUDE.md "Schema dumps (opt-in fast path)" subsection added with
  the workflow: brew install mysql-client → migrate to head →
  make schema-dump → optionally commit.

phpstan-baseline.neon: removed a stale "unused use \$actor" entry
in FormSubmissionService whose underlying closure pint cleaned up
in commit 060d6f3 (Task 1).

Wall-time on this dev machine (no host mysql CLI): NO speedup,
backfill tests still ~6s per setUp. The dump file is ready for
environments that have mysql CLI. Documented as a deviation.

JSON canonicalization (commit 060d6f3) is the load-bearing
correctness fix from this branch; the schema-dump perf path is a
nice-to-have that activates per-environment.

Refs: WS-6 session 2.6 deviation #5 cleanup

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:07:15 +02:00

105 lines
4.7 KiB
Makefile

.PHONY: help services services-stop api app portal docs migrate fresh db-shell test test-db-create schema-dump
# Colors
GREEN := \033[0;32m
YELLOW := \033[0;33m
CYAN := \033[0;36m
NC := \033[0m
help:
@echo ""
@echo "$(GREEN)╔══════════════════════════════════════════════════════════════╗$(NC)"
@echo "$(GREEN)║ CREWLI - Development Commands ║$(NC)"
@echo "$(GREEN)╚══════════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo " $(YELLOW)Services (Docker):$(NC)"
@echo " make services Start MySQL, Redis, Mailpit"
@echo " make services-stop Stop all Docker services"
@echo ""
@echo " $(YELLOW)Development Servers:$(NC)"
@echo " make api Laravel API → http://localhost:8000"
@echo " make app Organizer SPA → http://localhost:5174"
@echo " make portal Portal SPA → http://localhost:5175"
@echo " make docs VitePress docs → http://localhost:5176"
@echo ""
@echo " $(YELLOW)Database:$(NC)"
@echo " make migrate Run migrations"
@echo " make fresh Fresh migrate + seed"
@echo " make db-shell Open MySQL shell"
@echo " make test-db-create Create crewli_test database (one-time)"
@echo " make schema-dump Regenerate MySQL schema dump (run after new migrations)"
@echo ""
@echo " $(YELLOW)Testing:$(NC)"
@echo " make test Run PHPUnit suite (creates crewli_test if needed)"
@echo ""
services:
@echo "$(GREEN)Starting Docker services...$(NC)"
@docker compose up -d
@echo ""
@echo "$(GREEN)Services:$(NC)"
@echo " $(CYAN)MySQL:$(NC) localhost:3306 (crewli / secret)"
@echo " $(CYAN)Redis:$(NC) localhost:6379"
@echo " $(CYAN)Mailpit:$(NC) http://localhost:8025"
@echo ""
@echo "$(YELLOW)Waiting for MySQL...$(NC)"
@until docker exec bm_mysql mysqladmin ping -h localhost -u root -proot --silent 2>/dev/null; do sleep 1; done
@echo "$(GREEN)✓ Ready!$(NC)"
services-stop:
@docker compose down
@echo "$(GREEN)✓ Services stopped$(NC)"
api:
@echo "$(GREEN)Starting Laravel API → http://localhost:8000$(NC)"
@cd api && php artisan serve
app:
@echo "$(GREEN)Starting Organizer SPA → http://localhost:5174$(NC)"
@cd apps/app && pnpm dev
portal:
@echo "$(GREEN)Starting Portal SPA → http://localhost:5175$(NC)"
@cd apps/portal && pnpm dev
docs:
@echo "$(GREEN)Starting VitePress docs → http://localhost:5176$(NC)"
@cd docs && npm run docs:dev
migrate:
@cd api && php artisan migrate
fresh:
@cd api && php artisan migrate:fresh --seed
db-shell:
@docker exec -it bm_mysql mysql -u crewli -psecret crewli
test-db-create:
@echo "$(GREEN)Creating crewli_test database...$(NC)"
@docker exec bm_mysql mysql -u root -proot -e "CREATE DATABASE IF NOT EXISTS crewli_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; GRANT ALL PRIVILEGES ON crewli_test.* TO 'crewli'@'%'; FLUSH PRIVILEGES;"
@echo "$(GREEN)✓ crewli_test ready$(NC)"
test: test-db-create
@cd api && php artisan test
# Regenerate api/database/schema/mysql-schema.sql from the current
# crewli_test schema. Runs mysqldump INSIDE the bm_mysql Docker
# container, so contributors don't need mysqldump on the host.
#
# Workflow: this target dumps WHATEVER state crewli_test is currently
# in. Run `make test-db-create` (creates DB), then put it at the desired
# state — typically by running the test suite, which migrates the test
# DB to head — then `make schema-dump`.
#
# See CLAUDE.md "Schema dumps" — commit the regenerated dump alongside
# any new migrations so CI / fast-path migrate:fresh stays in sync.
schema-dump:
@echo "$(GREEN)Regenerating api/database/schema/mysql-schema.sql from current crewli_test state...$(NC)"
@docker exec bm_mysql mysqldump --no-tablespaces --skip-add-locks --skip-comments --skip-set-charset --tz-utc -u root -proot crewli_test --routines --no-data 2>/dev/null > /tmp/crewli-schema-structure.sql
@docker exec bm_mysql mysqldump --no-tablespaces --skip-add-locks --skip-comments --skip-set-charset --tz-utc -u root -proot crewli_test migrations --no-create-info 2>/dev/null > /tmp/crewli-schema-migrations.sql
@cat /tmp/crewli-schema-structure.sql /tmp/crewli-schema-migrations.sql > api/database/schema/mysql-schema.sql
@rm /tmp/crewli-schema-structure.sql /tmp/crewli-schema-migrations.sql
@echo "$(GREEN)✓ api/database/schema/mysql-schema.sql updated$(NC)"
@echo "$(YELLOW)Note: Commit the updated schema dump alongside any new migrations.$(NC)"