From d44cad5ebdee5e2e9bc7aa4ff2e83eb4f62d5614 Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Thu, 5 Sep 2024 14:15:42 +1200 Subject: [PATCH] =?UTF-8?q?fix:=20Multiline=20regex=20for=20definers.=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent missing SQL statements. Added "_" to expression --- internal/dump/dump.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/dump/dump.go b/internal/dump/dump.go index ae71c56..f97dfff 100644 --- a/internal/dump/dump.go +++ b/internal/dump/dump.go @@ -96,6 +96,7 @@ func WithPassword(password string) Option { } } func (c *Client) Dump() error { + // Construct schema output fmt.Printf("%s Dumping schema %s from %s\n\r", style.Success(icon.Info), @@ -103,6 +104,14 @@ func (c *Client) Dump() error { lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname), ) + f, _ := os.OpenFile(filepath.Join(c.storagePath, c.databaseName+"-keys.sql"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + + _, err := f.WriteString("SET FOREIGN_KEY_CHECKS=0;\n") + if err != nil { + return err + } + f.Close() + response, err := exec.Command(c.executable, "--host="+c.hostname, "--port="+strconv.Itoa(c.port), @@ -191,9 +200,9 @@ func removeDefiners(filename string) { // Regex 3: (\/\*\!50013.*DEFINER \*\/) (Used in schema) expressions := make([]string, 3) - expressions[0] = `s/(^.*)(.DEFINER=[a-zA-Z0-9\x60%@]+)(.*)/$1$3/g` - expressions[1] = `s/(.*)(\/\*\!50003.*!50003+)(.*)/$1$3/g` - expressions[2] = `s/(\/\*\!50013.*DEFINER \*\/)//g` + expressions[0] = `s/(^.*)(.DEFINER=[a-zA-Z0-9_\x60%@]+)(.*)/$1$3/gm` + expressions[1] = `s/(.*)(\/\*\!50003.*!50003+)(.*)/$1$3/gm` + expressions[2] = `s/(\/\*\!50013.*DEFINER \*\/)//gm` if !strings.Contains(filename, "data") { for _, re := range expressions { @@ -221,10 +230,11 @@ func removeDefiners(filename string) { } func (c *Client) Combine() (string, error) { - var files [3]string - files[0] = "schema" - files[1] = "data" - files[2] = "routines" + var files [4]string + files[0] = "keys" + files[1] = "schema" + files[2] = "data" + files[3] = "routines" filepath.Join(c.storagePath, c.databaseName+"-backup.sql") err := concatenate.FilesToFile(filepath.Join(c.storagePath, c.databaseName+"-backup.sql"), @@ -233,6 +243,7 @@ func (c *Client) Combine() (string, error) { filepath.Join(c.storagePath, c.databaseName+"-"+files[0]+".sql"), filepath.Join(c.storagePath, c.databaseName+"-"+files[1]+".sql"), filepath.Join(c.storagePath, c.databaseName+"-"+files[2]+".sql"), + filepath.Join(c.storagePath, c.databaseName+"-"+files[3]+".sql"), ) if err != nil { return "", err