Move all database objects into a configurable dedicated schema #13

Merged
hannah-vernon merged 1 commit from fix/dedicated-schema into dev 2026-08-25 17:53:30 -05:00

What does this PR do?

Moves every Viegard database object out of the PostgreSQL default public schema and into a dedicated schema, configurable per deployment via Viegard__Database__Schema in docker-compose.yml (default: viegard).

Design: the schema is applied through the connection search_path rather than HasDefaultSchema, so the EF model, the generated migration, and the raw queue SQL all stay schema-agnostic (the regenerated migration is byte-identical to the previous one). The EF migrations-history table is explicitly pinned to the configured schema via a new shared ViegardDbContextConfiguration helper used by the runtime hosts, the design-time factory, and the integration tests. The pipeline creates the schema on startup if missing.

Because the schema name participates in CREATE SCHEMA DDL, it is validated fail-closed: ^[a-z][a-z0-9_]*$, max 63 characters.

Docs: compose example documents the new setting for both services; docs/deployment.md gains a Database schema section including the reset path for deployments that already migrated into public (with an optional row-export step first). D-0024 amendment recorded; AGENT-README current state refreshed.

How was this tested?

  • dotnet build - 0 errors, 0 warnings
  • dotnet test - 263 passed, 7 skipped (live-PostgreSQL integration tests; local WSL Docker unavailable)
  • Manually tested on the Debian VM post-merge (existing deployment reset per the new runbook section)

Note: live verification against PostgreSQL will happen on the deployment VM after merge, following the runbook's upgrade steps.

Checklist

  • I have read the Contributing Guide
  • Changes are focused - one logical change per PR
  • Documentation updated (README.md / DECISIONS.md / TODO.md / AGENT-README.md, if applicable)
  • New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (none added)
  • No secrets, credentials, or real infrastructure identifiers in the diff
  • No commented-out code or debug leftovers
## What does this PR do? Moves every Viegard database object out of the PostgreSQL default `public` schema and into a dedicated schema, configurable per deployment via `Viegard__Database__Schema` in docker-compose.yml (default: `viegard`). Design: the schema is applied through the connection `search_path` rather than `HasDefaultSchema`, so the EF model, the generated migration, and the raw queue SQL all stay schema-agnostic (the regenerated migration is byte-identical to the previous one). The EF migrations-history table is explicitly pinned to the configured schema via a new shared `ViegardDbContextConfiguration` helper used by the runtime hosts, the design-time factory, and the integration tests. The pipeline creates the schema on startup if missing. Because the schema name participates in `CREATE SCHEMA` DDL, it is validated fail-closed: `^[a-z][a-z0-9_]*$`, max 63 characters. Docs: compose example documents the new setting for both services; `docs/deployment.md` gains a Database schema section including the reset path for deployments that already migrated into `public` (with an optional row-export step first). D-0024 amendment recorded; AGENT-README current state refreshed. ## How was this tested? - [x] `dotnet build` - 0 errors, 0 warnings - [x] `dotnet test` - 263 passed, 7 skipped (live-PostgreSQL integration tests; local WSL Docker unavailable) - [ ] Manually tested on the Debian VM post-merge (existing deployment reset per the new runbook section) Note: live verification against PostgreSQL will happen on the deployment VM after merge, following the runbook's upgrade steps. ## Checklist - [x] I have read the [Contributing Guide](../CONTRIBUTING.md) - [x] Changes are focused - one logical change per PR - [x] Documentation updated (README.md / DECISIONS.md / TODO.md / AGENT-README.md, if applicable) - [x] New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (none added) - [x] No secrets, credentials, or real infrastructure identifiers in the diff - [x] No commented-out code or debug leftovers
Viegard previously created every table in the PostgreSQL default public
schema.  All objects now live in a dedicated schema, configurable per
deployment via Viegard__Database__Schema (default: viegard).

- DatabaseOptions gains Schema with fail-closed validation
  (^[a-z][a-z0-9_]*$, max 63 chars) since the name participates in DDL
- Schema applied via connection search_path; model, migrations, and
  queue SQL stay schema-agnostic
- ViegardDbContextConfiguration centralizes Npgsql setup and pins the
  EF migrations-history table to the configured schema
- MigrateViegardDatabaseAsync creates the schema if missing before
  applying migrations
- Migration regenerated schema-agnostic
- Integration tests run in the viegard schema (SearchPath on the test
  data source, schema created before migrate)
- Compose example documents Viegard__Database__Schema for both
  services; deployment runbook covers the setting and the reset path
  for deployments that already migrated into public
- D-0024 amendment recorded; AGENT-README current state refreshed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hannah-vernon/viegard-sentinel!13
No description provided.