fix: Multiline regex for definers. 🐛

Prevent missing SQL statements.
Added "_" to expression
This commit is contained in:
2024-09-05 14:15:42 +12:00
parent 0cbfb81096
commit d44cad5ebd

View File

@@ -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