+++ title = "Implement database connection module and SQLx migrations (quotes + quote_tags schema)" priority = 8 status = "done" ticket_type = "task" dependencies = ["1f5bb5", "580e66", "33ed29"] +++ The `quotesdb` API is built with Axum + Tokio, targeting Cloudflare Workers via `workers-rs`. It serves JSON at `/api/*` endpoints and persists data to Cloudflare D1 (production) or a local SQLite file via Turso (development). Source lives in `src/bin/api/`. Shared types and utilities are in `src/lib.rs` — code placed there must compile for both the host target and `wasm32-unknown-unknown`. The database schema consists of two tables: - `quotes` — stores id (NanoID), text, author, source, date, auth_code, created_at, updated_at - `quote_tags` — join table for quote-to-tag relationships with cascade delete **This ticket's SQLx-based goal has been superseded by ticket 00aff0.** TRIAGE e8a330 concluded that SQLx is incompatible with workers-rs/D1. The new approach uses: - workers-rs `D1Database` bindings for the WASM/production target - `rusqlite` + `tokio-rusqlite` for the native/test target - A `QuoteRepository` async trait as the shared interface - `cfg(target_arch = "wasm32")` for compile-time target selection See ticket 00aff0 for the full implementation plan. This ticket remains open as tracking context but its implementation is covered by 00aff0. ~~Implement `src/bin/api/db.rs` (or equivalent module) providing:~~ ~~1. A database connection pool constructor (Turso/SQLite locally, D1 in production)~~ ~~2. SQLx migrations that create the `quotes` and `quote_tags` tables if they don't exist~~ ~~3. Re-export the pool type for use by handlers~~ **Updated goal (see ticket 00aff0):** Implement `src/bin/api/db/` module with: 1. `QuoteRepository` trait in `db/mod.rs` 2. `D1Repository` in `db/d1.rs` (`#[cfg(target_arch = "wasm32")]`) 3. `NativeRepository` in `db/native.rs` (`#[cfg(not(target_arch = "wasm32"))]`) 4. SQL migration strings in `db/migrations.rs` - TRIAGE 580e66 resolved (same decision as 5c0c64): D1 production schema is applied via `wrangler d1 execute` (separate CI step). The Workers fetch handler does NOT run migrations. Native `main()` calls `repo.run_migrations()` via rusqlite on startup. - Schema must exactly match the design: NanoID primary key, `auth_code` stored plaintext, optional `source` and `date` fields, cascade delete on `quote_tags`. - SQLx is NOT used. Use workers-rs D1 bindings (wasm32) and rusqlite (native). See 00aff0. Use `superpowers:test-driven-development` — write a test that verifies migration runs and tables exist. Use `superpowers:verification-before-completion` before closing. Run in order from the `quotesdb/` directory: ```sh cargo fmt cargo check cargo clippy cargo test ``` `feat(quotesdb): implement database connection module and SQLx migrations`