-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migrate): support migrate data to another storage
- Loading branch information
Showing
6 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package archive | ||
package migrate | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package migrate | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/fatih/color" | ||
"github.com/go-faster/errors" | ||
|
||
"github.com/iyear/tdl/pkg/kv" | ||
) | ||
|
||
func Migrate(ctx context.Context, to map[string]string) error { | ||
meta, err := kv.From(ctx).MigrateTo() | ||
if err != nil { | ||
return errors.Wrap(err, "read data") | ||
} | ||
|
||
dest, err := kv.NewWithMap(to) | ||
if err != nil { | ||
return errors.Wrap(err, "create dest storage") | ||
} | ||
|
||
var confirm bool | ||
if err = survey.AskOne(&survey.Confirm{ | ||
Message: "It will overwrite the namespace data in the destination storage, continue?", | ||
Default: false, | ||
}, &confirm); err != nil { | ||
return errors.Wrap(err, "confirm") | ||
} | ||
if !confirm { | ||
return nil | ||
} | ||
|
||
if err = dest.MigrateFrom(meta); err != nil { | ||
return errors.Wrap(err, "migrate from") | ||
} | ||
|
||
color.Green("Migrate successfully.") | ||
for ns := range meta { | ||
color.Green(" - %s", ns) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package archive | ||
package migrate | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters