feat: wire --json output to rich Pydantic models (STOPS-7492)#909
Merged
feat: wire --json output to rich Pydantic models (STOPS-7492)#909
Conversation
…mands (STOPS-7492) The 4 commands that already return structured dicts (check-connectivity, connections, status, precheck) now produce their full Pydantic model output when invoked with --json, instead of dumping raw dicts into the generic CommandResult.detail field. The conversion is centralized in _build_json_output via a command-name to builder-function mapping, so no command implementations were modified. Simple pass/fail commands continue to use the generic CommandResult. Made-with: Cursor
… to rich models Commands that previously returned None now return structured dicts which are converted into their full Pydantic models (SyncSequencesResult, SyncTablesResult, ValidateDataResult, CreateIndexesResult) when --json is used. sync-sequences: returns per-sequence detail (PK vs non-PK, method, source/destination values, stride application, skip reasons) sync-tables: returns per-table load/skip detail with duration_ms via new dump_and_load_tables_with_details utility validate-data: wraps each validation strategy to capture pass/fail create-indexes: returns per-index create/skip/fail detail with duration_ms via new create_target_indexes_with_details utility Non-JSON mode behavior is unchanged -- the dicts are ignored by run_with_configs when json_mode is False. Made-with: Cursor
|
Chorus detected one or more security issues with this pull request. See the Checks tab for more details. As a reminder, please follow the secure code review process as part of the Secure Coding Non-Negotiable requirement. |
New DiffSchemasResult model with per-DB DiffSchemaRow (match/mismatch/ skipped) and computed all_match field. On mismatch the unified diff text is now included in the returned dict (previously only logged). This completes the wiring of all 9 commands that have rich models. Made-with: Cursor
pg_isready defaults to the OS user (root) which doesn't exist as a Postgres role, causing intermittent healthcheck failures. Made-with: Cursor
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
All 9 commands with rich Pydantic model subclasses now produce their full structured output when invoked with
--json. No command is left using the genericCommandResult.detaildict when a dedicated model exists.Commands that already returned dicts (no implementation changes)
check-connectivityConnectivityCheckResultconnectionsConnectionsResultstatusStatusResultprecheckPrecheckResultdiff-schemasDiffSchemasResult(new model)Commands that previously returned None (implementation changes)
sync-sequencesSyncSequencesResult_sync_sequencesnow returns per-sequence detail: PK vs non-PK classification, sync method, source/destination values, stride application, skip reasonssync-tablesSyncTablesResultdump_and_load_tables_with_detailsutility tracks per-table load/skip/error withduration_msvalidate-dataValidateDataResultcreate-indexesCreateIndexesResultcreate_target_indexes_with_detailsutility tracks per-index create/skip/fail withduration_msNew model:
DiffSchemasResultdiff-schemasalready returned a dict but had no dedicated model. NewDiffSchemasResultwithDiffSchemaRowprovides per-DBresult(match/mismatch/skipped), the unified diff text on mismatch (previously only logged), and a computedall_matchfield.Remaining commands (no rich model -- by design)
Setup, teardown variants, analyze, load-constraints, login commands, etc. use the generic
CommandResultper the architectural rule: they're simple pass/fail without per-item structured output.Files changed
pgbelt/cmd/helpers.py_RICH_MODEL_BUILDERSmapping for all rich commandspgbelt/cmd/sync.pysync_sequences,sync_tables,validate_datanow return structured dictspgbelt/cmd/schema.pycreate_indexesnow returns structured dictpgbelt/util/dump.pydump_and_load_tables_with_details,create_target_indexes_with_details;validate_schema_dumpnow includes diff textpgbelt/models/schema.pyDiffSchemaRow,DiffSchemasResultpgbelt/models/__init__.pytests/pgbelt/cmd/test_json_flag.pytests/pgbelt/models/test_round_trips.pyDiffSchemasResultTest plan
pytest tests/ --ignore=tests/integration)--jsoncommands produce their rich model output