Skip to content

Persist LOADLINE workspaces in PostgreSQL (Neon) - #2

Merged
kekubhai merged 1 commit into
mainfrom
feat/neon-workspace-persistence
Sep 30, 2026
Merged

kekubhai merged 1 commit into
mainfrom
feat/neon-workspace-persistence

Conversation

@kekubhai

Copy link
Copy Markdown
Owner

Persistence & Project Workspace milestone: projects → architectures → immutable versions → workloads → simulation runs → result summaries, stored in Neon PostgreSQL.

The simulation engine is untouched and stays a pure in-memory (architecture + workload + seed) → result function. Nothing under engine/, sim/, workload/ or providers/ gained a dependency on pgx, HTTP, or the API layer — the new packages import from the engine, never the other way around.

Backend

  • Schema (internal/db/migrations/001_initial_schema.sql, embedded + versioned, applied in one transaction under an advisory lock): relational columns for identity/relationship/timestamps/status/version/seed; JSONB for definition, configuration, summary, plan, metrics, capacity, bottlenecks, failures, cost — all protojson of the API messages the engine produced. simulation_runs.workload_id is ON DELETE SET NULL so run history outlives a deleted workload; containment cascades from project/architecture deliberately.
  • Repositories (internal/repositories): one per aggregate, parameterized SQL everywhere, WithTx for atomic multi-writes (create architecture + first version; persist run + result). Version numbers are assigned inside the transaction that inserts them.
  • API: new WorkspaceService (proto/loadline/v1/workspace.proto) — project/architecture/version/workload CRUD plus ExecuteSimulation, which loads a stored version + workload, runs the existing engine, and persists the run with its measured output. A failed run is stored with its reason and no fabricated metrics. Database errors are logged server-side and never returned to clients.
  • Server: migrates at boot, /healthz reports api/database/simulationEngine separately, graceful shutdown closes the pool. -require-database makes a missing DATABASE_URL fatal; by default the simulation API still runs without a database.

Frontend

New workspace view wired to WorkspaceService: project/architecture/version/workload selection, save current document as v1 / as a new immutable version, save workload, run & save, run history, open a stored result (metrics, per-component table, diagnosis, capacity, cost), load a run back into the editor for modify → re-run, and a stored-run comparison table reusing the existing comparison rows.

Tests

gofmt/go vet clean; go test ./... green including the database-backed suite against Neon (12 repository tests + 7 API tests: CRUD, v1/v2/v3 versioning, two rollback tests proving no partial writes, run/result round-trip, project-delete containment, deterministic re-runs, failed-run honesty). Web: 157 tests pass, tsc --noEmit clean, next build succeeds.

Database-backed tests skip when neither LOADLINE_TEST_DATABASE_URL nor DATABASE_URL is set, so go test ./... stays green on a machine without PostgreSQL.

Deferred

No Redis/queues/event-sourcing; comparison of persisted runs reuses the existing RunComparison + stored metrics rather than a new RPC; CI has no Postgres service yet, so those tests skip in CI; the users table is deferred (no identity abstraction exists).

The simulator stays a pure in-memory (architecture + workload + seed)
function; the documents around it become durable so a run can be saved,
re-opened, and re-run. Adds an embedded versioned schema (projects →
architectures → immutable versions → workloads → runs → results) with
JSONB for the structures the model is still evolving, a pgx repository
layer using parameterized SQL and transactions for multi-write
workflows, and a WorkspaceService that loads a stored version and
workload, runs the existing engine unchanged, and stores what it
measured. The web app gains a workspace view for the
save → run → modify → re-run → compare loop.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@kekubhai
kekubhai merged commit 05c729b into main Sep 30, 2026
4 checks passed
@kekubhai
kekubhai deleted the feat/neon-workspace-persistence branch September 30, 2026 17:11
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