Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skeleton code for 'migrate' command #39

Merged
merged 1 commit into from
Aug 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bee.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var commands = []*Command{
cmdVersion,
cmdGenerate,
cmdRundocs,
cmdMigrate,
}

func main() {
Expand Down
90 changes: 90 additions & 0 deletions migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2013 bee authors
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package main

import "os"

var cmdMigrate = &Command{
UsageLine: "migrate [Command]",
Short: "run database migrations",
Long: `
bee migrate
run all outstanding migrations

bee migrate rollback
rollback the last migration operation

bee migrate reset
rollback all migrations

bee migrate refresh
rollback all migrations and run them all again
`,
}

func init() {
cmdMigrate.Run = runMigration
}

func runMigration(cmd *Command, args []string) {
//curpath, _ := os.Getwd()

gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
os.Exit(2)
}

if len(args) == 0 {
// run all outstanding migrations
ColorLog("[INFO] running all outstanding migrations\n")
migrateUpdate()
} else {
mcmd := args[0]
switch mcmd {
case "rollback":
ColorLog("[INFO] rolling back the last migration operation\n")
migrateRollback()
case "reset":
ColorLog("[INFO] reseting all migrations\n")
migrateReset()
case "refresh":
ColorLog("[INFO] refreshing all migrations\n")
migrateReset()
default:
ColorLog("[ERRO] command is missing\n")
os.Exit(2)
}
ColorLog("[SUCC] migration successful!\n")
}
}

func migrateUpdate() {
println("=>update")
}

func migrateRollback() {
println("=>rollback")
}

func migrateReset() {
println("=>reset")
}

func migrateRefresh() {
println("=>refresh")
}