From 31b481d96add3004bbaba31e0e2dee3c153867c9 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Thu, 7 Aug 2014 10:47:06 +0800 Subject: [PATCH] basic structure for generate migration files --- g.go | 13 +++++++++++++ g_migration.go | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 g_migration.go diff --git a/g.go b/g.go index 9b8444d..ff039ab 100644 --- a/g.go +++ b/g.go @@ -26,6 +26,9 @@ bee generate model [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test] [-leve -conn: the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test -level: [1 | 2 | 3], 1 = model; 2 = models,controller; 3 = models,controllers,router +bee generate migration [filename] + generate migration file for making database schema update + bee generate controller [modelfile] generate RESTFul controllers based on modelfile @@ -85,6 +88,16 @@ func generateCode(cmd *Command, args []string) { ColorLog("[INFO] Using '%s' as 'conn'\n", conn) ColorLog("[INFO] Using '%s' as 'level'\n", level) generateModel(string(driver), string(conn), string(level), curpath) + case "migration": + if len(args) == 2 { + filename := args[1] + ColorLog("[INFO] Using '%s' as migration file name\n", filename) + generateMigration(filename, curpath) + } else { + ColorLog("[ERRO] Wrong number of arguments\n") + ColorLog("[HINT] usage: bee generate migration [filename]\n") + os.Exit(2) + } default: ColorLog("[ERRO] command is missing\n") } diff --git a/g_migration.go b/g_migration.go new file mode 100644 index 0000000..0a301f0 --- /dev/null +++ b/g_migration.go @@ -0,0 +1,22 @@ +// 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 "fmt" + +func generateMigration(filename string, curpath string) { + fmt.Println("filename:", filename) + fmt.Println("curpath:", curpath) +}