diff --git a/core/schema.rs b/core/schema.rs index dea630da4..f6d1aa7c1 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -249,6 +249,10 @@ impl BTreeTable { sql.push_str(column.name.as_ref().expect("column name is None")); sql.push(' '); sql.push_str(&column.ty.to_string()); + if let Some(default) = &column.default { + sql.push_str(" DEFAULT "); + sql.push_str(&default.to_string()); + } } sql.push_str(");\n"); sql diff --git a/testing/alter_table.test b/testing/alter_table.test index 8035a475f..508dfac16 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -31,16 +31,15 @@ do_execsql_test_on_specific_db {:memory:} alter-table-add-column { do_execsql_test_on_specific_db {:memory:} alter-table-add-column-typed { CREATE TABLE t(a); - ALTER TABLE t ADD b TEXT; - ALTER TABLE t ADD c INTEGER DEFAULT 0; + ALTER TABLE t ADD b DEFAULT 0; SELECT sql FROM sqlite_schema; - INSERT INTO t VALUES (1, 'a'); + INSERT INTO t (a) VALUES (1); SELECT * FROM t; } { - "CREATE TABLE t(a, b TEXT, c INTEGER DEFAULT(0))" - "1|a|0" + "CREATE TABLE t(a, b DEFAULT 0)" + "1|0" } do_execsql_test_on_specific_db {:memory:} alter-table-drop-column {