diff --git a/test.migrations.toml b/test.migrations.toml index 9a8211f..4fc61d7 100644 --- a/test.migrations.toml +++ b/test.migrations.toml @@ -39,12 +39,18 @@ migrations_append_only = [ "ALTER TABLE person ADD COLUMN name TEXT", "ALTER TABLE person ADD COLUMN age INTEGER", "ALTER TABLE person ADD COLUMN image_jpg BLOB", + "CREATE TABLE nooption (rowid INTEGER PRIMARY KEY) STRICT", + "ALTER TABLE nooption ADD COLUMN e INTEGER NOT NULL DEFAULT 0", ] output_generated_schema_for_your_information_do_not_edit = """ CREATE TABLE _turbosql_migrations ( rowid INTEGER PRIMARY KEY, migration TEXT NOT NULL ) STRICT + CREATE TABLE nooption ( + rowid INTEGER PRIMARY KEY, + e INTEGER NOT NULL DEFAULT 0 + ) STRICT CREATE TABLE person ( rowid INTEGER PRIMARY KEY, name TEXT, @@ -86,6 +92,19 @@ output_generated_schema_for_your_information_do_not_edit = """ ) STRICT """ +[output_generated_tables_do_not_edit.nooption] +name = "nooption" + +[[output_generated_tables_do_not_edit.nooption.columns]] +name = "rowid" +rust_type = "Option < i64 >" +sql_type = "INTEGER PRIMARY KEY" + +[[output_generated_tables_do_not_edit.nooption.columns]] +name = "e" +rust_type = "u8" +sql_type = "INTEGER NOT NULL" + [output_generated_tables_do_not_edit.person] name = "person" diff --git a/turbosql-impl/src/lib.rs b/turbosql-impl/src/lib.rs index 66fc221..2ab130e 100644 --- a/turbosql-impl/src/lib.rs +++ b/turbosql-impl/src/lib.rs @@ -860,11 +860,11 @@ fn extract_columns(fields: &FieldsNamed) -> Vec { (_, "String") => ("TEXT NOT NULL", "\"\""), // SELECT LENGTH(blob_column) ... will be null if blob is null (_, "Option < Blob >") => ("BLOB", "b\"\""), - (_, "Blob") => ("BLOB NOT NULL", "b\"\""), + (_, "Blob") => ("BLOB NOT NULL", "\"\""), (_, "Option < Vec < u8 > >") => ("BLOB", "b\"\""), - (_, "Vec < u8 >") => ("BLOB NOT NULL", "b\"\""), + (_, "Vec < u8 >") => ("BLOB NOT NULL", "\"\""), (_, "Option < [u8; _] >") => ("BLOB", "b\"\\x00\\x01\\xff\""), - (_, "[u8; _]") => ("BLOB NOT NULL", "b\"\\x00\\x01\\xff\""), + (_, "[u8; _]") => ("BLOB NOT NULL", "\"\""), _ => { // JSON-serialized if ty_str.starts_with("Option < ") { @@ -876,7 +876,8 @@ fn extract_columns(fields: &FieldsNamed) -> Vec { }; if sql_default.is_none() && sql_type.ends_with("NOT NULL") { - abort!(f, "Field {} has no default value and is not nullable. Either add a default value with e.g. #[turbosql(sql_default = {default_example})] or make it Option<{ty_str}>.", name); + sql_default = Some(default_example.into()); + // abort!(f, "Field `{}` has no default value and is not nullable. Either add a default value with e.g. #[turbosql(sql_default = {default_example})] or make it Option<{ty_str}>.", name); } Some(Column { diff --git a/turbosql/tests/ui/macros.stderr b/turbosql/tests/ui/macros.stderr index dac714d..4d4f1d2 100644 --- a/turbosql/tests/ui/macros.stderr +++ b/turbosql/tests/ui/macros.stderr @@ -1,9 +1,3 @@ -error: Field e has no default value and is not nullable. Either add a default value with e.g. #[turbosql(sql_default = 0)] or make it Option. - --> tests/ui/macros.rs:8:2 - | -8 | e: u8, - | ^^^^^ - error: derive(Turbosql) structs must include a 'rowid: Option' field --> tests/ui/macros.rs:11:10 |