flags: improved option names

pull/2/head
Liam Staskawicz 2012-12-24 12:12:31 -08:00
parent 1232c87d8e
commit 9fbce90a79
3 changed files with 14 additions and 14 deletions

View File

@ -17,7 +17,7 @@ goose expects you to maintain a folder (typically called "db"), which contains t
* a dbconf.yml file that describes the database configurations you'd like to use * a dbconf.yml file that describes the database configurations you'd like to use
* a folder called "migrations" which contains .sql and/or .go scripts that implement your migrations * a folder called "migrations" which contains .sql and/or .go scripts that implement your migrations
You may use the `--db` option to specify an alternate location for the folder containing your config and migrations. You may use the `-path` option to specify an alternate location for the folder containing your config and migrations.
# Migrations # Migrations
@ -65,7 +65,7 @@ A sample Go migration looks like:
A transaction is provided, rather than the DB instance directly, since goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway. A transaction is provided, rather than the DB instance directly, since goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway.
## Database Configurations ## Database Environments
A sample dbconf.yml looks like A sample dbconf.yml looks like
@ -73,6 +73,6 @@ A sample dbconf.yml looks like
driver: postgres driver: postgres
open: user=liam dbname=tester sslmode=disable open: user=liam dbname=tester sslmode=disable
Here, `development` specifies the name of the configuration, and the `driver` and `open` elements are passed directly to database/sql to access the specified database. Here, `development` specifies the name of the environment, and the `driver` and `open` elements are passed directly to database/sql to access the specified database.
You may include as many configurations as you like, and you can use the `--config` command line option to specify which one to use. goose defaults to using a configuration called `development`. You may include as many configurations as you like, and you can use the `-env` command line option to specify which one to use. goose defaults to using a configuration called `development`.

View File

@ -8,12 +8,12 @@ import (
) )
// global options. available to any subcommands. // global options. available to any subcommands.
var dbFolder = flag.String("db", "db", "folder containing db info") var dbPath = flag.String("path", "db", "folder containing db info")
var dbConfName = flag.String("config", "development", "which DB configuration to use") var dbEnv = flag.String("env", "development", "which DB environment to use")
type DBConf struct { type DBConf struct {
MigrationsDir string MigrationsDir string
Name string Env string
Driver string Driver string
OpenStr string OpenStr string
} }
@ -21,26 +21,26 @@ type DBConf struct {
// extract configuration details from the given file // extract configuration details from the given file
func MakeDBConf() (*DBConf, error) { func MakeDBConf() (*DBConf, error) {
cfgFile := path.Join(*dbFolder, "dbconf.yml") cfgFile := path.Join(*dbPath, "dbconf.yml")
f, err := yaml.ReadFile(cfgFile) f, err := yaml.ReadFile(cfgFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }
drv, derr := f.Get(fmt.Sprintf("%s.driver", *dbConfName)) drv, derr := f.Get(fmt.Sprintf("%s.driver", *dbEnv))
if derr != nil { if derr != nil {
return nil, derr return nil, derr
} }
open, oerr := f.Get(fmt.Sprintf("%s.open", *dbConfName)) open, oerr := f.Get(fmt.Sprintf("%s.open", *dbEnv))
if oerr != nil { if oerr != nil {
return nil, oerr return nil, oerr
} }
return &DBConf{ return &DBConf{
MigrationsDir: path.Join(*dbFolder, "migrations"), MigrationsDir: path.Join(*dbPath, "migrations"),
Name: *dbConfName, Env: *dbEnv,
Driver: drv, Driver: drv,
OpenStr: open, OpenStr: open,
}, nil }, nil

View File

@ -55,8 +55,8 @@ func runMigrations(conf *DBConf, migrationsDir string, target int) {
return return
} }
fmt.Printf("goose: migrating db configuration '%v', current version: %d, target: %d\n", fmt.Printf("goose: migrating db environment '%v', current version: %d, target: %d\n",
conf.Name, current, target) conf.Env, current, target)
for _, v := range mm.Versions { for _, v := range mm.Versions {