Skip to content

programs(config): program versions, publish freeze, and export/import - #15

Merged
TusanHomichi merged 1 commit into
mainfrom
claude/status-check-wwwfh6
Aug 28, 2026
Merged

TusanHomichi merged 1 commit into
mainfrom
claude/status-check-wwwfh6

Conversation

@TusanHomichi

Copy link
Copy Markdown
Member

Primary Issue

Closes #14

Problem And Outcome

Milestone 2 needs the configuration schema that finalized records will pin to forever, with immutability the database enforces rather than trusts. After merge: a program version can be authored as a draft, validated, published (frozen at the database), exported as documented versioned JSON, and reproduced byte-for-byte on a clean installation.

Changes

  • Migration 0004_programs.sql: program, program_version, and eleven owned typed tables (phases, transitions, competencies, tasks, rating scales/anchors/modifiers, evaluation forms, form competency bindings, form narratives, standards citations). Every cross-reference is a composite foreign key including program_version_id, so domain invariant 5 — all referenced configuration belongs to the pinned version — is enforced by the schema. Publish freeze: once published_at is set, the version row and every owned table reject INSERT/UPDATE/DELETE via RAISE(ABORT) triggers, the same enforcement class as audit_event. Phases are optional (annual/in-service shape). audit_event gains nullable subject_kind/subject_id (deliberately no FK, so audit rows can never block lawful disposition of their subjects).
  • src/programs.rs: the typed content document (also the export payload), structural validation mirroring the database's case-insensitive uniqueness, and services — create program, create/replace/discard draft (wholesale replacement: single editor, honest last write per ADR 0007), publish with completeness refusals, deterministic content loading. All mutating services gate on manage_programs and append attributable audit events in the same transaction.
  • src/program_export.rs: versioned envelope (consolebook-program-version v1), deterministic byte-stable export, strict import (unknown fields refused) into a new program or the next version of an existing one.
  • docs/formats/program-version-export.md: the normative format spec, following the canonical-bytes principles in docs/records-integrity.md.
  • src/audit.rs: program lifecycle EventKinds and record_for_subject.
  • tests/programs.rs: 14 integration tests, including raw-SQL proof that all 12 tables reject mutation after publish, the phase-less publish, validation and capability refusals, audit attribution, and an export → fresh-installation import → export byte-identity round trip.

One note against #14's wording: cross-version reference rejection lands earlier than publish time — document validation refuses unknown references at every write, and the composite foreign keys make a dangling reference unrepresentable at the database. Publish-time validation covers completeness (a form with no competencies and no narratives refuses to publish).

Scope

Verification

  • Listed the exact verification commands run below
  • Added or updated tests when behavior changed
  • Added or updated an ADR when a durable decision changed (ADR 0007 merged in docs(decisions): adopt program-version configuration model #13; this slice implements it)
  • All fixtures and examples are invented; no real agency data
cargo fmt --check                                        # clean
cargo clippy --workspace --all-targets -- -D warnings    # clean (pedantic)
cargo test --workspace                                   # 52 passed, 0 failed

Web sources untouched; pr-gate builds web/ first as always.

Review And Merge Notes

  • Review focus: the freeze-trigger coverage in 0004_programs.sql (every owned table, INSERT included, both OLD and NEW parents on UPDATE), and whether the export format doc matches what the serializer actually emits.
  • User or operator impact: none visible yet — services only; the authoring interface arrives in the next slice. Existing installations migrate additively on next start.

Generated by Claude Code

Implement ADR 0007's first slice: migration 0004 with typed owned rows
and composite foreign keys enforcing domain invariant 5, publish-freeze
triggers in the audit_event enforcement class, phase-optional versions,
domain services for wholesale draft authoring and validated publishing,
attributable lifecycle audit events with domain subjects, and the
documented versioned JSON export/import with a byte-identical round
trip (docs/formats/program-version-export.md).

Refs #14
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.

Milestone 2 slice 1: program-version schema, domain services, and export/import

2 participants