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

Function normalizePostgreSQLFunction

backend/plugin/schema/differ.go:2229–2269  ·  view source on GitHub ↗

normalizePostgreSQLFunction normalizes PostgreSQL function definitions for comparison

(definition string)

Source from the content-addressed store, hash-verified

2227
2228// normalizePostgreSQLFunction normalizes PostgreSQL function definitions for comparison
2229func normalizePostgreSQLFunction(definition string) string {
2230 if definition == "" {
2231 return ""
2232 }
2233
2234 normalized := strings.ToLower(definition)
2235
2236 // Normalize whitespace
2237 normalized = strings.ReplaceAll(normalized, "\n", " ")
2238 normalized = strings.ReplaceAll(normalized, "\t", " ")
2239
2240 // Remove extra spaces
2241 for strings.Contains(normalized, " ") {
2242 normalized = strings.ReplaceAll(normalized, " ", " ")
2243 }
2244
2245 // Normalize CREATE vs CREATE OR REPLACE
2246 normalized = strings.ReplaceAll(normalized, "create or replace function", "create function")
2247 normalized = strings.ReplaceAll(normalized, "create or replace procedure", "create procedure")
2248
2249 // Remove public schema prefix from function and procedure names
2250 normalized = strings.ReplaceAll(normalized, "function public.", "function ")
2251 normalized = strings.ReplaceAll(normalized, "procedure public.", "procedure ")
2252
2253 // Normalize parameter types
2254 normalized = strings.ReplaceAll(normalized, "character varying", "varchar")
2255 normalized = strings.ReplaceAll(normalized, "returns numeric", "returns decimal")
2256
2257 // Normalize dollar quoting - handle various dollar quote formats
2258 normalized = strings.ReplaceAll(normalized, "$function$", "$$")
2259 normalized = strings.ReplaceAll(normalized, "$procedure$", "$$")
2260
2261 // Normalize language position - move to end
2262 if strings.Contains(normalized, "language plpgsql") && !strings.HasSuffix(strings.TrimSpace(normalized), "language plpgsql") {
2263 withoutLanguage := strings.ReplaceAll(normalized, " language plpgsql", "")
2264 withoutLanguage = strings.ReplaceAll(withoutLanguage, "language plpgsql ", "")
2265 normalized = strings.TrimSpace(withoutLanguage) + " language plpgsql"
2266 }
2267
2268 return strings.TrimSpace(normalized)
2269}
2270
2271// normalizePostgreSQLCheckConstraint normalizes PostgreSQL check constraint expressions for comparison
2272func normalizePostgreSQLCheckConstraint(expression string) string {

Callers 2

functionsEqualFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected