Files
turso/tests
Pekka Enberg 5507fa4d5e Merge 'core/schema: keep COLLATE and DESC in UNIQUE and PRIMARY KEY table constraints' from teleivo
`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
2026-10-15 12:16:14 +03:00
..
…
…

Integration and regression test suite.


# run all tests
cargo test 

# run individual test
cargo test test_sequential_write -- --nocapture