Semantic updater and migrator for GoLang executables.
Updater aims to unify semantic migrations and executable updates using GitHub repositories in GoLang. You can seamlessly update executables and run any SQL database migrations that depend on the specific version of the application. Callbacks can be passed to each migration allowing you to edit environment variables, or a directory structure.
go get -u github.com/ainsleyclark/updaterMigrations are stored in memory, so you can call AddMigration from anywhere with a version number, SQL statement
(optional) and CallBack functions (optional). When Update() is called, migrations will run from the the base
version right up until the remote GitHub version.
func init() {
err := updater.AddMigration(&updater.Migration{
Version: "v0.0.2", // The version of the migration
SQL: strings.NewReader("UPDATE my_table SET 'title' WHERE id = 1"),
CallBackUp: func() error { return nil }, // Runs on up of migration.
CallBackDown: func() error { return nil }, // Runs on error of migration.
Stage: updater.Patch, // Can be Patch, Major or Minor.
})
if err != nil {
log.Fatal(err)
}
}To create an updater, simply call updater.New() with options Updater.Options{} The zip file is parsed with the
current version.
u, err := updater.New(updater.Options{
GithubURL: "https://github.com/ainsleyclark/my-repo", // The URL of the Git Repos
Version: "v0.0.1", // The currently running version
Verify: false, // Updates will be verified by checking the new exec with -version
DB: nil, // Pass in an sql.DB for a migration
})
if err != nil {
log.Fatal(err)
}
status, err := u.Update(fmt.Sprintf("my-repo_v0.0.2_%s_%s.zip", runtime.GOOS, runtime.GOARCH))
if err != nil {
return
}
fmt.Println(status)Shout out to go-rocket-update for providing an excellent API for self updating executables.