* chore(db): empty the two byte-identical duplicate migrations instead of skipping one
004_ai_inventory_system.sql and 005_messaging_system.sql were 402- and
295-line copies of 004b and 005c (the originals were renamed with a suffix
in 21a6b2477, then re-added unsuffixed in e920eb231). Both names are
recorded in production's schema_migrations — backfilled by
083_backfill_schema_migrations.sql, which lists all four filenames — so
neither file can be deleted without a restore-from-backup audit reading it
as a vanished migration.
The bodies are gone; each file keeps a comment with the history. Applied
as a no-op, so the MIGRATION_SUPERSEDED skip list in migration-order.sh
(which existed only because 005's unguarded CREATE TRIGGERs aborted a
second application) is no longer needed and is removed from all three
runners' comments. The deploy script was not run; evidence is read from
the migration files and the runner sources only.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
* chore(scripts): delete the Strapi-era blog and docker setup scripts
scripts/setup-blog.sh and scripts/start-blog.sh were byte-identical copies
of tools/development/setup-blog.sh and start-blog.sh; all four drove a
Strapi blog that no longer exists (the blog is DB-backed, no compose file
has a Strapi service, and .gitignore's /strapi entry pointed at nothing).
tools/development/docker-setup.sh was the wrapper around the same stack.
Nothing in package.json, CI or the docs invoked any of them; the one
prose mention in docs/guides/system-integration.md now says so.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
* fix(i18n): baseline states each missing key once, not once per locale
scripts/baselines/i18n-missing.json listed the same ~90 keys under each of
six locales — six near-identical blocks that jscpd flagged as the repo's
largest clone group. The generator now writes one entry per key naming
the locales it is missing from; the audit converts back to the per-locale
view it compares against, so its regression semantics are unchanged
(0 new, 0 fixed on regeneration).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
* refactor(security): one rate limiter over limitkit, lockout kept apart
Two hand-rolled limiters served ~20 routes each: an lru-cache counter in
lib/security/rate-limit.ts and a bare-Map window in lib/auth/rate-limiter.ts.
Both are replaced by the fleet's limitkit (SHARED.md); evig keeps only its
limit VALUES and the call shapes routes were written against, so no route
changed beyond its import. The auth file's account-lockout half — a
per-account, DB-backed state, not rate limiting — lives on as
lib/auth/lockout.ts. AUTH_CONFIG.rateLimit moves next to the other limits
as AUTH_RATE_LIMITS; lru-cache is dropped.
Behaviour that changed underneath, deliberately: sliding windows instead
of a TTL that restarted on every hit, refusals no longer count (a hammered
key recovers when the attacker stops), the client IP is the last
X-Forwarded-For hop (the one Caddy wrote), and the store is bounded. The
login limit was "5 per 15 min then a 30-min block"; limitkit does not
model a punitive block, so it is 5 per sliding 30 minutes — the same
steady-state admission.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
* chore(lint): no-console in src/, and a useMounted hook for the SSR mount flag
App code logs through src/lib/logger.ts, the one console sink. ESLint now
enforces no-console (warn/error allowed) across src/, with the logger and
tests carved out; scripts/ are CLIs whose stdout is their output and stay
uncovered.
Four components each carried a useState(false)+useEffect(setMounted(true))
pair with a react-hooks/set-state-in-effect exception. They share one
useMounted() built on useSyncExternalStore, which needs no effect and no
exception.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KAn51JHFcTrPeCjZDGXM8
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Migrations were enumerated three different ways. run-migration.sh sorted
-V with no skip list, apply-migrations-ci.sh sorted -V WITH one, and the
production deploy used a bare glob — lexicographic, which orders the
005* duplicates the opposite way. So the order production would use in a
disaster-recovery rebuild was the one order CI never replayed, and a
from-scratch local DB died on a duplicate CI had been skipping for
months. scripts/db/migration-order.sh is now the only enumeration.
The deploy also read schema_migrations with '|| true'. An empty answer
does not mean 'nothing applied', it means 'could not look' — and the
loop treats every unlisted file as pending, so one ssh blip would have
re-applied ~150 migrations to the live database. It now fails closed.
Also:
- deploy-selfhost.yml re-inlined four checks instead of calling verify,
making the DEPLOY gate weaker than the MERGE gate (no card-shell
ratchet, i18n subset instead of the full suite). Calls verify verbatim.
- .gitignore had a blanket *.sh + hand-kept negations, so every new
script under scripts/ was invisible to git — it commits clean, then CI
fails on a file that exists on one laptop. Anchored to the repo root.
- 5 dev-only packages sat in dependencies, where dependency-audit.sh
(npm audit --omit=dev) reports an ESLint advisory as a runtime
critical. Moved to devDependencies.
- dependabot: groups for the next / next-auth / tailwind / eslint / jest
lockstep families, and @types/node major pinned to the runtime major
(Node 20) — PR #356 was closed for exactly that.
- Untracked 2.7 MB of committed Jest output and a .bak dropping.
Verified: from-zero CI replay green (133 applied), local runner green
from a fresh DB (149 applied — it could not complete at all before),
lint 0 errors, typecheck clean, 7798 tests.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Retire cloud DB and AUTH_DB_* split in code, env examples, and docs so
local dev uses Docker Postgres and prod ops use the Hetzner tunnel pattern.
Add Playwright user-admin-flows spec with locale-aware auth helper.
Co-authored-by: Cursor <cursoragent@cursor.com>
Before this, scripts/db/run-migration.sh ran every .sql file in
scripts/db/migrations/ on every invocation, with no record of what
had been applied. Most files are guarded with IF NOT EXISTS / IF
EXISTS, but a handful are not — most notably 061_unify_technician_
profiles.sql which does a raw INSERT of helper-profile rows into
repairer_profiles. Re-running against an already-populated database
crashes on duplicate-id INSERT and leaves the migration half-applied.
Migration 075:
- Creates `schema_migrations(filename PRIMARY KEY, applied_at)`.
- Bootstraps it with the 74 historical filenames (the production DB
already has all of these applied — the bootstrap is pure record-
keeping, no schema effect). Explicit list rather than a synthesized
one so anyone reviewing this file can verify exactly what's
considered already-applied.
- ON CONFLICT DO NOTHING so the migration itself is idempotent.
scripts/db/run-migration.sh:
- `set -euo pipefail` instead of bare `set -e` — catches undefined
variable bugs and pipefail propagation.
- Defensive bootstrap: CREATE TABLE IF NOT EXISTS schema_migrations
before reading from it, so even a pre-075 DB doesn't error out
when the runner first looks for applied filenames.
- Reads the applied filenames into a temp file at startup; each
candidate is checked via O(1) `grep -Fxq` lookup.
- Sort order changes from plain `sort` to `sort -V` (version sort).
Pre-075 hyphenated/underscored names happen to sort identically
under both, so no historical ordering changes; new migrations
numbered ≥ 100 will sort correctly going forward.
- Each migration file runs inside `BEGIN; \i file; INSERT INTO
schema_migrations ...; COMMIT;` so a partial failure rolls back
and the file is NOT marked applied.
- End-of-run summary reports applied vs skipped counts.
Production note: prod (Neon) doesn't go through this script — apply
075 manually against $DATABASE_URL via psql. After that one-time
bootstrap, future migrations can be applied with the same `\i file;
INSERT INTO schema_migrations ...` pattern against Neon, mirroring
what the runner does for dev. The schema_migrations table exists in
both environments and serves as the source of truth for "what's
been applied".
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Added curl to Dockerfile for health check improvements.
- Modified npm install commands to build TypeScript and prune unnecessary packages.
- Updated health check command to use curl for better reliability.
- Adjusted TypeScript definitions for user-related functions to return more specific response types.
- Changed user role options from 'viewer' to 'user' in multiple places for consistency.
- Updated package.json dependencies, including downgrading jsonwebtoken types and switching bcrypt to bcryptjs for compatibility.
- Added new environment variables for email configuration in the env.template file.
- Cleaned up various files by removing unnecessary newlines and ensuring consistent formatting.