Skip to content

FIX [SCMS] Normalize env + DB handling, add safe auto-seed on dev boot#2

Merged
AdaInTheLab merged 1 commit into
mainfrom
scms/env-raccoon-taming
Dec 28, 2025
Merged

FIX [SCMS] Normalize env + DB handling, add safe auto-seed on dev boot#2
AdaInTheLab merged 1 commit into
mainfrom
scms/env-raccoon-taming

Conversation

@AdaInTheLab
Copy link
Copy Markdown
Owner

Normalize env + DB handling, add safe auto-seed on dev boot

This PR started as “why won’t the CLI behave?” and evolved into a full cleanup and hardening of environment handling, database safety, and dev startup ergonomics.

The result is a deterministic, safer backend with improved developer experience and zero risk of accidental DB misuse.


✨ What changed

Environment handling

  • Centralized environment loading in src/env.ts
  • Normalized NODE_ENV to development | test | production
  • Added lightweight runtime env validation (Zod-style, no dependency)
  • Fail-fast behavior for invalid or dangerous configurations

Database safety

  • Single source of truth for DB path resolution
  • Deterministic DB selection per environment:
    • developmentlab.dev.db
    • test:memory:
    • productionlab.db
  • Guardrails preventing test or dev from touching prod data
  • Auto-create DB directories when missing (SQLite-safe)

Seeding improvements

  • Updated seed script to align with current schema:
    • created_at / updated_at
    • coherence_score
    • optional content fields
  • Idempotent inserts
  • Refuses to run in test
  • Refuses to run in production unless explicitly allowed

Auto-seed on dev boot

  • On app startup:
    • Runs only in development
    • Runs only if DB is empty
    • Executes after schema bootstrap
  • Removes manual setup friction without risking prod or test environments

Dev ergonomics

  • Clean, predictable dev startup flow
  • Instant health check visibility on boot
  • Reduced “it works on my machine” edge cases
  • IDE/browser tooling clarified to avoid cache/session bleed

🛡️ Why this matters

  • Eliminates ENV ambiguity (local, dev, etc.)
  • Prevents accidental DB spills across environments
  • Aligns schema ↔ seed ↔ models ↔ API
  • Makes development startup reliable, repeatable, and fast
  • Establishes a safer foundation for future features

🦝 Notes

This work was born out of debugging CLI and IDE behavior, but resulted in meaningful infrastructure improvements and clearer system boundaries. Consider this a small internal reset that pays dividends going forward.

…to-seed dev 🌱🦝

- Normalize NODE_ENV to development/test/production with runtime validation
- Centralize dotenv loading and env parsing
- Make DB resolution deterministic and safe across envs
- Prevent test/prod DB spills with explicit guardrails
- Align seed script with current schema (timestamps, coherence_score, content fields)
- Add auto-seeding on first dev boot when DB is empty
- Improve dev ergonomics and startup reliability

co-authored-by: Lyric <lyric@thehumanpatternlab.com>
co-authored-by: Carmel <carmel@thehumanpatternlab.com>
@AdaInTheLab AdaInTheLab merged commit cda16fe into main Dec 28, 2025
1 check passed
@AdaInTheLab AdaInTheLab deleted the scms/env-raccoon-taming branch December 28, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant