Persist LOADLINE workspaces in PostgreSQL (Neon) - #2
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) → resultfunction. Nothing underengine/,sim/,workload/orproviders/gained a dependency onpgx, HTTP, or the API layer — the new packages import from the engine, never the other way around.Backend
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 fordefinition,configuration,summary,plan,metrics,capacity,bottlenecks,failures,cost— all protojson of the API messages the engine produced.simulation_runs.workload_idisON DELETE SET NULLso run history outlives a deleted workload; containment cascades from project/architecture deliberately.internal/repositories): one per aggregate, parameterized SQL everywhere,WithTxfor atomic multi-writes (create architecture + first version; persist run + result). Version numbers are assigned inside the transaction that inserts them.WorkspaceService(proto/loadline/v1/workspace.proto) — project/architecture/version/workload CRUD plusExecuteSimulation, 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./healthzreports api/database/simulationEngine separately, graceful shutdown closes the pool.-require-databasemakes a missingDATABASE_URLfatal; by default the simulation API still runs without a database.Frontend
New
workspaceview wired toWorkspaceService: 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 vetclean;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 --noEmitclean,next buildsucceeds.Database-backed tests skip when neither
LOADLINE_TEST_DATABASE_URLnorDATABASE_URLis set, sogo 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).