Created
October 1, 2014 04:06
-
-
Save ShawnMilo/8df0afd9b4c426f99c74 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git migrate.go migrate.go | |
index 2659631..0ff1ada 100644 | |
--- migrate.go | |
+++ migrate.go | |
@@ -22,6 +22,14 @@ const ( | |
Down | |
) | |
+var tableName = "gorp_migrations" | |
+ | |
+func SetTable(name string) { | |
+ if name != "" { | |
+ tableName = name | |
+ } | |
+} | |
+ | |
type Migration struct { | |
Id string | |
Up []string | |
@@ -265,7 +273,8 @@ func PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationD | |
// Find the newest applied migration | |
var record MigrationRecord | |
- err = dbMap.SelectOne(&record, "SELECT * FROM gorp_migrations ORDER BY id DESC LIMIT 1") | |
+ query := fmt.Sprintf("SELECT * FROM %s ORDER BY id DESC LIMIT 1", tableName) | |
+ err = dbMap.SelectOne(&record, query) | |
if err != nil && err != sql.ErrNoRows { | |
return nil, nil, err | |
} | |
@@ -325,7 +334,8 @@ func GetMigrationRecords(db *sql.DB, dialect string) ([]*MigrationRecord, error) | |
} | |
var records []*MigrationRecord | |
- _, err = dbMap.Select(&records, "SELECT * FROM gorp_migrations ORDER BY id ASC") | |
+ query := fmt.Sprintf("SELECT * FROM %s ORDER BY id ASC", tableName) | |
+ _, err = dbMap.Select(&records, query) | |
if err != nil { | |
return nil, err | |
} | |
@@ -340,7 +350,7 @@ func getMigrationDbMap(db *sql.DB, dialect string) (*gorp.DbMap, error) { | |
} | |
dbMap := &gorp.DbMap{Db: db, Dialect: d} | |
- dbMap.AddTableWithName(MigrationRecord{}, "gorp_migrations").SetKeys(false, "Id") | |
+ dbMap.AddTableWithName(MigrationRecord{}, tableName).SetKeys(false, "Id") | |
//dbMap.TraceOn("", log.New(os.Stdout, "migrate: ", log.Lmicroseconds)) | |
return dbMap, nil | |
} | |
diff --git sql-migrate/command_common.go sql-migrate/command_common.go | |
index e5949c6..f6b0237 100644 | |
--- sql-migrate/command_common.go | |
+++ sql-migrate/command_common.go | |
@@ -17,6 +17,8 @@ func ApplyMigrations(dir migrate.MigrationDirection, dryrun bool, limit int) err | |
return err | |
} | |
+ migrate.SetTable(env.TableName) | |
+ | |
source := migrate.FileMigrationSource{ | |
Dir: env.Dir, | |
} | |
diff --git sql-migrate/config.go sql-migrate/config.go | |
index a560c55..9a12cf2 100644 | |
--- sql-migrate/config.go | |
+++ sql-migrate/config.go | |
@@ -33,6 +33,7 @@ type Environment struct { | |
Dialect string `yaml:"dialect"` | |
DataSource string `yaml:"datasource"` | |
Dir string `yaml:"dir"` | |
+ TableName string `yaml:"table"` | |
} | |
func ReadConfig() (map[string]*Environment, error) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment