- Created expected JSON files for Go modules and workspaces. - Added go.mod and go.sum files for example projects. - Implemented private module structure with expected JSON output. - Introduced vendored dependencies with corresponding expected JSON. - Developed PostgresGraphJobStore for managing graph jobs. - Established SQL migration scripts for graph jobs schema. - Implemented GraphJobRepository for CRUD operations on graph jobs. - Created IGraphJobRepository interface for repository abstraction. - Added unit tests for GraphJobRepository to ensure functionality.
3.0 KiB
3.0 KiB
Scheduler Graph Jobs: PostgreSQL Migration Plan (2025-12-06)
Goals
- Replace Mongo-based GraphJobStore/PolicyRunService with PostgreSQL equivalents.
- Keep graph job determinism (status transitions, ordering) and tenant isolation.
- Provide schema, repository surface, and migration steps to unblock PG-T7.1.2a (Cleanup Wave A).
Proposed Schema (schema: scheduler)
-
graph_jobsid UUID PKtenant_id TEXT NOT NULLtype SMALLINT NOT NULL(0=build,1=overlay)status SMALLINT NOT NULL(queued, running, completed, failed, canceled)payload JSONB NOT NULL(serialized GraphBuildJob/GraphOverlayJob)created_at TIMESTAMPTZ NOT NULL DEFAULT now()updated_at TIMESTAMPTZ NOT NULL DEFAULT now()correlation_id TEXT NULL- Indexes:
idx_graph_jobs_tenant_status(tenant_id, status, created_at DESC),idx_graph_jobs_tenant_type_status(tenant_id, type, status, created_at DESC)
-
graph_job_eventsid BIGSERIAL PKjob_id UUID NOT NULL REFERENCES graph_jobs(id) ON DELETE CASCADEtenant_id TEXT NOT NULLstatus SMALLINT NOT NULLpayload JSONB NOT NULLcreated_at TIMESTAMPTZ NOT NULL DEFAULT now()- Index:
idx_graph_job_events_job(job_id, created_at DESC)
Repository Contracts
IGraphJobRepository(Postgres)ValueTask InsertAsync(GraphBuildJob job, CancellationToken ct)ValueTask InsertAsync(GraphOverlayJob job, CancellationToken ct)ValueTask<bool> TryReplaceAsync(GraphBuildJob job, GraphJobStatus expected, CancellationToken ct)ValueTask<bool> TryReplaceOverlayAsync(GraphOverlayJob job, GraphJobStatus expected, CancellationToken ct)ValueTask<GraphBuildJob?> GetBuildJobAsync(string tenantId, string id, CancellationToken ct)ValueTask<GraphOverlayJob?> GetOverlayJobAsync(string tenantId, string id, CancellationToken ct)ValueTask<IReadOnlyCollection<GraphBuildJob>> ListBuildJobsAsync(string tenantId, GraphJobStatus? status, int limit, CancellationToken ct)ValueTask<IReadOnlyCollection<GraphOverlayJob>> ListOverlayJobsAsync(string tenantId, GraphJobStatus? status, int limit, CancellationToken ct)ValueTask AppendEventAsync(GraphJobEvent evt, CancellationToken ct)
Migration
- New migration file:
014_graph_jobs.sqlundersrc/Scheduler/__Libraries/StellaOps.Scheduler.Storage.Postgres/Migrationswith the tables above.
DI Changes
- Replace
AddSchedulerMongoStorageandMongoGraphJobStorein WebService withAddSchedulerPostgresStorageand newPostgresGraphJobStoreimplementingIGraphJobStore. - Worker.Backfill: swap Mongo options to Postgres options; use Postgres repos from
StellaOps.Scheduler.Storage.Postgres.
Tests
- Add Postgres integration tests for
PostgresGraphJobRepositorycovering insert/list/update/expected-status checks and event log. - Update WebService/Worker tests to use Postgres fixtures; remove Mongo fixtures.
Rollback
- If regressions occur, revert migration + DI switch; Mongo storage remains in history.
Owners
- Schema/repo: Scheduler Guild
- DI/tests: Scheduler Guild