feat(rf-commissioning): add SQLite persistence module with repository architecture#232
Open
lisazacarias wants to merge 4 commits intoslaclab:mainfrom
Open
feat(rf-commissioning): add SQLite persistence module with repository architecture#232lisazacarias wants to merge 4 commits intoslaclab:mainfrom
lisazacarias wants to merge 4 commits intoslaclab:mainfrom
Conversation
… architecture - add facade for RF commissioning persistence operations - introduce persistence schema initialization, shared helpers, and conflict error handling - split data access into focused repositories (records, queries, notes, measurements, operators, cryomodules) - export persistence package entry points under - add comprehensive persistence test coverage for database, schema, helpers, errors, and repositories - add with project-specific architecture and workflow guidance
There was a problem hiding this comment.
Pull request overview
Adds a new SQLite-backed persistence layer for RF commissioning, using a repository architecture to separate schema/init, record CRUD, workflow/measurement queries, and note/operator/cryomodule persistence, along with a comprehensive new test suite and agent-facing project guidance.
Changes:
- Introduces RF commissioning SQLite schema initialization, shared helpers, and optimistic-locking conflict errors.
- Adds repository classes for records, queries, measurements, notes, operators, and cryomodules, wrapped by a
CommissioningDatabasefacade. - Adds extensive pytest coverage for schema, helpers, errors, and repository behaviors, plus
AGENTS.mdworkflow/architecture guidance.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/applications/rf_commissioning/models/persistence/test_database_schema.py | Verifies schema tables/columns/indexes and idempotent init. |
| tests/applications/rf_commissioning/models/persistence/test_database_helpers.py | Covers JSON parsing, note helpers, workflow state derivation, and serialization helpers. |
| tests/applications/rf_commissioning/models/persistence/test_database_errors.py | Validates optimistic-locking conflict exception context/message. |
| tests/applications/rf_commissioning/models/persistence/test_database.py | End-to-end DB behaviors: FK enforcement, conflicts, summaries, active record logic, stats, notes migration handling. |
| tests/applications/rf_commissioning/models/persistence/repositories/test_queries_cryomodules.py | Exercises query + cryomodule repository round-trips and conflict detection. |
| tests/applications/rf_commissioning/models/persistence/repositories/test_notes_measurements_operators.py | Covers operator normalization, versioned general notes, and measurement note editing flows. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/base.py | Adds shared repository serialization + optimistic-lock helpers. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/records.py | Implements record persistence and workflow-state loading. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/queries.py | Adds browsing/query APIs, summaries, active-record selection, deletion, workflow metadata reads. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/notes.py | Implements versioned general notes storage/editing. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/measurements.py | Implements measurement history persistence and note append/update utilities. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/operators.py | Adds operator list persistence with normalization/deduplication. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/cryomodules.py | Adds cryomodule checkout record persistence with optimistic locking. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/repositories/init.py | Exposes internal repository implementations. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/database_schema.py | Defines SQLite schema (records, workflow, measurements, operators, cryomodules) and indexes. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/database_helpers.py | Adds shared JSON/note/workflow-state helpers. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/database_errors.py | Adds RecordConflictError. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/database.py | Provides CommissioningDatabase facade wiring repositories + connection management. |
| src/sc_linac_physics/applications/rf_commissioning/models/persistence/init.py | Exports persistence entry points. |
| AGENTS.md | Adds repo architecture + workflow guidance for new agents/contributors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…b helpers Enforce retention-safe behavior by raising RecordDeletionDisabledError instead of deleting commissioning records from persistence APIs. Also tighten schema foreign key ON DELETE actions for normalized workflow tables and remove unused duplicate helper wrappers from CommissioningDatabase that duplicated BaseRepository logic. Update persistence exports and tests to cover deletion policy, error context, and expected schema FK delete actions.
Prevent AttributeError in record browsing when legacy/corrupted payloads are valid JSON but not objects. Only map piezo summary fields when decoded payload is a dict, and add parametrized regression tests for list/string/number JSON payloads.
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.
This PR refactors the RF commissioning database layer from a monolithic
CommissioningDatabaseclass into a repository-based architecture, improving separation of concerns and testability. It also adds anAGENTS.mddocumentation file to guide AI agents working with the codebase.Key Changes
Architecture Refactoring
Extracted 6 focused repositories from the original
CommissioningDatabaseclass:RecordRepository- Cavity commissioning session persistenceQueryRepository- Read/query operations and workflow metadataMeasurementRepository- Measurement history and notesNotesRepository- General record-level notesOperatorRepository- Approved operator name managementCryomoduleRepository- Cryomodule-level checkout recordsIntroduced
BaseRepositorywith shared database helpers (serialization, versioning, conflict detection)New helper modules:
database_errors.py-RecordConflictErrorexceptiondatabase_helpers.py- Pure functions for JSON parsing, note management, workflow state projectiondatabase_schema.py- Schema initialization logicDatabase Schema Evolution
commissioning_records:current_phase,overall_status,phase_status,phase_historycommissioning_runsandcommissioning_phase_instancestables at query timelinac,cryomodule,cavity_number)idx_active_record_per_cavity; active filtering now usescommissioning_runs.statusBehavior Changes
status = 'in_progress'get_record_by_cavity(..., active_only=True)now filters via join tocommissioning_runscurrent_phase,overall_status,phase_status) computed viabuild_workflow_state()helperDocumentation
AGENTS.mdwith:MACHINEconstruction)PVwrapper,PVBatch, structured logging, platform paths)Testing
Migration Notes
initialize()callCommissioningDatabasemaintains all public methods; internal implementation delegates to repositoriesFiles Changed
Motivation: This refactoring prepares the codebase for concurrent multi-user workflows by centralizing conflict detection logic and making workflow state computation explicit and testable.