mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-29 09:33:48 +00:00
`ALTER TABLE` rewrites the stored `CREATE TABLE` text with `BTreeTable::to_sql`, which dropped `COLLATE` from table-level `UNIQUE (...)` and `PRIMARY KEY (...)` constraints and `DESC` from `UNIQUE (...)`. `ADD COLUMN` and `DROP COLUMN` both go through it. After the database is opened again, the constraint's automatic index is searched as `BINARY` and ascending while its b-tree is sorted by the original collation and order, so duplicates are accepted. * write the collation of each constraint column, for `UNIQUE` and `PRIMARY KEY` * write `DESC` for `UNIQUE` columns. `PRIMARY KEY (a DESC)` already kept it: it is written inline as `a TEXT PRIMARY KEY DESC`, which is the same constraint, not `a TEXT PRIMARY KEY` as the issue says * keep a single-column primary key with a collation as a table constraint. Writing it inline as `a PRIMARY KEY COLLATE NOCASE` would give the column itself that collation, which changes every comparison on `a` Not covered: `NULLS FIRST/LAST` in both constraints is still dropped, and the constraint order problem from #8704 is unchanged. Fixes #8702 Closes #9635
Integration and regression test suite.
# run all tests
cargo test
# run individual test
cargo test test_sequential_write -- --nocapture