From 5ed022f4ea9d278489405fc9de5d87a11872de70 Mon Sep 17 00:00:00 2001 From: Reza Date: Mon, 19 Feb 2024 06:24:10 +0100 Subject: [PATCH] Fix db column nullability detection in DDL generation 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. --- lib/db/schema/ddl/ddl.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/db/schema/ddl/ddl.go b/lib/db/schema/ddl/ddl.go index dc805752..24932766 100644 --- a/lib/db/schema/ddl/ddl.go +++ b/lib/db/schema/ddl/ddl.go @@ -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" {