Skip to content

chore: drop sqlx-crud; use mostro_core::db::Crud#789

Merged
grunch merged 1 commit into
mainfrom
chore/drop-sqlx-crud-use-mostro-core-crud
Jun 26, 2026
Merged

chore: drop sqlx-crud; use mostro_core::db::Crud#789
grunch merged 1 commit into
mainfrom
chore/drop-sqlx-crud-use-mostro-core-crud

Conversation

@arkanoider

@arkanoider arkanoider commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove the unmaintained sqlx-crud dependency from mostrod.
  • Bump mostro-core to 0.13.2 and route all persistence through mostro_core::db::Crud for Order, Dispute, and Bond.
  • Add hand-written impl Crud for Bond in src/app/bond/crud.rs (direct push_bind chains, QueryBuilder + RETURNING *).
  • Update bond and order docs to reflect the new persistence path.

Follow-up to mostro-core #154 / #155 (released as 0.13.2).

Test plan

  • cargo fmt --all
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test — 496 tests passed
  • cargo build

Bond regression coverage: bond/db, bond/flow, and bond/slash integration tests exercise create/update paths.

Reviewer notes

  • Bond CRUD follows the same style as mostro-core db/dispute.rs (compile-safe explicit binds, no string-dispatch match).
  • sqlx-data.json unchanged — no raw SQL query strings were modified.
  • Requires mostro-core >= 0.13.2 (published crate with db::Crud).

Summary by CodeRabbit

  • New Features

    • Added native persistence support for Bond records, including create, update, and lookup behavior.
    • Bond is now handled through a shared database CRUD interface.
  • Bug Fixes

    • Updated database integration across the app to use the new shared CRUD approach.
    • Improved consistency in persisted order and bond handling.
  • Documentation

    • Updated technical docs to reflect the current persistence model and Bond structure.
  • Chores

    • Upgraded a core dependency and removed an unused database helper dependency.

Replace the unmaintained sqlx-crud dependency with the in-tree Crud trait
from mostro-core 0.13.2. Add hand-written Bond persistence in bond/crud.rs
and switch all Order, Dispute, and Bond call sites to mostro_core::db::Crud.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 69ff7016-20d7-47eb-8e1d-886fa99ce4cd

📥 Commits

Reviewing files that changed from the base of the PR and between f64e93b and 5f84086.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • Cargo.toml
  • docs/ANTI_ABUSE_BOND.md
  • docs/ORDERS_AND_ACTIONS.md
  • src/app/add_invoice.rs
  • src/app/admin_cancel.rs
  • src/app/admin_settle.rs
  • src/app/admin_take_dispute.rs
  • src/app/bond/crud.rs
  • src/app/bond/db.rs
  • src/app/bond/flow.rs
  • src/app/bond/mod.rs
  • src/app/bond/model.rs
  • src/app/bond/payout.rs
  • src/app/bond/slash.rs
  • src/app/cancel.rs
  • src/app/dispute.rs
  • src/app/fiat_sent.rs
  • src/app/rate_user.rs
  • src/app/release.rs
  • src/app/take_sell.rs
  • src/app/trade_pubkey.rs
  • src/flow.rs
  • src/scheduler.rs
  • src/util.rs

Walkthrough

This PR removes sqlx-crud, switches shared database trait imports to mostro_core::db::Crud, adds src/app/bond/crud.rs, and updates related bond wiring and docs.

Changes

Mostro CRUD migration

Layer / File(s) Summary
Bond persistence contract and wiring
Cargo.toml, docs/ANTI_ABUSE_BOND.md, src/app/bond/db.rs, src/app/bond/flow.rs, src/app/bond/mod.rs, src/app/bond/model.rs, src/app/bond/payout.rs, src/app/bond/slash.rs
sqlx-crud is removed from the crate, Bond drops SqlxCrud derive wiring, and the bond helper modules switch to mostro_core::db::Crud.
Bond CRUD implementation
src/app/bond/crud.rs, src/app/bond/slash.rs
Bond gets ordered insert/update binding helpers and a Crud implementation for create, update, and by-id lookup; the slash test helpers call .create(...) through the new trait.
Shared Crud import migration
docs/ORDERS_AND_ACTIONS.md, src/app/add_invoice.rs, src/app/admin_*.rs, src/app/cancel.rs, src/app/dispute.rs, src/app/fiat_sent.rs, src/app/rate_user.rs, src/app/release.rs, src/app/take_sell.rs, src/app/trade_pubkey.rs, src/flow.rs, src/scheduler.rs, src/util.rs
Remaining app modules and docs switch their Crud imports from sqlx-crud to mostro_core::db::Crud.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • MostroP2P/mostro#412 — Touches src/app/trade_pubkey.rs, which this PR also updates to import Crud from mostro_core::db.
  • MostroP2P/mostro#419 — Overlaps the same trade_pubkey module that this PR adjusts for the Crud import change.
  • MostroP2P/mostro#744 — Extends src/app/bond/slash.rs, the same bond test helper file updated here for the new Crud trait import and .create(...) calls.

Suggested reviewers

  • Catrya
  • grunch

Poem

A bunny hopped through code so neat,
With Crud now home, the burrow beats.
Bonds and orders softly thrum,
No sqlx-crud crumbs left to come.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing sqlx-crud in favor of mostro_core::db::Crud.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/drop-sqlx-crud-use-mostro-core-crud

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ermeme ermeme 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.

