Conversation
WalkthroughAdds optional sqlx-backed SQLite support: new Cargo feature and dependency, a conditional Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Init as init_db()
participant DB as SQLite DB
participant Meta as _meta Table
participant Mig as Migration
App->>Init: call init_db(name, ddls, migrations)
Init->>DB: query sqlite_master for `_meta`
DB-->>Init: `_meta` exists? / not exists
alt `_meta` missing
Init->>DB: CREATE TABLE _meta(...)
Init->>DB: execute initial DDLs
Init->>Meta: INSERT version = 0
end
Init->>Meta: SELECT version FROM _meta
Meta-->>Init: current_version
loop for each migration where version > current_version
Init->>DB: BEGIN TRANSACTION
Init->>Mig: execute migration query
Mig->>DB: apply changes
Init->>Meta: UPDATE version
Init->>DB: COMMIT
end
alt migrations applied and growth suspected
Init->>DB: PRAGMA wal_checkpoint(TRUNCATE)
Init->>DB: VACUUM
end
Init-->>App: return Result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
6fdfd47 to
48469ff
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/utils/sqlite/tests.rs`:
- Around line 215-255: Replace the brittle SQL string parsing inside
TableData::try_from (taking TableDataRow and db: &SqlitePool) with a PRAGMA
table_info query to fetch column names reliably: run "PRAGMA table_info({name})"
via sqlx to collect the "name" field for each column into cols, and change the
row-fetching query to sqlx::query(&format!("SELECT * FROM {name} ORDER BY
rowid")) to ensure deterministic ordering when building data; keep existing
error handling and value extraction logic (the r.try_get paths) otherwise.
🧹 Nitpick comments (2)
src/utils/sqlite/mod.rs (2)
13-58: Avoid blocking FS ops in async open_file and add context.Line 31 uses
std::fs::create_dir_allinside an async function. Considertokio::fs(orspawn_blocking) and add context to failures so diagnostics are clearer. As per coding guidelines, add context to fallible operations.♻️ Suggested adjustment
use anyhow::Context as _; +use tokio::fs; ... pub async fn open_file(file: &Path) -> anyhow::Result<SqlitePool> { if let Some(dir) = file.parent() && !dir.is_dir() { - std::fs::create_dir_all(dir)?; + fs::create_dir_all(dir) + .await + .with_context(|| format!("creating sqlite directory {dir:?}"))?; } let options = SqliteConnectOptions::new().filename(file); - Ok(open(options).await?) + Ok(open(options) + .await + .with_context(|| format!("opening sqlite database at {file:?}"))?) }
61-105: Clarify the DDL vs migration contract for fresh DBs.When
_metais missing, the code inserts all versions and skips migrations, so fresh DBs rely onddlsalready representing the latest schema. Please document or assert this contract to avoid marking a version that hasn’t actually been applied.📝 Doc clarification
/// This function initializes the database by checking whether it needs to be created or upgraded. /// The `ddls` are the `DDL`(Data Definition Language) statements to create the tables in the database and their initial required +/// content. NOTE: `ddls` must represent the latest schema; migrations are only for upgrading existing databases. /// content. The `schema_version` will be set inside the database if it is newly created. Otherwise, the
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Cargo.toml
Outdated
| slotmap = "1" | ||
| smallvec = "1" | ||
| smart-default = "0.7" | ||
| sqlx = { version = "0.8", default-features = false, features = ["sqlite", "runtime-tokio", "macros"] } |
There was a problem hiding this comment.
given we don't use it anywhere yet, let's hide it behind a feature flag
There was a problem hiding this comment.
It's not meant to be an optional feature and will be integrated in a subsequent PR.
There was a problem hiding this comment.
Yeah, but until integrated, it's wasteful.
There was a problem hiding this comment.
Putting it behind a feature flag would make CI ignore the unit test unless we change the script but we will need to change everything back right after this is merged : )
There was a problem hiding this comment.
Or I can add the feature to the default list so it's excluded by mise run i --slim quick
LesnyRumcajs
left a comment
There was a problem hiding this comment.
LGTM, but probably best to keep it behind a feature flag until we actually use it.
Summary of changes
(Part of #6249)
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Summary by CodeRabbit
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.