|
| 1 | +# TASK-075: Spec (RGRTDD) — `crsql_automigrate` behavior |
| 2 | + |
| 3 | +## Status |
| 4 | +- [ ] Planned |
| 5 | +- [ ] Assigned |
| 6 | +- [ ] In Progress |
| 7 | +- [ ] Blocked (reason: ...) |
| 8 | +- [ ] Complete |
| 9 | + |
| 10 | +## Priority |
| 11 | +high |
| 12 | + |
| 13 | +## Assigned To |
| 14 | +(unassigned) |
| 15 | + |
| 16 | +## Parent Docs / Cross-links |
| 17 | +- Rust reference implementation: `core/rs/core/src/automigrate.rs` |
| 18 | +- Rust integration tests: `core/rs/integration_check/src/t/automigrate.rs` |
| 19 | +- Zig alter path: `zig/src/schema_alter.zig` |
| 20 | +- Gap backlog: `research/zig-cr/92-gap-backlog.md` |
| 21 | + |
| 22 | +## Description |
| 23 | +Define the intended behavior of `crsql_automigrate(schema_sql[, cleanup_sql])` by capturing it in executable tests. |
| 24 | + |
| 25 | +The goal is to make it hard to accidentally ship a “toy” automigrate: |
| 26 | +- It must be idempotent. |
| 27 | +- It must be atomic. |
| 28 | +- It must preserve CRR invariants (when migrating CRR tables it must use the alter flow). |
| 29 | + |
| 30 | +This is a **spec/tests-only** task. Do not implement `crsql_automigrate` here. |
| 31 | + |
| 32 | +## Files to Modify |
| 33 | +- `zig/harness/test-automigrate.sh` (new) |
| 34 | +- `zig/harness/test-parity.sh` (wire into suite) |
| 35 | +- `research/zig-cr/92-gap-backlog.md` |
| 36 | + |
| 37 | +## Acceptance Criteria |
| 38 | +- [ ] Test suite exists that fails on current Zig (missing function). |
| 39 | +- [ ] Tests describe behavior (no “should”). |
| 40 | +- [ ] At minimum, tests cover: |
| 41 | + 1. **Empty schema is a no-op**: `SELECT crsql_automigrate('')` returns `migration complete`. |
| 42 | + 2. **Create tables**: schema with a new table results in the table existing. |
| 43 | + 3. **Drop tables**: tables not present in desired schema are dropped (excluding `sqlite_%`, `crsql_%`, `__crsql_%`, and `%__crsql_%`). |
| 44 | + 4. **Add column**: adding a column via desired schema results in column existing. |
| 45 | + 5. **Drop column**: removing a column results in column dropped. |
| 46 | + 6. **Index reconciliation**: indices match the desired schema. |
| 47 | + 7. **CRR table migration uses alter flow**: if the table is a CRR, automigrate uses `crsql_begin_alter`/`crsql_commit_alter` semantics so triggers remain correct. |
| 48 | + 8. **Atomicity**: if the schema is invalid, no partial changes persist. |
| 49 | + |
| 50 | +## Progress Log |
| 51 | +### 2025-12-18 |
| 52 | +- Task created from Rust↔Zig gap analysis. |
| 53 | + |
| 54 | +## Completion Notes |
0 commit comments