Code Review Summary

Verdict: Approve

The sqlx-crud removal and the new mostro_core::db::Crud wiring look correct. I did not find any blocking correctness issues on the current head.

Notes

  • Bond CRUD column order matches the migration schema.
  • No remaining sqlx_crud references in the repo.

@mostronatorcoder

Copy link
Copy Markdown
Contributor

I did a strict pass on this PR and I do not currently see a correctness blocker.

What I specifically checked:

  • the migration from sqlx_crud::Crud imports to mostro_core::db::Crud
  • the handwritten impl Crud for Bond in src/app/bond/crud.rs
  • whether the new bond persistence path repeats the same kind of compile-time safety regression that was previously discussed on the mostro-core side
  • whether the bond table shape, the Bond row model, and the insert/update bind order still line up coherently

My read is that this follow-up is in a good state.

The important part is that Bond CRUD stays explicit and compile-safe: it uses direct handwritten bind chains for insert/update, and it does not reintroduce the string-dispatch + runtime-panic pattern that would have turned a mapping drift into a runtime failure.

I also ran the bond-focused test slices locally against this branch:

  • cargo test bond::db → 11 passed
  • cargo test bond::flow → 23 passed
  • cargo test bond::slash → 60 passed

So from my side, this looks like a solid daemon-side completion of the sqlx-crud removal, and I did not find a blocker in the persistence changes.

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strict review — drop sqlx-crud, route persistence through mostro_core::db::Crud

Verdict: APPROVE-WITH-NITS. No CRITICAL/HIGH issues. The risk is concentrated in the hand-written impl Crud for Bond and call-site parity; both check out. CI green is the merge gate (the branch can't be compiled locally because mostro-core 0.13.2 isn't in the registry cache), but the db::Crud contract the branch assumes was verified against the real mostro-core source.

Verified correct

  • impl Crud for Bond SQL is correct. INSERT column list vs push_bind order: no off-by-one, no missing column (31 insert binds + 30 update-SET + 1 WHERE = 62). FromRow decodes by column name, not ordinal, so RETURNING * and the payout_payment_hash column (added via ALTER TABLE, physically last) are safe.
  • No SQL injection. Every value goes through push_bind/push_bind_unseparated; the only formatted string interpolates ? placeholders, not values.
  • UPDATE parity. push_bond_update_set covers all 30 non-PK fields (incl. created_at) = the same full-row UPDATE sqlx-crud's derive produced. Confirmed Order::update / Dispute::update follow the identical QueryBuilder + push_*_update_set + RETURNING * full-row pattern in mostro-core, so no Order/Dispute update-semantics regression.
  • CAS transitions are NOT routed through Crud::update(). The critical state-machine writes (bond slash Locked->PendingPayout, payout hash-persist, range-close) remain raw UPDATE ... WHERE id=? AND state=?. No new TOCTOU window — Crud::update() is used only for auxiliary full-row updates where idempotency (not atomicity) is the needed property.
  • Clean dependency drop (sqlx-crud and its Inflector transitive dep both gone). Executor narrowing (E: Executor -> &Pool<Sqlite>) is lossless — no call site passed a &mut Transaction to the old Crud.
  • update() is exercised by the bond/db tests (create + update paths).

Nits worth fixing before merge (non-blocking)

  1. [MED] Misleading comment in src/app/bond/crud.rs. "Drift is caught by bond integration tests" overstates it — the tests verify value round-trip, not that push_bind[N] lines up with BOND_INSERT_COLUMNS[N]. A future field added with a misaligned bind would write to the wrong column and the tests would still pass (SQLite's loose typing hides it). Either add an assertion that bind count == column count, or drop the claim.
  2. [MED] Live duplicate in src/app/bond/db.rs:74-84. find_bond_by_id reimplements Bond::by_id byte-for-byte, so the trait's by_id is never used in production -> future divergence point. Delegate find_bond_by_id to Bond::by_id.
  3. [LOW] update() rewrites created_at every time (same as before). Consider omitting it from the SET with a comment, so an accidentally-mutated created_at can't corrupt the row.

Merge gate

CI must be green — it's the only thing this review can't substitute for. With CI green, this is mergeable.

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. No CRITICAL/HIGH issues — the impl Crud for Bond SQL is correct (bind/column order, decode-by-name RETURNING *, full-row UPDATE parity with the old sqlx-crud derive), critical CAS transitions stay as raw atomic UPDATE … WHERE state=? (no new TOCTOU), and the sqlx-crud drop is clean. The three nits in my detailed review (misleading "drift caught by tests" comment, find_bond_by_id duplicating Bond::by_id, created_at rewritten on update) are non-blocking and can be addressed in a follow-up. Merge once CI is green.

@grunch grunch merged commit 170f087 into main Jun 26, 2026
8 checks passed
@grunch grunch deleted the chore/drop-sqlx-crud-use-mostro-core-crud branch June 26, 2026 21:10
arkanoider added a commit that referenced this pull request Jun 27, 2026
Keep sqlx 0.9 / mostro-core 0.14 changes on top of merged #789.

Co-authored-by: Cursor <cursoragent@cursor.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.

2 participants