Skip to content

feat: generate PostgreSQL DDL from canonical SQLite schemas - #168219

Merged
steipete merged 2 commits into
mainfrom
pgprep/postgres-schema
Oct 10, 2026
Merged

steipete merged 2 commits into
mainfrom
pgprep/postgres-schema

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

We need a reproducible account of which canonical SQLite schema objects PostgreSQL can represent before building a real PostgreSQL conformance lane. This is maintainer-requested PostgreSQL-readiness preparation.

User Impact

There is no runtime behavior change. SQLite remains the only supported runtime store, and the canonical SQLite files remain authoritative and unchanged. The generated DDL is a partial projection with explicit omissions, not a production migration; per-agent PostgreSQL topology remains undecided.

Why This Change Was Made

pnpm db:postgres:gen --out <dir> reads SQLite's own catalog and pragmas, translates an explicit portable expression subset, and writes deterministic DDL plus JSON/Markdown portability reports. Every canonical table, column, index, FK, CHECK, trigger, and virtual table is accounted for. Unsupported expressions and dependent objects are reported rather than silently discarded. --verify-psql compares the applied PostgreSQL catalog with the mapped SQLite facts.

The projection emits 174 ordinary tables, 1,712 ordinary columns, all 57 FKs, and 320 of 354 CHECKs. Six ordinary indexes, 34 CHECKs, 14 triggers, and two FTS5 virtual tables are reported as untranslatable; SQLite internal storage is inventoried separately. Identity allocation differences and excluded runtime/plugin/startup DDL are documented in the report. There are no runtime dependencies or runtime-code changes.

Evidence

  • Readability refactor: catalog() is now a 9-line coordinator with named helpers per object kind sharing one context. The entrypoint and catalog module total 900 lines, unchanged; the expression translator and test expectations are unchanged.

  • Output identity: generated before/after artifacts with the default prefix and with --schema-prefix pgtest; both diff -r comparisons returned exit 0 with no output, covering all four generated SQL/JSON/Markdown files per prefix. The accepted PostgreSQL 17.11 apply/catalog proof carries over and was not rerun.

  • Refactor validation: all 13 unchanged tests passed locally (186 ms execution / 4.15 s wall); focused lint/format and autoreview through P2 passed. pnpm check:changed --base f91baf27ccc296c90a8268a7bee234e4ffdfd3b3 -- scripts/generate-postgres-schema.mts scripts/lib/postgres-schema-catalog.mts passed on Testbox in 293.427 s. Its initial missing-baseline-object failure was resolved by fetching that exact published commit without changing the tested checkout.

  • PostgreSQL 17.11 on isolated Testbox: applied both generated files with psql -v ON_ERROR_STOP=1; verified all 129 state and 45 agent tables with zero unexplained differences in columns, types, nullability, identity, PKs, UNIQUE constraints, FKs/actions/deferrability, index counts, and CHECK counts.

  • Live generated-DDL probes passed for standalone-unique-index FK targets, nested unary operators, IS JSON, and exact GLOB translation.

  • pnpm test test/scripts/generate-postgres-schema.test.ts --maxWorkers=1: 13 passed. Local: 165 ms test execution / 2.46 s wall. Testbox: 133 ms test execution / 1.67 s wall. Canonical schemas are loaded only by the inventory/determinism test; regression cases use tiny distinct schemas. Hosted PR-CI test time is not yet available.

  • pnpm check:changed --base 03fab71bbad05c6d73c48c2dff83db07f18263ad -- scripts/generate-postgres-schema.mts test/scripts/generate-postgres-schema.test.ts package.json docs/reference/database-schemas/storage-changes.md: passed on Testbox. The final remote tests/check/cleanup bundle took 381.293 s.

  • Codex autoreview: scoped-clean through P2. git diff --check passed. A supplemental proof-script schema-name typo and three test-inventory parameter type errors were corrected before the final successful proof.

DDL/catalog proof does not establish runtime SQL, data-migration, transaction/concurrency, FTS-tokenizer, or vector-search conformance.

Landing validation

The coordinator-approved rebase produced head 7bed777cbbafdde4d0ef3cc9622923ff1c7736e0. Range-diff against the reviewed 0a5afe62677d stack marks both commits =; there was no conflict or patch change. git diff --check passed. The independent Codex review and original PostgreSQL apply/catalog proof carry over for those identical patches.

PR CI run 38072214963, attempt 2, remains failed because of three independently qualified baseline failures:

  • check-lint: managed-cleanup-handoff.mts:224 consistent-return error, also present in main CI run 38072014174. Main subsequently fixed the cleanup owner in 493a499b86e3.
  • checks-node-changed-extensions-bundle-28: three Agents API steering/retry assertions. An isolated checkout of main 0f08bb02f0b7 reproduced exactly the same three failures, with the other nine cases passing, on Testbox.
  • checks-node-changed-extensions-bundle-22-1: the memory-core shard stopped after five minutes without output. The same ten-file, two-worker main baseline independently stalled and repeatedly timed out in manager.borrowed-connection.test.ts hooks on Testbox. The lease was stopped after recording those failures; remaining baseline coverage is unrun.

