Skip to content

feat(diff): structural schema diff + migration SQL - #465

Merged
seonghobae merged 7 commits into
mainfrom
feat/diff-on-main
Jul 10, 2026
Merged

feat(diff): structural schema diff + migration SQL#465
seonghobae merged 7 commits into
mainfrom
feat/diff-on-main

Conversation

@seonghobae

@seonghobae seonghobae commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Independent PR against main (split out of #440). Now also contains the merged stack: #468 (migration-safety risk classification) and #484 (down-migration direction=down).

  • Name-keyed structural diff (diff/schema_diff.py, oid-independent): GET /diff?against=
  • Migration SQL (ddl/migration.py): GET /migration.sql?against=&dialect=&direction=up|down — up and rollback are exact mirrors
  • Migration safety: GET /migration-safety?against= — safe/warning/destructive per change, has_destructive/has_blocking
    IDOR-safe. backend +23 tests; mypy clean.

🤖 Generated with Claude Code

@opencode-agent

opencode-agent Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: dc44afaefd9a1cfd32e3d6d82361ed0c489676f4
  • Workflow run: 29098613855
  • Workflow attempt: 1
  • Gate result: APPROVE (approval step)

Pull request overview

OpenCode reviewed the current-head bounded evidence and found no blocking issues.

Findings

No blocking findings.

Summary

Approval sufficiency: bounded evidence supplied affirmative approval evidence for changed files, coverage/docstring posture, risk surfaces, and current-head verification; approval is not based merely on the absence of known blockers.
Verification posture: CodeGraph evidence was initialized and bounded current-head evidence reviewed for changed-file evidence including backend/app/api/snapshots.py, backend/app/ddl/migration.py, backend/app/ddl/migration_safety.py, backend/app/diff/init.py, backend/app/diff/schema_diff.py, and 7 more.
Linter/static: workflow/static review evidence is bounded by the current-head GitHub Checks gate and changed-file evidence.
TDD/regression: coverage execution evidence and focused changed hunks were reviewed from bounded-review-evidence.md.
Coverage: coverage execution evidence reports supported repository test suites passed.
Docstring coverage: coverage execution evidence reports configured repository docstring gates passed or docstring coverage was advisory.
DAG: CodeGraph/source-backed behavior map connects backend/app/api/snapshots.py to the affected review, runtime, or workflow path and required checks.
PoC/execution: coverage-evidence job executed on the current head and reported PASS.
DDD/domain: workflow and repository-governance invariants were reviewed against changed files in bounded evidence.
CDD/context: CodeGraph evidence, changed-file history, and focused hunks were reviewed from bounded-review-evidence.md.
Similar issues: changed-file history evidence was reviewed for comparable local precedents.
Claim/concept check: bounded evidence, repository source, current-head workflow evidence, and, where numeric, scientific, statistical, or literature-backed claims are affected, original-paper/formula evidence and parameter-recovery expectations were used for claims.
Standards search: standards and external-source checks are delegated to configured OpenCode web_search/Context7/DeepWiki sources when applicable; no evidence-backed standards blocker is present in bounded evidence.
Compatibility/convention: changed workflow/script conventions, object naming, and reserved-word safety for schema/API/config/code surfaces were checked in bounded evidence.
Breaking-change/backcompat: deployment evidence and changed-file history were checked for backward-compatibility risk.
Performance: changed surfaces were checked for performance risk in bounded evidence.
Developer experience: changed automation, review, test, setup, and maintenance surfaces were checked for helpful or obstructive DX impact in bounded evidence.
User experience: connected user, operator, API, CLI, documentation, review-comment, status-check, rendering, and workflow-reader behavior was checked for contradictions against code, docs, and tests in bounded evidence.
Visual/DOM: Playwright visual, DOM locator, ARIA snapshot, console, and responsive evidence were checked when a web UI surface was present; for non-web surfaces, API/CLI/log/docs/workflow interaction evidence was reviewed instead.
Accessibility/i18n: accessibility, localization, and human-readable text surfaces were checked where UI, CLI, API message, docs, logs, or review text changed.
Supply-chain/license: dependency, package, model, container, and external-tool changes were checked in bounded evidence.
Packaging: package, build, test, lint, and security contracts were checked in bounded evidence.
Security/privacy: workflow-token, review-gate, and repository-automation security/privacy boundaries were checked in bounded evidence.

  • Result: APPROVE
  • Reason: The PR introduces structural schema diff and migration SQL functionality with comprehensive tests and coverage.
  • Head SHA: dc44afaefd9a1cfd32e3d6d82361ed0c489676f4
  • Workflow run: 29098613855
  • Workflow attempt: 1

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Backend (12 files)"]
  S1 --> I1["API and service runtime"]
  I1 --> R1["Review risk: Backend (12 files)"]
  R1 --> V1["backend tests"]
Loading

seonghobae and others added 4 commits July 8, 2026 11:07
Split out of the adhesive-piper foundation as an independent PR against main. Name-keyed diff (oid-independent) via diff/schema_diff.py; GET /api/snapshots/{uuid}/diff?against=... (SnapshotDiffOut, IDOR-safe). Migration SQL via ddl/migration.py reusing the diff indexer + ddl/export type-mapping; GET /api/snapshots/{uuid}/migration.sql?against=...&dialect=... emits CREATE/ALTER/DROP + FK, destructive/PK as review comments. +16 tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
Stacked on #465 (diff) since it reuses diff/schema_diff._index_snapshot; auto-retargets to main when #465 merges. Labels every change safe/warning/destructive (drop=data loss; type change/SET NOT NULL/new FK=lock or fail; add nullable/drop FK=safe), summary has_destructive/has_blocking, dangerous-first. GET /api/snapshots/{uuid}/migration-safety?against=... IDOR-safe. +5 tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
Stacked on #465; auto-retargets to main when it merges. GET /migration.sql?against=...&direction=down emits the rollback (target->base) using the SAME generator with endpoints swapped, so up and down are always exact mirrors — CREATE in up is DROP in down, ADD COLUMN in up is DROP COLUMN in down. Completes up+down change management. +2 tests (mirror + identity).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
The generator (correctly) emits DROP TABLE IF EXISTS; the assertion missed IF EXISTS. Test-only fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
@seonghobae
seonghobae force-pushed the feat/diff-on-main branch from 3e01d17 to d4ef5c7 Compare July 8, 2026 02:11
@seonghobae

Copy link
Copy Markdown
Collaborator Author

🔀 Rebased onto origin/main (now at 174b0f4) to clear the merge conflict — branch went from CONFLICTING → MERGEABLE.

Conflicts (both in the import/declaration blocks, resolved by keeping BOTH sides):

  • backend/app/schemas.py — main added WideTablesOut; this PR adds SnapshotDiffOut / MigrationSafetyOut. Kept all three.
  • backend/app/api/snapshots.py — merged the from app.schemas import (...) list and the module imports so main's NamingLintOut/lint_naming/detect_wide_tables and this PR's diff_snapshots/snapshot_diff_to_migration_sql/analyze_migration_safety all coexist.

The IDOR-safe authorization (independent _get_authorized_snapshot on base + target, uniform not_found to prevent existence enumeration) is fully preserved. No security remediation dropped; no changes to main's naming-lint/wide-table features.

Verification: net diff vs main is exactly the PR's feature set (only backend/ diff/migration files, +1367). Focused suites green — test_schema_diff, test_migration, test_migration_safety, test_down_migration, test_api_snapshot_diff (23 passed) plus main's test_naming_lint (5 passed). All changed Python compiles.

🤖 Rebase performed by Claude Opus 4.8.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

OpenCode reviewed the current-head bounded evidence and found no blocking issues.

Findings

No blocking findings.

Summary

Approval sufficiency: bounded evidence supplied affirmative approval evidence for changed files, coverage/docstring posture, risk surfaces, and current-head verification; approval is not based merely on the absence of known blockers.
Verification posture: CodeGraph evidence was initialized and bounded current-head evidence reviewed for changed-file evidence including backend/app/api/snapshots.py, backend/app/ddl/migration.py, backend/app/ddl/migration_safety.py, backend/app/diff/init.py, backend/app/diff/schema_diff.py, and 7 more.
Linter/static: workflow/static review evidence is bounded by the current-head GitHub Checks gate and changed-file evidence.
TDD/regression: coverage execution evidence and focused changed hunks were reviewed from bounded-review-evidence.md.
Coverage: coverage execution evidence reports supported repository test suites passed.
Docstring coverage: coverage execution evidence reports configured repository docstring gates passed or docstring coverage was advisory.
DAG: CodeGraph/source-backed behavior map connects backend/app/api/snapshots.py to the affected review, runtime, or workflow path and required checks.
PoC/execution: coverage-evidence job executed on the current head and reported PASS.
DDD/domain: workflow and repository-governance invariants were reviewed against changed files in bounded evidence.
CDD/context: CodeGraph evidence, changed-file history, and focused hunks were reviewed from bounded-review-evidence.md.
Similar issues: changed-file history evidence was reviewed for comparable local precedents.
Claim/concept check: bounded evidence, repository source, current-head workflow evidence, and, where numeric, scientific, statistical, or literature-backed claims are affected, original-paper/formula evidence and parameter-recovery expectations were used for claims.
Standards search: standards and external-source checks are delegated to configured OpenCode web_search/Context7/DeepWiki sources when applicable; no evidence-backed standards blocker is present in bounded evidence.
Compatibility/convention: changed workflow/script conventions, object naming, and reserved-word safety for schema/API/config/code surfaces were checked in bounded evidence.
Breaking-change/backcompat: deployment evidence and changed-file history were checked for backward-compatibility risk.
Performance: changed surfaces were checked for performance risk in bounded evidence.
Developer experience: changed automation, review, test, setup, and maintenance surfaces were checked for helpful or obstructive DX impact in bounded evidence.
User experience: connected user, operator, API, CLI, documentation, review-comment, status-check, rendering, and workflow-reader behavior was checked for contradictions against code, docs, and tests in bounded evidence.
Visual/DOM: Playwright visual, DOM locator, ARIA snapshot, console, and responsive evidence were checked when a web UI surface was present; for non-web surfaces, API/CLI/log/docs/workflow interaction evidence was reviewed instead.
Accessibility/i18n: accessibility, localization, and human-readable text surfaces were checked where UI, CLI, API message, docs, logs, or review text changed.
Supply-chain/license: dependency, package, model, container, and external-tool changes were checked in bounded evidence.
Packaging: package, build, test, lint, and security contracts were checked in bounded evidence.
Security/privacy: workflow-token, review-gate, and repository-automation security/privacy boundaries were checked in bounded evidence.

  • Result: APPROVE
  • Reason: The PR introduces structural schema diff and migration SQL functionality with comprehensive tests and coverage.
  • Head SHA: dc44afaefd9a1cfd32e3d6d82361ed0c489676f4
  • Workflow run: 29098613855
  • Workflow attempt: 1

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Backend (12 files)"]
  S1 --> I1["API and service runtime"]
  I1 --> R1["Review risk: Backend (12 files)"]
  R1 --> V1["backend tests"]
Loading

@seonghobae
seonghobae merged commit 6308628 into main Jul 10, 2026
28 checks passed
@seonghobae
seonghobae deleted the feat/diff-on-main branch July 10, 2026 18:41
seonghobae added a commit that referenced this pull request Jul 11, 2026
* feat(ci): schema-drift deploy gate (recipe + script)

P0 roadmap item. docs/ci-drift-check.md documents gating deploys on 'schema matches the approved baseline' via GET /diff?against= (has_changes) with exit-code semantics, plus a ready-made scripts/ci/check_schema_drift.sh (0 = no drift, 1 = drift + prints summary & reconciling migration.sql, 2 = missing/unauthorized) and a GitHub Actions example. Script syntax + JSON extraction paths verified. Depends only on the diff/migration endpoints (#465).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd

* fix(ci): make schema drift gate failures explicit

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
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.

1 participant