sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

IDE Plugin and gradle test task could be improved when adding a new migration for a NON NULL column?

Open ColtonIdle opened this issue 1 month ago • 1 comments

SQLDelight Version

2.0.1

IDE Version

No response

Dialect

SQLite

Describe the Bug

I had a table written as such

CREATE TABLE myDbo (
  uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  serializedData TEXT NOT NULL
);

then today I came back and added a line

myNewId INTEGER NOT NULL

and sqldelight prompted me to create a new migraiton file. AWESOME (thanks to whoever worked on that)

but reading the docs it looks like if you have something not null, then you should provide a default.

but the migration written was

ALTER TABLE myDbo ADD COLUMN myNewId INTEGER NOT NULL;

should it be?

ALTER TABLE myDbo ADD COLUMN myNewId INTEGER NOT NULL DEFAULT 0;

The tests ran by the gradle plugin also didn't catch this... which i think it maybe could/should have?

So "two" issues here (really feature requests i guess)

  1. can the plugin be improved to write the ALTER TABLE with a default if it's set to NOT NULL
  2. can the built in migration tests catch this case?

Source: https://www.sqlite.org/lang_altertable.html

If a NOT NULL constraint is specified, then the column must have a default value other than NULL.

Stacktrace

No response

ColtonIdle avatar May 17 '24 16:05 ColtonIdle