diff --git a/core/schema.rs b/core/schema.rs index 20ae6380e..2d7c2f8d9 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -1033,6 +1033,9 @@ impl BTreeTable { sql.push(' '); sql.push_str(&column.ty_str); } + if column.notnull { + sql.push_str(" NOT NULL"); + } if column.unique { sql.push_str(" UNIQUE"); diff --git a/testing/alter_table.test b/testing/alter_table.test index 172802395..5a856eca9 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -204,3 +204,10 @@ do_execsql_test_on_specific_db {:memory:} alter-table-rename-to-quoted-identifie "CREATE INDEX idx ON \"t t\" (\"b b\")" "2" } + +# https://github.com/tursodatabase/turso/issues/3391 +do_execsql_test_on_specific_db {:memory:} alter-table-add-notnull-col { + CREATE TABLE t (a); + ALTER TABLE t ADD b NOT NULL; + SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = 't'; +} {{CREATE TABLE t (a, b NOT NULL)}}