Skip to content

Commit ed0cef1

Browse files
committed
docs(issues): keep eager schema initialization in 1525-05
1 parent 76594b7 commit ed0cef1

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

docs/issues/1717-1525-05-migrate-sqlite-and-mysql-to-sqlx.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ The technique is to put the async traits and new drivers in a temporary `databas
4141
submodule during Tasks 1–3. Task 4 moves them into place, updates consumers, and removes the sync
4242
code.
4343

44+
### Decision update (2026-04-29)
45+
46+
After implementation review, we decided to keep **eager schema initialization** in this subissue
47+
for operational clarity and parity with the existing sync drivers:
48+
49+
- Do **not** use per-method lazy schema checks (`ensure_schema()`).
50+
- Keep explicit startup initialization (`create_database_tables()`) in setup/factory wiring.
51+
- Keep using raw `sqlx::query()` DDL in this subissue; migration tooling stays in `1525-06`.
52+
53+
This decision also applies to Task 4 (switch commit): keep eager initialization there as well.
54+
4455
### What changes in the drivers
4556

4657
The current drivers use blocking I/O and create the schema eagerly on construction. The new
@@ -50,8 +61,7 @@ The current drivers use blocking I/O and create the schema eagerly on constructi
5061
- Manage the schema with raw `sqlx::query()` DDL statements (`CREATE TABLE IF NOT EXISTS ...`),
5162
exactly mirroring what the current sync drivers do. `sqlx::migrate!()` and migration files are
5263
**not** introduced here — that is subissue `1525-06`.
53-
- Run `create_database_tables()` lazily the first time any operation is called, protected by an
54-
`AtomicBool` + `Mutex` double-checked latch (`ensure_schema()`).
64+
- Keep schema initialization eager via setup/factory initialization (`create_database_tables()`).
5565
- All trait methods become `async fn` (via `async_trait`).
5666

5767
## Tasks
@@ -70,9 +80,7 @@ sqlx = { version = "*", features = ["sqlite", "mysql", "runtime-tokio-native-tls
7080
tokio = { version = "*", features = ["full"] } # latest compatible; if not already present with needed features
7181
```
7282

73-
Use the latest crate versions compatible with MSRV 1.72. For the `Mutex` used in
74-
`ensure_schema()`, use `tokio::sync::Mutex` (not `std::sync::Mutex`) to avoid runtime conflicts
75-
since Tokio is used throughout the project.
83+
Use the latest crate versions compatible with MSRV 1.72.
7684

7785
Keep `r2d2`, `r2d2_sqlite`, `rusqlite`, and the `mysql` crate — they are still needed by the old
7886
drivers until Task 4.
@@ -219,8 +227,8 @@ This task is a single focused commit. Steps within the commit:
219227

220228
4. **Update `databases/setup.rs``initialize_database()`**: this function already returns
221229
`DatabaseStores` (a struct of four `Arc<dyn XxxStore>` fields, one per narrow trait — not
222-
`Arc<Box<dyn Database>>`). Remove the eager `create_database_tables()` call; schema
223-
initialization is now lazy via `ensure_schema()`. No return-type change is needed.
230+
`Arc<Box<dyn Database>>`). Keep eager `create_database_tables()` during initialization.
231+
No return-type change is needed.
224232

225233
5. **Add `.await` at all consumer call sites**: every location that called a narrow-trait method
226234
synchronously now needs `.await`. The affected files are:
@@ -258,13 +266,12 @@ and all `r2d2`/`rusqlite`/`mysql` dependencies are gone.
258266
- `DatabaseStores` (four `Arc<dyn XxxStore>` fields, one per narrow trait) is already the
259267
consumer-facing type returned by `initialize_database()`; do not change this. Do not introduce
260268
`Arc<Box<dyn Database>>` or the `Persistence` struct from the reference implementation.
261-
- The lazy `ensure_schema()` latch must be correct under concurrent async access: use
262-
`AtomicBool` (Acquire/Release) + `Mutex` double-checked pattern as in the reference.
269+
- Keep startup schema initialization eager in this subissue and in Task 4.
263270

264271
## Acceptance Criteria
265272

266273
- [ ] SQLite and MySQL drivers use `sqlx` with async trait methods.
267-
- [ ] Schema initialization is lazy (`ensure_schema()` pattern) — no eager call in `build()`.
274+
- [ ] Schema initialization remains eager via setup/factory initialization.
268275
- [ ] Schema management uses raw `sqlx::query()` DDL; `sqlx::migrate!()` is not used.
269276
- [ ] `r2d2`, `r2d2_sqlite`, `rusqlite`, and the `mysql` crate are removed from
270277
`tracker-core/Cargo.toml`.

0 commit comments

Comments
 (0)