MCPcopy Create free account
hub / github.com/bytebase/bytebase / normalizePostgreSQLTypecastInDefault

Function normalizePostgreSQLTypecastInDefault

backend/plugin/schema/differ.go:708–732  ·  view source on GitHub ↗

normalizePostgreSQLTypecastInDefault normalizes PostgreSQL type casts in default values

(defaultValue string)

Source from the content-addressed store, hash-verified

706
707// normalizePostgreSQLTypecastInDefault normalizes PostgreSQL type casts in default values
708func normalizePostgreSQLTypecastInDefault(defaultValue string) string {
709 if defaultValue == "" {
710 return ""
711 }
712
713 normalized := strings.TrimSpace(defaultValue)
714
715 // Remove PostgreSQL type casts from default values
716 // Handle patterns like '1 day'::interval -> '1 day'
717 normalized = strings.ReplaceAll(normalized, "'::interval", "'")
718 normalized = strings.ReplaceAll(normalized, "'::timestamp", "'")
719 normalized = strings.ReplaceAll(normalized, "'::date", "'")
720 normalized = strings.ReplaceAll(normalized, "'::time", "'")
721 normalized = strings.ReplaceAll(normalized, "'::numeric", "'")
722
723 // Handle string type casts
724 // Handle character varying first (longest match first to avoid partial replacement)
725 normalized = strings.ReplaceAll(normalized, "'::character varying", "'") // CHARACTER VARYING type (full form of VARCHAR)
726 normalized = strings.ReplaceAll(normalized, "'::bpchar", "'") // CHAR type
727 normalized = strings.ReplaceAll(normalized, "'::text", "'") // TEXT type
728 normalized = strings.ReplaceAll(normalized, "'::varchar", "'") // VARCHAR type
729 normalized = strings.ReplaceAll(normalized, "'::character", "'") // CHARACTER type
730
731 return normalized
732}
733
734// generationMetadataEqual compares two generation metadata structs.
735func generationMetadataEqual(engine storepb.Engine, gen1, gen2 *storepb.GenerationMetadata) bool {

Callers 1

defaultValuesEqualFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected