4 Commits

Author SHA1 Message Date
0cbfb81096 fix: Spelling update/fixed zip creation. 🐛
All checks were successful
CI / build (push) Successful in 3m12s
closes #3
closes #1
2024-09-03 11:08:27 +12:00
254183ceff chore: Updated build actions for win/nix 🧑‍💻 2024-09-03 11:06:24 +12:00
676ed11c3f chore: TODO removed as function created 💡 2024-09-02 22:49:15 +12:00
5d9be49f6c fix: Schema and Host transposed in output 🐛 2024-09-02 22:45:19 +12:00
3 changed files with 26 additions and 17 deletions

View File

@@ -48,7 +48,7 @@ to quickly create a Cobra application.`,
return
}
fmt.Printf(
"%s combining dump files\n\r",
"%s Combining files\n\r",
style.Success(icon.Info),
)
@@ -65,7 +65,7 @@ to quickly create a Cobra application.`,
return
}
fmt.Printf(
"%s Completer combining dump files\n\r",
"%s Completed combining files\n\r",
style.Success(icon.Check),
)
fmt.Printf(

View File

@@ -99,8 +99,8 @@ func (c *Client) Dump() error {
// Construct schema output
fmt.Printf("%s Dumping schema %s from %s\n\r",
style.Success(icon.Info),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
)
response, err := exec.Command(c.executable,
@@ -126,15 +126,15 @@ func (c *Client) Dump() error {
fmt.Printf(
"%s Done dumping schema %s from %s\n\r",
style.Success(icon.Check),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
)
// Construct data output
fmt.Printf("%s Dumping data %s from %s\n\r",
style.Success(icon.Info),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
)
_ = exec.Command(c.executable,
@@ -151,15 +151,15 @@ func (c *Client) Dump() error {
fmt.Printf(
"%s Done dumping data %s from %s\n\r",
style.Success(icon.Check),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
)
// Construct routines/triggers output
fmt.Printf("%s Dumping routines %s from %s\n\r",
style.Success(icon.Info),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
lipgloss.NewStyle().Foreground(color.Yellow).Render(fmt.Sprint(c.databaseName)),
lipgloss.NewStyle().Foreground(color.Purple).Render(c.hostname),
)
_ = exec.Command(c.executable,
@@ -189,7 +189,7 @@ 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)
// TODO: Add routine body to strip definers.
expressions := make([]string, 3)
expressions[0] = `s/(^.*)(.DEFINER=[a-zA-Z0-9\x60%@]+)(.*)/$1$3/g`
expressions[1] = `s/(.*)(\/\*\!50003.*!50003+)(.*)/$1$3/g`
@@ -248,37 +248,46 @@ func (c *Client) Combine() (string, error) {
}
func ZipFile(filename string) (string, error) {
fmt.Println("creating zip archive")
//Create a new zip archive and named archive.zip
archive, err := os.Create(util.FileNameWithoutExt(filename) + ".zip")
if err != nil {
panic(err)
// this is to catch errors if any
}
defer archive.Close()
fmt.Println("archive file created successfully....")
_, file := filepath.Split(filename)
//Create a new zip writer
zipWriter := zip.NewWriter(archive)
fmt.Println("opening .sql file")
fmt.Printf(
"%s Opening .sql file\n\r",
style.Success(icon.Info),
)
f1, err := os.Open(filename)
if err != nil {
panic(err)
}
defer f1.Close()
fmt.Println("adding file to archive..")
w1, err := zipWriter.Create(filename)
fmt.Printf(
"%s Adding file to archive\n\r",
style.Success(icon.Info),
)
w1, err := zipWriter.Create(file)
if err != nil {
panic(err)
}
if _, err := io.Copy(w1, f1); err != nil {
panic(err)
}
fmt.Println("closing archive")
fmt.Printf(
"%s Closing archive\n\r",
style.Success(icon.Info),
)
zipWriter.Close()
f1.Close()
_ = os.Remove(filename)
os.Remove(filename)
return util.FileNameWithoutExt(filename) + ".zip", nil
}

View File

@@ -8,11 +8,11 @@ install:
build:
@echo -n "Building app ... "
@go build {{flags}} -o bin/ && echo "OK" || echo "FAILED"
@go build {{flags}} -o bin/gosqldump ./main.go && echo "OK" || echo "FAILED"
build-win:
@echo -n "Building app for windows ... "
@GOOS=windows GOARCH=amd64 go build {{flags}} -o bin/ && echo "OK" || echo "FAILED"
@GOOS=windows GOARCH=amd64 go build {{flags}} -o bin/gosqldump.exe ./main.go && echo "OK" || echo "FAILED"
update:
go get -u
go mod tidy -v