tursodatabase / libsql-shell-go

7 stars 7 forks source link

`.dump` outputs invalid `NULL;` on table with UNIQUE column #118

Closed CodingDoug closed 1 year ago

CodingDoug commented 1 year ago

Create a new database:

turso db create t
turso db shell t

Create a new table with a unique column and dump it:

create table foo(x text unique);
.dump

See invalid NULL in the output, as well as missing UNIQUE in the schema:

PRAGMA foreign_keys=OFF;
CREATE TABLE foo(x TEXT);
NULL;

This does not happen for unique indexes added separately.

athoscouto commented 1 year ago

A UNIQUE constraint is returned as an index when getTableIndexes is called. Then it is passed to dumpTableIndexes, dumpIndex and getIndex. The last function does a SQL query to fetch the index data, but the query returns null, which leads to a NULL; statement being print in the dump.