feat(writers): quote default values based on SQL column type
Some checks failed
CI / Test (1.24) (push) Successful in -22m47s
CI / Lint (push) Failing after -24m34s
Integration Tests / Integration Tests (push) Successful in -25m0s
CI / Test (1.25) (push) Successful in -22m35s
CI / Build (push) Successful in -24m43s
Release / Build and Release (push) Successful in -21m46s

Bun and GORM struct tags now emit quoted defaults for string/date/time/UUID
columns (e.g. default:'disconnected') and unquoted defaults for numeric and
boolean columns (e.g. default:0, default:true). Function-call expressions
such as now() or gen_random_uuid() are never quoted regardless of type.

Adds QuoteDefaultValue(value, sqlType) helper in pkg/writers and updates
both type mappers and the bun writer tests accordingly.
This commit is contained in:
Hein
2026-02-20 16:03:50 +02:00
parent 77436757c8
commit 480038d51d
4 changed files with 98 additions and 10 deletions

View File

@@ -238,8 +238,8 @@ func (tm *TypeMapper) BuildGormTag(column *models.Column, table *models.Table) s
// Default value
if column.Default != nil {
// Sanitize default value to remove backticks
safeDefault := writers.SanitizeStructTagValue(fmt.Sprintf("%v", column.Default))
// Sanitize default value to remove backticks, then quote based on column type
safeDefault := writers.QuoteDefaultValue(writers.SanitizeStructTagValue(fmt.Sprintf("%v", column.Default)), column.Type)
parts = append(parts, fmt.Sprintf("default:%s", safeDefault))
}