From b7fc9fef40e7eeb83866183edec6f3cd12de765b Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 27 Sep 2025 13:12:19 -0400 Subject: [PATCH 1/4] Persist NOT NULL column constraint to schema table --- core/schema.rs | 3 +++ 1 file changed, 3 insertions(+) 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"); From bd17c5d5df8edd8d739cead39f9accfcf06e4a0b Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 27 Sep 2025 13:15:48 -0400 Subject: [PATCH 2/4] Add regression test for alter table with notnull constraint --- testing/alter_table.test | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/alter_table.test b/testing/alter_table.test index 172802395..8c5b25bec 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; + .schema t +} {{CREATE TABLE t (a, b NOT NULL);}} From 6e3c30623c352415304b7fbda9b325ffc654e287 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 27 Sep 2025 13:17:50 -0400 Subject: [PATCH 3/4] Fix regression test to not use dot command --- testing/alter_table.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/alter_table.test b/testing/alter_table.test index 8c5b25bec..33adc5b34 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -209,5 +209,5 @@ do_execsql_test_on_specific_db {:memory:} alter-table-rename-to-quoted-identifie do_execsql_test_on_specific_db {:memory:} alter-table-add-notnull-col { CREATE TABLE t (a); ALTER TABLE t ADD b NOT NULL; - .schema t + SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = 't'; } {{CREATE TABLE t (a, b NOT NULL);}} From ace2ac632a89adea726f059e2664803bc9b82c6d Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sat, 27 Sep 2025 13:59:51 -0400 Subject: [PATCH 4/4] Remove semicolon from test --- testing/alter_table.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/alter_table.test b/testing/alter_table.test index 33adc5b34..5a856eca9 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -210,4 +210,4 @@ 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);}} +} {{CREATE TABLE t (a, b NOT NULL)}}