From 59acfec6707fc221c64932f89c7b11a1ff9965ec Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Thu, 24 Oct 2024 07:02:31 +1300 Subject: [PATCH] =?UTF-8?q?fix:=20Now=20run=20definers=20cleanup=20once=20?= =?UTF-8?q?after=20combining=20files.=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #7 --- cmd/dump.go | 4 ++++ internal/dump/dump.go | 19 +++++-------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cmd/dump.go b/cmd/dump.go index c9ff555..d8207ae 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -72,6 +72,10 @@ to quickly create a Cobra application.`, "%s Zipping file\n\r", style.Success(icon.Info), ) + + // Strip definers from the Dumpfile + myDump.RemoveDefiners(filename) + filename, _ = dump.ZipFile(filename) timeElapsed := time.Since(start) fmt.Printf( diff --git a/internal/dump/dump.go b/internal/dump/dump.go index 29a5965..edb8afa 100644 --- a/internal/dump/dump.go +++ b/internal/dump/dump.go @@ -131,7 +131,6 @@ func (c *Client) Dump() error { ) return err } - removeDefiners(filepath.Join(c.storagePath, c.databaseName+"-schema.sql")) fmt.Printf( "%s Done dumping schema %s from %s\n\r", @@ -158,7 +157,7 @@ func (c *Client) Dump() error { "--compact", "--result-file", filepath.Join(c.storagePath, c.databaseName+"-data.sql"), c.databaseName).Run() - removeDefiners(filepath.Join(c.storagePath, c.databaseName+"-data.sql")) + fmt.Printf( "%s Done dumping data %s from %s\n\r", style.Success(icon.Check), @@ -186,7 +185,7 @@ func (c *Client) Dump() error { "--compact", "--result-file", filepath.Join(c.storagePath, c.databaseName+"-routines.sql"), c.databaseName).Run() - removeDefiners(filepath.Join(c.storagePath, c.databaseName+"-routines.sql")) + fmt.Printf( "%s Done dumping routines %s from %s\n\r", style.Success(icon.Check), @@ -197,17 +196,9 @@ func (c *Client) Dump() error { return nil } -func removeDefiners(filename string) { - // Regex 1: .*(DEFINER=[a-zA-Z0-9\x60%@]+).* (Used by procedures/funcs) - // Regex 2: .*(\/\*\!50003.*!50003+).* (Used by triggers) - // Regex 3: (\/\*\!50013.*DEFINER \*\/) (Used in schema) - // Regex 4: ^(.TRIGGER).(\x60.*) (Fix the create triggers) - - expressions := make([]string, 4) - 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[3] = `s/(^.TRIGGER).(\x60.*)/CREATE$1 $2/g` +func (c *Client) RemoveDefiners(filename string) { + expressions := make([]string, 1) + expressions[0] = `s/DEFINER=[^ ]* / /g` if !strings.Contains(filename, "data") { for _, re := range expressions {