MCPcopy Index your code
hub / github.com/coder/coder / normalizeDump

Function normalizeDump

coderd/database/dbtestutil/db.go:306–324  ·  view source on GitHub ↗
(schema []byte)

Source from the content-addressed store, hash-verified

304}
305
306func normalizeDump(schema []byte) []byte {
307 // Remove all comments.
308 schema = regexp.MustCompile(`(?im)^(--.*)$`).ReplaceAll(schema, []byte{})
309 // Strip psql meta-commands (\restrict / \unrestrict) emitted by pg_dump
310 // 13.22+ / 14.19+ / 15.14+ / 16.10+ / 17.6+. The token in these lines is
311 // randomized per run, so we drop them entirely. See
312 // https://github.com/coder/internal/issues/965.
313 schema = regexp.MustCompile(`(?im)^\\(restrict|unrestrict).*$`).ReplaceAll(schema, []byte{})
314 // Public is implicit in the schema.
315 schema = regexp.MustCompile(`(?im)( |::|'|\()public\.`).ReplaceAll(schema, []byte(`$1`))
316 // Remove database settings.
317 schema = regexp.MustCompile(`(?im)^(SET.*;)`).ReplaceAll(schema, []byte(``))
318 // Remove select statements
319 schema = regexp.MustCompile(`(?im)^(SELECT.*;)`).ReplaceAll(schema, []byte(``))
320 // Removes multiple newlines.
321 schema = regexp.MustCompile(`(?im)\n{3,}`).ReplaceAll(schema, []byte("\n\n"))
322
323 return schema
324}
325
326// Deprecated: disable foreign keys was created to aid in migrating off
327// of the test-only in-memory database. Do not use this in new code.

Callers 3

DumpOnFailureFunction · 0.85
PGDumpSchemaOnlyFunction · 0.85

Calls 1

MustCompileMethod · 0.80

Tested by 1