Update formatting per PR comments

Also rename `VersionId` to `VersionID`
This commit is contained in:
Nicholas Duffy 2017-05-08 11:01:48 -06:00
parent 5ee045e0f9
commit abb2957c5d
7 changed files with 35 additions and 35 deletions

View File

@ -6,7 +6,7 @@ import (
"time"
)
// Create : Writes a new blank migration file.
// Create writes a new blank migration file.
func Create(db *sql.DB, dir, name, migrationType string) error {
path, err := CreateMigration(name, migrationType, dir, time.Now())
if err != nil {

View File

@ -5,7 +5,7 @@ import (
"fmt"
)
// SQLDialect : abstracts the details of specific SQL dialects
// SQLDialect abstracts the details of specific SQL dialects
// for goose's few SQL specific statements
type SQLDialect interface {
createVersionTableSQL() string // sql string to create the goose_db_version table
@ -15,12 +15,12 @@ type SQLDialect interface {
var dialect SQLDialect = &PostgresDialect{}
// GetDialect : Get the SQLDialect
// GetDialect gets the SQLDialect
func GetDialect() SQLDialect {
return dialect
}
// SetDialect : Set the SQLDialect
// SetDialect sets the SQLDialect
func SetDialect(d string) error {
switch d {
case "postgres":
@ -42,7 +42,7 @@ func SetDialect(d string) error {
// Postgres
////////////////////////////
// PostgresDialect : The PostgreSQL dialect struct.
// PostgresDialect struct.
type PostgresDialect struct{}
func (pg PostgresDialect) createVersionTableSQL() string {
@ -72,7 +72,7 @@ func (pg PostgresDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
// MySQL
////////////////////////////
// MySQLDialect : The MySQLDialect struct.
// MySQLDialect struct.
type MySQLDialect struct{}
func (m MySQLDialect) createVersionTableSQL() string {
@ -102,7 +102,7 @@ func (m MySQLDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
// sqlite3
////////////////////////////
// Sqlite3Dialect : The sqlite dialect struct.
// Sqlite3Dialect struct.
type Sqlite3Dialect struct{}
func (m Sqlite3Dialect) createVersionTableSQL() string {
@ -131,7 +131,7 @@ func (m Sqlite3Dialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
// Redshift
////////////////////////////
// RedshiftDialect : The Redshift dialect struct.
// RedshiftDialect struct.
type RedshiftDialect struct{}
func (rs RedshiftDialect) createVersionTableSQL() string {

View File

@ -5,7 +5,7 @@ import (
"fmt"
)
// Down : Roll back a single migration from the current version.
// Down rolls back a single migration from the current version.
func Down(db *sql.DB, dir string) error {
currentVersion, err := GetDBVersion(db)
if err != nil {
@ -25,7 +25,7 @@ func Down(db *sql.DB, dir string) error {
return current.Down(db)
}
// DownTo : Roll back migrations to a specific version.
// DownTo rolls back migrations to a specific version.
func DownTo(db *sql.DB, dir string, version int64) error {
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
if err != nil {

View File

@ -13,7 +13,7 @@ var (
maxVersion = int64((1 << 63) - 1)
)
// Run : Run a goose command.
// Run runs a goose command.
func Run(command string, db *sql.DB, dir string, args ...string) error {
switch command {
case "up":

View File

@ -11,17 +11,17 @@ import (
)
var (
// ErrNoCurrentVersion : Error when not find a current migration version.
// ErrNoCurrentVersion when a current migration version is not found.
ErrNoCurrentVersion = errors.New("no current version found")
// ErrNoNextVersion : Error when not find a next migration version.
// ErrNoNextVersion when the next migration version is not found.
ErrNoNextVersion = errors.New("no next version found")
// MaxVersion : The maximum allowed version.
// MaxVersion is the maximum allowed version.
MaxVersion int64 = 9223372036854775807 // max(int64)
goMigrations []*Migration
)
// Migrations : Slice of migrations.
// Migrations slice.
type Migrations []*Migration
// helpers so we can use pkg sort
@ -34,7 +34,7 @@ func (ms Migrations) Less(i, j int) bool {
return ms[i].Version < ms[j].Version
}
// Current : Get the current migration.
// Current gets the current migration.
func (ms Migrations) Current(current int64) (*Migration, error) {
for i, migration := range ms {
if migration.Version == current {
@ -45,7 +45,7 @@ func (ms Migrations) Current(current int64) (*Migration, error) {
return nil, ErrNoCurrentVersion
}
// Next : Get the next migration.
// Next gets the next migration.
func (ms Migrations) Next(current int64) (*Migration, error) {
for i, migration := range ms {
if migration.Version > current {
@ -67,7 +67,7 @@ func (ms Migrations) Previous(current int64) (*Migration, error) {
return nil, ErrNoNextVersion
}
// Last : Get the last migration.
// Last gets the last migration.
func (ms Migrations) Last() (*Migration, error) {
if len(ms) == 0 {
return nil, ErrNoNextVersion
@ -84,7 +84,7 @@ func (ms Migrations) String() string {
return str
}
// AddMigration : Add a migration.
// AddMigration adds a migration.
func AddMigration(up func(*sql.Tx) error, down func(*sql.Tx) error) {
_, filename, _, _ := runtime.Caller(1)
AddNamedMigration(filename, up, down)
@ -98,7 +98,7 @@ func AddNamedMigration(filename string, up func(*sql.Tx) error, down func(*sql.T
goMigrations = append(goMigrations, migration)
}
// CollectMigrations : Returns all the valid looking migration scripts in the
// CollectMigrations returns all the valid looking migration scripts in the
// migrations folder and go func registry, and key them by version.
func CollectMigrations(dirpath string, current, target int64) (Migrations, error) {
var migrations Migrations
@ -170,7 +170,7 @@ func versionFilter(v, current, target int64) bool {
return false
}
// EnsureDBVersion: Retrieve the current version for this DB.
// EnsureDBVersion retrieves the current version for this DB.
// Create and initialize the DB version table if it doesn't exist.
func EnsureDBVersion(db *sql.DB) (int64, error) {
rows, err := GetDialect().dbVersionQuery(db)
@ -187,14 +187,14 @@ func EnsureDBVersion(db *sql.DB) (int64, error) {
for rows.Next() {
var row MigrationRecord
if err = rows.Scan(&row.VersionId, &row.IsApplied); err != nil {
if err = rows.Scan(&row.VersionID, &row.IsApplied); err != nil {
log.Fatal("error scanning rows:", err)
}
// have we already marked this version to be skipped?
skip := false
for _, v := range toSkip {
if v == row.VersionId {
if v == row.VersionID {
skip = true
break
}
@ -206,11 +206,11 @@ func EnsureDBVersion(db *sql.DB) (int64, error) {
// if version has been applied we're done
if row.IsApplied {
return row.VersionId, nil
return row.VersionID, nil
}
// latest version of migration has not been applied.
toSkip = append(toSkip, row.VersionId)
toSkip = append(toSkip, row.VersionID)
}
return 0, ErrNoNextVersion
@ -241,7 +241,7 @@ func createVersionTable(db *sql.DB) error {
return txn.Commit()
}
// GetDBVersion : Wrapper for EnsureDBVersion for callers that don't already
// GetDBVersion is a wrapper for EnsureDBVersion for callers that don't already
// have their own DB instance
func GetDBVersion(db *sql.DB) (int64, error) {
version, err := EnsureDBVersion(db)

View File

@ -12,14 +12,14 @@ import (
"time"
)
// MigrationRecord : A migration record struct.
// MigrationRecord struct.
type MigrationRecord struct {
VersionId int64
VersionID int64
TStamp time.Time
IsApplied bool // was this a result of up() or down()
}
// Migration : The migration struct.
// Migration struct.
type Migration struct {
Version int64
Next int64 // next version, or -1 if none
@ -33,12 +33,12 @@ func (m *Migration) String() string {
return fmt.Sprintf(m.Source)
}
// Up : Run an up migration.
// Up runs an up migration.
func (m *Migration) Up(db *sql.DB) error {
return m.run(db, true)
}
// Down : Run a down migration.
// Down runs a down migration.
func (m *Migration) Down(db *sql.DB) error {
return m.run(db, false)
}
@ -78,7 +78,7 @@ func (m *Migration) run(db *sql.DB, direction bool) error {
return nil
}
// NumericComponent : look for migration scripts with names in the form:
// NumericComponent looks for migration scripts with names in the form:
// XXX_descriptivename.ext where XXX specifies the version number
// and ext specifies the type of migration
func NumericComponent(name string) (int64, error) {
@ -102,7 +102,7 @@ func NumericComponent(name string) (int64, error) {
return n, e
}
// CreateMigration : Create a migration.
// CreateMigration creates a migration.
func CreateMigration(name, migrationType, dir string, t time.Time) (path string, err error) {
if migrationType != "go" && migrationType != "sql" {
@ -123,7 +123,7 @@ func CreateMigration(name, migrationType, dir string, t time.Time) (path string,
return
}
// FinalizeMigration : Update the version table for the given migration,
// FinalizeMigration updates the version table for the given migration,
// and finalize the transaction.
func FinalizeMigration(tx *sql.Tx, direction bool, v int64) error {

View File

@ -5,7 +5,7 @@ import (
"fmt"
)
// Version : Print the current version of the database.
// Version prints the current version of the database.
func Version(db *sql.DB, dir string) error {
current, err := GetDBVersion(db)
if err != nil {