The tested merge 54ce781fdd0c differs from its main parent only in this PR's five files. The relevant runtime, extension, test configuration, lockfile, and runner inputs are unchanged; these failing shards do not execute the new generator. These failures are submitted for native inherited-failure admission; CI remains failed.

The initial Android 16 KB job failed while resolving Kotlin 2.4.0. The exact Maven Central artifact later returned HTTP 200; one targeted job rerun passed. No code was changed or repushed for that infrastructure recovery. security-fast passed independently, and no jobs were cancelled in attempt 2.

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: XL labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR generates PostgreSQL DDL and explicit portability reports from the canonical SQLite schemas.

Example: A developer runs pnpm db:postgres:gen --out /tmp/openclaw-postgres.

  • Before: No command produces a PostgreSQL projection with an inventory of unsupported schema objects.
  • After: The command produces state.postgres.sql, agent.postgres.sql, portability-report.json, and portability-report.md.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused readiness tooling with meaningful generation-boundary tests and reported PostgreSQL execution; no definite introduced defect was identified.
Proof confidence 🐚 platinum hermit (4/6) Maintainer-authored tooling is outside the external-contributor proof gate; the body reports real CLI generation, PostgreSQL 17.11 application and catalog verification, and byte-identical output after refactoring, while linked terminal logs were inaccessible to this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Storage developers lack a reproducible inventory of which canonical SQLite schema objects PostgreSQL can represent.
Reason: The maintainer-directed change delivers the stated readiness artifacts with explicit limitations and no runtime cutover.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it delivers useful, maintainer-directed PostgreSQL readiness tooling, and review found no definite introduced correctness or security defect.

Priority: P3
Reviewed head: 7bed777cbbafdde4d0ef3cc9622923ff1c7736e0

Before merge

None.

Findings

None.

Agent review details

How this fits together

Offline developer tooling loads the canonical SQL files into in-memory SQLite, translates catalog facts into PostgreSQL artifacts, and optionally compares an applied PostgreSQL catalog.

flowchart LR
A[Canonical SQLite schemas] --> B[In-memory SQLite catalog]
B --> C[Portable expression translator]
C --> D[PostgreSQL DDL]
C --> E[Portability reports]
D --> F[Disposable PostgreSQL database]
F --> G[Catalog verification]
B --> G
Loading

Technical review

Best possible solution:

Land the bounded readiness generator through the native CI admission workflow while keeping runtime PostgreSQL support and data migration separate.

Do we have a high-confidence way to reproduce the issue?

This PR adds developer tooling rather than fixing a reported runtime defect; source inspection establishes its generation and verification paths.

Is this the best way to solve the issue?

SQLite catalog introspection, an explicit portable subset, and visible omissions fit the approved preparation scope without introducing a second runtime storage owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3e44be0fb8a6.

Provenance checked

  • Database backend preparation guidance keeps the original intent (ccc84ac: The cited documentation refactor moved the existing preparation guidance without changing its SQLite ownership contract.)
  • Canonical schema tooling keeps the original intent (6337d15: Existing tooling derives Kysely declarations from maintained SQLite schemas; the new command preserves those authoritative inputs and existing build behavior.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit da67a08 adds docs/reference/database-schemas/storage-changes.md:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da67a08b20eb; files: docs/reference/database-schemas/storage-changes.md)
  • Vincent Koc: Raw commit ccc84ac adds docs/reference/database-schemas/storage-changes.md:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ccc84ac86f2b; files: docs/reference/database-schemas/storage-changes.md)

PR surface

Tests +399, Docs +9, Config +1, Other +900. Total +1309 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 399 0 +399
Docs 1 9 0 +9
Config 1 1 0 +1
Generated 0 0 0 0
Other 2 900 0 +900
Total 5 1309 0 +1309

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is optional developer readiness tooling with no change to installed runtime behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T05:16:37.220Z sha f91baf2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T06:14:47.165Z sha 0a5afe6 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T17:13:28.948Z sha 0a5afe6 :: needs changes before merge. :: none
  • reviewed 2026-10-10T17:40:40.587Z sha 7bed777 :: needs changes before merge. :: none

Reviewed October 10, 2026, 2:48 PM ET / 18:48 UTC (Revision 5).

@steipete
steipete marked this pull request as ready for review October 10, 2026 17:08
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
Add deterministic readiness DDL, an explicit portability inventory, and PostgreSQL catalog verification. SQLite remains the only runtime store; canonical schemas and runtime code stay unchanged.
@steipete
steipete force-pushed the pgprep/postgres-schema branch from 0a5afe6 to 7bed777 Compare October 10, 2026 17:33
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete
steipete merged commit 4575155 into main Oct 10, 2026
397 of 407 checks passed
@steipete
steipete deleted the pgprep/postgres-schema branch October 10, 2026 18:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…#168219)

* feat: generate PostgreSQL DDL from canonical SQLite schemas

Add deterministic readiness DDL, an explicit portability inventory, and PostgreSQL catalog verification. SQLite remains the only runtime store; canonical schemas and runtime code stay unchanged.

* refactor: split PostgreSQL schema catalog by object kind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant