Skip to content

Commit

Permalink
Fix db column nullability detection in DDL generation
Browse files Browse the repository at this point in the history
This update introduces a nullable check in making the DDL. Now, the column.getFieldType.Kind() is not only checked if it's pointing to a reference, but also made nullable when the NULLABLE TagSetting exists. This improves the accuracy in defining nullability in the database schema.
  • Loading branch information
iesreza committed Feb 19, 2024
1 parent ef8ac13 commit 5ed022f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/db/schema/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ func FromStatement(stmt *gorm.Statement) Table {
column.Type = "TIMESTAMP"
}

if field.FieldType.Kind() == reflect.Ptr {
var nullable = false
if _, ok := field.TagSettings["NULLABLE"]; ok {
nullable = true
}
if field.FieldType.Kind() == reflect.Ptr || nullable {
if _, ok := field.TagSettings["NOT NULL"]; !ok {
column.Nullable = true
if column.Type == "TIMESTAMP" && column.Default == "0000-00-00 00:00:00" {
Expand Down

0 comments on commit 5ed022f

Please sign in to comment.