Skip to content
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

fix: special case for gp_toolkit when gprestore close cloudberry #681 #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backup/predata_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func PrintFunctionModifiers(metadataFile *utils.FileWithByteCount, funcDef Funct
}

// Stored procedures do not permit parallelism declarations
if funcDef.Kind != "p" {
if funcDef.Kind != "p" {
switch funcDef.Parallel {
case "u":
metadataFile.MustPrintf(" PARALLEL UNSAFE")
Expand Down Expand Up @@ -278,7 +278,10 @@ func PrintCreateCastStatement(metadataFile *utils.FileWithByteCount, toc *toc.TO
func PrintCreateExtensionStatements(metadataFile *utils.FileWithByteCount, toc *toc.TOC, extensionDefs []Extension, extensionMetadata MetadataMap) {
for _, extensionDef := range extensionDefs {
start := metadataFile.ByteCount
metadataFile.MustPrintf("\n\nSET search_path=%s,pg_catalog;\nCREATE EXTENSION IF NOT EXISTS %s WITH SCHEMA %s;\nSET search_path=pg_catalog;", extensionDef.Schema, extensionDef.Name, extensionDef.Schema)
// changes to gp_toolkit in gpdb7 require explicilty creating the schema before the extension
metadataFile.MustPrintf(
"\n\nCREATE SCHEMA IF NOT EXISTS %[1]s;\nSET search_path=%[1]s,pg_catalog;\nCREATE EXTENSION IF NOT EXISTS %[2]s WITH SCHEMA %[1]s;\nSET search_path=pg_catalog;\n",
extensionDef.Schema, extensionDef.Name)

section, entry := extensionDef.GetMetadataEntry()
toc.AddMetadataEntry(section, entry, start, metadataFile.ByteCount)
Expand Down
6 changes: 4 additions & 2 deletions backup/predata_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,17 @@ AS ASSIGNMENT;`)
It("prints a create extension statement", func() {
extensionDef := backup.Extension{Oid: 1, Name: "extension1", Schema: "schema1"}
backup.PrintCreateExtensionStatements(backupfile, tocfile, []backup.Extension{extensionDef}, emptyMetadataMap)
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, `SET search_path=schema1,pg_catalog;
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, `CREATE SCHEMA IF NOT EXISTS schema1;
SET search_path=schema1,pg_catalog;
CREATE EXTENSION IF NOT EXISTS extension1 WITH SCHEMA schema1;
SET search_path=pg_catalog;`)
})
It("prints a create extension statement with a comment", func() {
extensionDef := backup.Extension{Oid: 1, Name: "extension1", Schema: "schema1"}
extensionMetadataMap := testutils.DefaultMetadataMap("EXTENSION", false, false, true, false)
backup.PrintCreateExtensionStatements(backupfile, tocfile, []backup.Extension{extensionDef}, extensionMetadataMap)
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, `SET search_path=schema1,pg_catalog;
testutils.AssertBufferContents(tocfile.PredataEntries, buffer, `CREATE SCHEMA IF NOT EXISTS schema1;
SET search_path=schema1,pg_catalog;
CREATE EXTENSION IF NOT EXISTS extension1 WITH SCHEMA schema1;
SET search_path=pg_catalog;`, "COMMENT ON EXTENSION extension1 IS 'This is an extension comment.';")
})
Expand Down
Loading