fix(merge,pgsql): treat serial types as their base integer in diffs, unquote bare keyword defaults
Merge conflict detection compared bigserial (DBML) against bigint (live PostgreSQL read of an existing serial column) as incompatible types, since serial is sugar over an integer column plus a sequence default and PostgreSQL always reports back the underlying integer type. Add SerialUnderlyingType and use it when comparing column types for conflicts. QuoteDefaultValue also wrapped bare keyword expressions like CURRENT_DATE in string quotes because they contain no parentheses, unlike function-call defaults such as now(). Recognize known bare keyword defaults and leave them unquoted across CREATE TABLE, ALTER TABLE ADD COLUMN, and ALTER COLUMN SET DEFAULT generation.
This commit is contained in:
@@ -148,6 +148,26 @@ func SanitizeFilename(name string) string {
|
||||
// Examples (boolean): "true" → "true"
|
||||
// Examples (bigint): "0" → "0"
|
||||
// Examples (timestamp): "now()" → "now()" (function call – never quoted)
|
||||
// bareKeywordDefaults are PostgreSQL default-value keywords that are
|
||||
// expressions, not string literals, even though they contain no
|
||||
// parentheses (e.g. "CURRENT_DATE" rather than "now()"). They must never be
|
||||
// wrapped in quotes.
|
||||
var bareKeywordDefaults = map[string]bool{
|
||||
"current_date": true,
|
||||
"current_time": true,
|
||||
"current_timestamp": true,
|
||||
"localtime": true,
|
||||
"localtimestamp": true,
|
||||
"current_user": true,
|
||||
"session_user": true,
|
||||
"current_role": true,
|
||||
"current_catalog": true,
|
||||
"current_schema": true,
|
||||
"null": true,
|
||||
"true": true,
|
||||
"false": true,
|
||||
}
|
||||
|
||||
func QuoteDefaultValue(value, sqlType string) string {
|
||||
value = strings.TrimSpace(value)
|
||||
|
||||
@@ -158,6 +178,12 @@ func QuoteDefaultValue(value, sqlType string) string {
|
||||
return value
|
||||
}
|
||||
|
||||
// Bare keyword expressions (e.g. CURRENT_DATE) are never quoted,
|
||||
// regardless of column type.
|
||||
if bareKeywordDefaults[strings.ToLower(value)] {
|
||||
return value
|
||||
}
|
||||
|
||||
// Normalise the SQL type: lowercase, strip length/precision suffix.
|
||||
baseType := strings.ToLower(strings.TrimSpace(sqlType))
|
||||
if idx := strings.Index(baseType, "("); idx > 0 {
|
||||
|
||||
Reference in New Issue
Block a user