-
Notifications
You must be signed in to change notification settings - Fork 29
fix: add SET search_path to dump output for non-public schemas (#296) #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,17 @@ func GenerateTempSchemaName() string { | |||||||||||||||||||||
| return fmt.Sprintf("pgschema_tmp_%s_%s", timestamp, randomSuffix) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // stripSetSearchPath removes SET search_path statements from SQL. | ||||||||||||||||||||||
| // This is needed because pgschema dump includes SET search_path for non-public schemas | ||||||||||||||||||||||
| // to make the dump self-contained. When applying desired state SQL to a temporary schema | ||||||||||||||||||||||
| // during plan generation, the SET search_path would override the temp schema's search_path, | ||||||||||||||||||||||
| // causing objects to be created in the wrong schema. | ||||||||||||||||||||||
| func stripSetSearchPath(sql string) string { | ||||||||||||||||||||||
| // Match SET search_path TO ... ; with optional whitespace and newlines | ||||||||||||||||||||||
| re := regexp.MustCompile(`(?im)^\s*SET\s+search_path\s+TO\s+[^;]+;\s*\n?`) | ||||||||||||||||||||||
| return re.ReplaceAllString(sql, "") | ||||||||||||||||||||||
|
Comment on lines
+65
to
+68
|
||||||||||||||||||||||
| func stripSetSearchPath(sql string) string { | |
| // Match SET search_path TO ... ; with optional whitespace and newlines | |
| re := regexp.MustCompile(`(?im)^\s*SET\s+search_path\s+TO\s+[^;]+;\s*\n?`) | |
| return re.ReplaceAllString(sql, "") | |
| // setSearchPathRegex matches "SET search_path TO ...;" with optional whitespace and newlines. | |
| var setSearchPathRegex = regexp.MustCompile(`(?im)^\s*SET\s+search_path\s+TO\s+[^;]+;\s*\n?`) | |
| func stripSetSearchPath(sql string) string { | |
| return setSearchPathRegex.ReplaceAllString(sql, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an integration test that verifies the complete workflow: dump a non-public schema (which should include SET search_path), then use the plan command to apply that dump to verify that stripSetSearchPath correctly prevents the dump header from overriding the temporary schema's search_path. This would provide more comprehensive test coverage for the fix beyond just verifying the dump output format.