Skip to content

Commit

Permalink
fix: migration move db to data dir
Browse files Browse the repository at this point in the history
Signed-off-by: zu1k <i@zu1k.com>
  • Loading branch information
zu1k committed Oct 6, 2022
1 parent 5039161 commit 0631804
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/migration/v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ func migration2v6() {
_, err = os.Stat(oldDefaultWorkPath)
if err == nil {
println("Old data directories are detected and will attempt to migrate automatically")

oldDefaultConfigPath := filepath.Join(oldDefaultWorkPath, "config.yaml")
stat, err := os.Stat(oldDefaultConfigPath)
if err == nil {
if stat.Mode().IsRegular() {
_ = os.Rename(oldDefaultConfigPath, filepath.Join(constant.ConfigDirPath, "config.yaml"))
}
}

files, err := os.ReadDir(oldDefaultWorkPath)
if err == nil {
for _, file := range files {
if file.Type().IsRegular() {
_ = os.Rename(filepath.Join(oldDefaultWorkPath, file.Name()), filepath.Join(constant.ConfigDirPath, file.Name()))
_ = os.Rename(filepath.Join(oldDefaultWorkPath, file.Name()), filepath.Join(constant.DataDirPath, file.Name()))
}
}
}

err = os.RemoveAll(oldDefaultWorkPath)
if err != nil {
log.Errorf("Auto migration failed: %s\n", err)
Expand Down

0 comments on commit 0631804

Please sign in to comment.