From 5aed294d259cae193c58beea5b43ac5ce691f3ba Mon Sep 17 00:00:00 2001
From: Frederik Galle <frederikgalle@fastmail.fm>
Date: Fri, 3 Feb 2017 12:47:24 +0100
Subject: [PATCH 01/23] Check version table existence for current schema

---
 driver/postgres/postgres.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/driver/postgres/postgres.go b/driver/postgres/postgres.go
index df38fde42..fc6e144f0 100644
--- a/driver/postgres/postgres.go
+++ b/driver/postgres/postgres.go
@@ -43,7 +43,7 @@ func (driver *Driver) Close() error {
 }
 
 func (driver *Driver) ensureVersionTableExists() error {
-	r := driver.db.QueryRow("SELECT count(*) FROM information_schema.tables WHERE table_name = $1;", tableName)
+	r := driver.db.QueryRow("SELECT count(*) FROM information_schema.tables WHERE table_name = $1 AND table_schema = (SELECT current_schema());", tableName)
 	c := 0
 	if err := r.Scan(&c); err != nil {
 		return err

From d2ad6f8ecf28a741162495edd2954fd428231b34 Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Fri, 10 Feb 2017 02:42:46 -0800
Subject: [PATCH 02/23] Update README.md

---
 README.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/README.md b/README.md
index b8642704a..d233696f6 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+__[v3.0 in the making](https://github.com/mattes/migrate/tree/v3.0-prev)__
+
+---
+
 # migrate
 
 [![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=master)](https://travis-ci.org/mattes/migrate)

From da12e27062e076288a3810b350a024778578c805 Mon Sep 17 00:00:00 2001
From: Pavel Sapezhko <pavel.sapezhko@synesis.ru>
Date: Fri, 17 Feb 2017 13:06:26 +0300
Subject: [PATCH 03/23] fix some lint errors

---
 driver/cassandra/cassandra.go                 |   8 +-
 driver/cassandra/cassandra_test.go            |  16 +-
 driver/crate/crate.go                         |   4 +-
 driver/driver.go                              |   2 +-
 driver/mongodb/example/mongodb_test.go        |   7 +-
 .../mongodb/example/sample_mongdb_migrator.go |   3 +-
 .../mongodb/gomethods/gomethods_migrator.go   |   5 +-
 .../mongodb/gomethods/gomethods_registry.go   |   3 +-
 driver/mongodb/mongodb.go                     |   5 +-
 driver/neo4j/neo4j.go                         | 241 +++++++++---------
 driver/postgres/postgres_test.go              |   8 +-
 driver/ql/ql.go                               |   9 +-
 driver/registry.go                            |   4 +-
 driver/sqlite3/sqlite3.go                     |   4 +-
 driver/sqlite3/sqlite3_test.go                |   4 +-
 file/file.go                                  |  13 +-
 file/file_test.go                             |  10 +-
 main.go                                       |  47 ++--
 migrate/direction/direction.go                |   7 +-
 migrate/migrate.go                            |  28 +-
 migrate/migrate_test.go                       | 116 ++++-----
 pipe/pipe.go                                  |  22 +-
 version.go                                    |   1 +
 23 files changed, 293 insertions(+), 274 deletions(-)

diff --git a/driver/cassandra/cassandra.go b/driver/cassandra/cassandra.go
index b91053c30..500d81f74 100644
--- a/driver/cassandra/cassandra.go
+++ b/driver/cassandra/cassandra.go
@@ -68,7 +68,8 @@ func (driver *Driver) Initialize(rawurl string) error {
 	cluster.Timeout = 1 * time.Minute
 
 	if len(u.Query().Get("consistency")) > 0 {
-		consistency, err := parseConsistency(u.Query().Get("consistency"))
+		var consistency gocql.Consistency
+		consistency, err = parseConsistency(u.Query().Get("consistency"))
 		if err != nil {
 			return err
 		}
@@ -77,7 +78,8 @@ func (driver *Driver) Initialize(rawurl string) error {
 	}
 
 	if len(u.Query().Get("protocol")) > 0 {
-		protoversion, err := strconv.Atoi(u.Query().Get("protocol"))
+		var protoversion int
+		protoversion, err = strconv.Atoi(u.Query().Get("protocol"))
 		if err != nil {
 			return err
 		}
@@ -90,7 +92,7 @@ func (driver *Driver) Initialize(rawurl string) error {
 		password, passwordSet := u.User.Password()
 
 		if passwordSet == false {
-			return fmt.Errorf("Missing password. Please provide password.")
+			return fmt.Errorf("Missing password. Please provide password")
 		}
 
 		cluster.Authenticator = gocql.PasswordAuthenticator{
diff --git a/driver/cassandra/cassandra_test.go b/driver/cassandra/cassandra_test.go
index 49024522f..7218ba23a 100644
--- a/driver/cassandra/cassandra_test.go
+++ b/driver/cassandra/cassandra_test.go
@@ -21,10 +21,10 @@ func TestMigrate(t *testing.T) {
 
 	host := os.Getenv("CASSANDRA_PORT_9042_TCP_ADDR")
 	port := os.Getenv("CASSANDRA_PORT_9042_TCP_PORT")
-	driverUrl := "cassandra://" + host + ":" + port + "/system"
+	driverURL := "cassandra://" + host + ":" + port + "/system"
 
 	// prepare a clean test database
-	u, err := url.Parse(driverUrl)
+	u, err := url.Parse(driverURL)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -35,23 +35,25 @@ func TestMigrate(t *testing.T) {
 	cluster.Timeout = 1 * time.Minute
 
 	session, err = cluster.CreateSession()
-
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	if err := session.Query(`DROP KEYSPACE IF EXISTS migrate;`).Exec(); err != nil {
+	if err = session.Query(`DROP KEYSPACE IF EXISTS migrate;`).Exec(); err != nil {
 		t.Fatal(err)
 	}
-	if err := session.Query(`CREATE KEYSPACE IF NOT EXISTS migrate WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};`).Exec(); err != nil {
+	if err = session.Query(`CREATE KEYSPACE IF NOT EXISTS migrate WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};`).Exec(); err != nil {
 		t.Fatal(err)
 	}
 	cluster.Keyspace = "migrate"
 	session, err = cluster.CreateSession()
-	driverUrl = "cassandra://" + host + ":" + port + "/migrate"
+	if err != nil {
+		t.Fatal(err)
+	}
+	driverURL = "cassandra://" + host + ":" + port + "/migrate"
 
 	d := &Driver{}
-	if err := d.Initialize(driverUrl); err != nil {
+	if err := d.Initialize(driverURL); err != nil {
 		t.Fatal(err)
 	}
 
diff --git a/driver/crate/crate.go b/driver/crate/crate.go
index eb30853a9..56fc50e9d 100644
--- a/driver/crate/crate.go
+++ b/driver/crate/crate.go
@@ -97,8 +97,8 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 func splitContent(content string) []string {
 	lines := strings.Split(content, ";")
 	resultLines := make([]string, 0, len(lines))
-	for i, line := range lines {
-		line = strings.Replace(lines[i], ";", "", -1)
+	for i := range lines {
+		line := strings.Replace(lines[i], ";", "", -1)
 		line = strings.TrimSpace(line)
 		if line != "" {
 			resultLines = append(resultLines, line)
diff --git a/driver/driver.go b/driver/driver.go
index e4ecb7837..2844e1a86 100644
--- a/driver/driver.go
+++ b/driver/driver.go
@@ -43,7 +43,7 @@ func New(url string) (Driver, error) {
 
 	d := GetDriver(u.Scheme)
 	if d == nil {
-		return nil, fmt.Errorf("Driver '%s' not found.", u.Scheme)
+		return nil, fmt.Errorf("Driver '%s' not found", u.Scheme)
 	}
 	verifyFilenameExtension(u.Scheme, d)
 	if err := d.Initialize(url); err != nil {
diff --git a/driver/mongodb/example/mongodb_test.go b/driver/mongodb/example/mongodb_test.go
index 86c37c006..6070ed73b 100644
--- a/driver/mongodb/example/mongodb_test.go
+++ b/driver/mongodb/example/mongodb_test.go
@@ -6,13 +6,14 @@ import (
 	"github.com/mattes/migrate/file"
 	"github.com/mattes/migrate/migrate/direction"
 
+	"os"
+	"reflect"
+	"time"
+
 	"github.com/mattes/migrate/driver"
 	"github.com/mattes/migrate/driver/mongodb"
 	"github.com/mattes/migrate/driver/mongodb/gomethods"
 	pipep "github.com/mattes/migrate/pipe"
-	"os"
-	"reflect"
-	"time"
 )
 
 type ExpectedMigrationResult struct {
diff --git a/driver/mongodb/example/sample_mongdb_migrator.go b/driver/mongodb/example/sample_mongdb_migrator.go
index 1ab1440ad..227874e7b 100644
--- a/driver/mongodb/example/sample_mongdb_migrator.go
+++ b/driver/mongodb/example/sample_mongdb_migrator.go
@@ -1,11 +1,12 @@
 package example
 
 import (
+	"time"
+
 	"github.com/mattes/migrate/driver/mongodb/gomethods"
 	_ "github.com/mattes/migrate/driver/mongodb/gomethods"
 	"gopkg.in/mgo.v2"
 	"gopkg.in/mgo.v2/bson"
-	"time"
 
 	"github.com/mattes/migrate/driver/mongodb"
 )
diff --git a/driver/mongodb/gomethods/gomethods_migrator.go b/driver/mongodb/gomethods/gomethods_migrator.go
index 97057ab52..d53f7d91a 100644
--- a/driver/mongodb/gomethods/gomethods_migrator.go
+++ b/driver/mongodb/gomethods/gomethods_migrator.go
@@ -3,11 +3,12 @@ package gomethods
 import (
 	"bufio"
 	"fmt"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
 	"os"
 	"path"
 	"strings"
+
+	"github.com/mattes/migrate/driver"
+	"github.com/mattes/migrate/file"
 )
 
 type MethodNotFoundError string
diff --git a/driver/mongodb/gomethods/gomethods_registry.go b/driver/mongodb/gomethods/gomethods_registry.go
index 418256fd4..d9a19eed8 100644
--- a/driver/mongodb/gomethods/gomethods_registry.go
+++ b/driver/mongodb/gomethods/gomethods_registry.go
@@ -2,8 +2,9 @@ package gomethods
 
 import (
 	"fmt"
-	"github.com/mattes/migrate/driver"
 	"sync"
+
+	"github.com/mattes/migrate/driver"
 )
 
 var methodsReceiversMu sync.Mutex
diff --git a/driver/mongodb/mongodb.go b/driver/mongodb/mongodb.go
index fcfae505d..473d2566f 100644
--- a/driver/mongodb/mongodb.go
+++ b/driver/mongodb/mongodb.go
@@ -2,14 +2,15 @@ package mongodb
 
 import (
 	"errors"
+	"reflect"
+	"strings"
+
 	"github.com/mattes/migrate/driver"
 	"github.com/mattes/migrate/driver/mongodb/gomethods"
 	"github.com/mattes/migrate/file"
 	"github.com/mattes/migrate/migrate/direction"
 	"gopkg.in/mgo.v2"
 	"gopkg.in/mgo.v2/bson"
-	"reflect"
-	"strings"
 )
 
 type UnregisteredMethodsReceiverError string
diff --git a/driver/neo4j/neo4j.go b/driver/neo4j/neo4j.go
index 9670abeb3..6446473ab 100644
--- a/driver/neo4j/neo4j.go
+++ b/driver/neo4j/neo4j.go
@@ -2,156 +2,165 @@
 package neo4j
 
 import (
-  "fmt"
-  "bytes"
-  "strings"
-  "errors"
-  "github.com/jmcvetta/neoism"
-  "github.com/mattes/migrate/driver"
-  "github.com/mattes/migrate/file"
-  "github.com/mattes/migrate/migrate/direction"
+	"bytes"
+	"errors"
+	"fmt"
+	"github.com/jmcvetta/neoism"
+	"github.com/mattes/migrate/driver"
+	"github.com/mattes/migrate/file"
+	"github.com/mattes/migrate/migrate/direction"
+	"strings"
 )
 
 type Driver struct {
-  db *neoism.Database
+	db *neoism.Database
 }
 
 const labelName = "SchemaMigration"
 
 func (driver *Driver) Initialize(url string) error {
-  url = strings.Replace(url,"neo4j","http",1)
+	url = strings.Replace(url, "neo4j", "http", 1)
 
-  db, err := neoism.Connect(url)
-  if err != nil {
-    return err
-  }
+	db, err := neoism.Connect(url)
+	if err != nil {
+		return err
+	}
 
-  driver.db = db
+	driver.db = db
 
-  if err := driver.ensureVersionConstraintExists(); err != nil {
-    return err
-  }
-  return nil
+	if err := driver.ensureVersionConstraintExists(); err != nil {
+		return err
+	}
+	return nil
 }
 
 func (driver *Driver) Close() error {
-  driver.db = nil
-  return nil
+	driver.db = nil
+	return nil
 }
 
 func (driver *Driver) FilenameExtension() string {
-  return "cql"
+	return "cql"
 }
 
 func (driver *Driver) ensureVersionConstraintExists() error {
-  uc, _ := driver.db.UniqueConstraints("SchemaMigration", "version")
-  if len(uc) == 0 {
-    _, err := driver.db.CreateUniqueConstraint("SchemaMigration", "version")
-    return err
-  }
-  return nil
+	uc, _ := driver.db.UniqueConstraints("SchemaMigration", "version")
+	if len(uc) == 0 {
+		_, err := driver.db.CreateUniqueConstraint("SchemaMigration", "version")
+		return err
+	}
+	return nil
 }
 
 func (driver *Driver) setVersion(d direction.Direction, v uint64, invert bool) error {
 
-  cqUp := neoism.CypherQuery {
-    Statement: `CREATE (n:SchemaMigration {version: {Version}}) RETURN n`,
-    Parameters: neoism.Props{"Version": v},
-  }
-
-  cqDown := neoism.CypherQuery {
-    Statement: `MATCH (n:SchemaMigration {version: {Version}}) DELETE n`,
-    Parameters: neoism.Props{"Version": v},
-  }
-
-  var cq neoism.CypherQuery
-  switch d {
-  case direction.Up:
-    if invert { cq = cqDown } else { cq = cqUp }
-  case direction.Down:
-    if invert { cq = cqUp } else { cq = cqDown }
-  }
-  return driver.db.Cypher(&cq)
+	cqUp := neoism.CypherQuery{
+		Statement:  `CREATE (n:SchemaMigration {version: {Version}}) RETURN n`,
+		Parameters: neoism.Props{"Version": v},
+	}
+
+	cqDown := neoism.CypherQuery{
+		Statement:  `MATCH (n:SchemaMigration {version: {Version}}) DELETE n`,
+		Parameters: neoism.Props{"Version": v},
+	}
+
+	var cq neoism.CypherQuery
+	switch d {
+	case direction.Up:
+		if invert {
+			cq = cqDown
+		} else {
+			cq = cqUp
+		}
+	case direction.Down:
+		if invert {
+			cq = cqUp
+		} else {
+			cq = cqDown
+		}
+	}
+	return driver.db.Cypher(&cq)
 }
 
 func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
-  var err error
-
-  defer func() {
-    if err != nil {
-      // Invert version direction if we couldn't apply the changes for some reason.
-      if err := driver.setVersion(f.Direction, f.Version, true); err != nil {
-        pipe <- err
-      }
-      pipe <- err
-    }
-    close(pipe)
-  }()
-
-  pipe <- f
-
-
-  if err = driver.setVersion(f.Direction, f.Version, false); err != nil {
-    pipe <- err
-    return
-  }
-
-  if err = f.ReadContent(); err != nil {
-    pipe <- err
-    return
-  }
-
-  cQueries := []*neoism.CypherQuery{}
-
-  // Neoism doesn't support multiple statements per query.
-  cqlStmts := bytes.Split(f.Content, []byte(";"))
-
-  for _, cqlStmt := range cqlStmts {
-    cqlStmt = bytes.TrimSpace(cqlStmt)
-    if len(cqlStmt) > 0 {
-      cq := neoism.CypherQuery{Statement: string(cqlStmt)}
-      cQueries = append( cQueries, &cq )
-    }
-  }
-
-  var tx *neoism.Tx
-
-  tx, err = driver.db.Begin(cQueries)
-  if err != nil {
-    pipe <- err
-    for _, err := range tx.Errors {
-      pipe <- errors.New(fmt.Sprintf("%v", err.Message))
-    }
-    if err = tx.Rollback(); err != nil {
-      pipe <- err
-    }
-    return
-  }
-
-  if err = tx.Commit(); err != nil {
-    pipe <- err
-    for _, err := range tx.Errors {
-      pipe <- errors.New(fmt.Sprintf("%v", err.Message))
-    }
-    return
-  }
+	var err error
+
+	defer func() {
+		if err != nil {
+			// Invert version direction if we couldn't apply the changes for some reason.
+			if err := driver.setVersion(f.Direction, f.Version, true); err != nil {
+				pipe <- err
+			}
+			pipe <- err
+		}
+		close(pipe)
+	}()
+
+	pipe <- f
+
+	if err = driver.setVersion(f.Direction, f.Version, false); err != nil {
+		pipe <- err
+		return
+	}
+
+	if err = f.ReadContent(); err != nil {
+		pipe <- err
+		return
+	}
+
+	cQueries := []*neoism.CypherQuery{}
+
+	// Neoism doesn't support multiple statements per query.
+	cqlStmts := bytes.Split(f.Content, []byte(";"))
+
+	for _, cqlStmt := range cqlStmts {
+		cqlStmt = bytes.TrimSpace(cqlStmt)
+		if len(cqlStmt) > 0 {
+			cq := neoism.CypherQuery{Statement: string(cqlStmt)}
+			cQueries = append(cQueries, &cq)
+		}
+	}
+
+	var tx *neoism.Tx
+
+	tx, err = driver.db.Begin(cQueries)
+	if err != nil {
+		pipe <- err
+		for _, err := range tx.Errors {
+			pipe <- errors.New(fmt.Sprintf("%v", err.Message))
+		}
+		if err = tx.Rollback(); err != nil {
+			pipe <- err
+		}
+		return
+	}
+
+	if err = tx.Commit(); err != nil {
+		pipe <- err
+		for _, err := range tx.Errors {
+			pipe <- errors.New(fmt.Sprintf("%v", err.Message))
+		}
+		return
+	}
 }
 
 func (driver *Driver) Version() (uint64, error) {
-  res := []struct {Version uint64 `json:"n.version"`}{}
+	res := []struct {
+		Version uint64 `json:"n.version"`
+	}{}
 
-  cq := neoism.CypherQuery{
-    Statement: `MATCH (n:SchemaMigration)
+	cq := neoism.CypherQuery{
+		Statement: `MATCH (n:SchemaMigration)
       RETURN n.version ORDER BY n.version DESC LIMIT 1`,
-    Result:     &res,
-  }
+		Result: &res,
+	}
 
-  if err := driver.db.Cypher(&cq); err != nil || len(res) == 0 {
-    return 0, err
-  }
-  return res[0].Version, nil
+	if err := driver.db.Cypher(&cq); err != nil || len(res) == 0 {
+		return 0, err
+	}
+	return res[0].Version, nil
 }
 
 func init() {
-  driver.RegisterDriver("neo4j", &Driver{})
+	driver.RegisterDriver("neo4j", &Driver{})
 }
diff --git a/driver/postgres/postgres_test.go b/driver/postgres/postgres_test.go
index df3d3586a..1a5c4d7cb 100644
--- a/driver/postgres/postgres_test.go
+++ b/driver/postgres/postgres_test.go
@@ -19,10 +19,10 @@ func TestMigrate(t *testing.T) {
 
 	host := os.Getenv("POSTGRES_PORT_5432_TCP_ADDR")
 	port := os.Getenv("POSTGRES_PORT_5432_TCP_PORT")
-	driverUrl := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable"
+	driverURL := "postgres://postgres@" + host + ":" + port + "/template1?sslmode=disable"
 
 	// prepare clean database
-	connection, err := sql.Open("postgres", driverUrl)
+	connection, err := sql.Open("postgres", driverURL)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -33,12 +33,12 @@ func TestMigrate(t *testing.T) {
 	}
 
 	d := &Driver{}
-	if err := d.Initialize(driverUrl); err != nil {
+	if err := d.Initialize(driverURL); err != nil {
 		t.Fatal(err)
 	}
 
 	// testing idempotency: second call should be a no-op, since table already exists
-	if err := d.Initialize(driverUrl); err != nil {
+	if err := d.Initialize(driverURL); err != nil {
 		t.Fatal(err)
 	}
 
diff --git a/driver/ql/ql.go b/driver/ql/ql.go
index 1c75fe709..898ed7d25 100644
--- a/driver/ql/ql.go
+++ b/driver/ql/ql.go
@@ -3,13 +3,14 @@ package ql
 import (
 	"database/sql"
 
-	"github.com/mattes/migrate/file"
 	"github.com/mattes/migrate/driver"
+	"github.com/mattes/migrate/file"
 	"github.com/mattes/migrate/migrate/direction"
 
-	_ "github.com/cznic/ql/driver"
-	"strings"
 	"fmt"
+	"strings"
+
+	_ "github.com/cznic/ql/driver"
 )
 
 const tableName = "schema_migration"
@@ -127,4 +128,4 @@ func (d *Driver) ensureVersionTableExists() error {
 func init() {
 	driver.RegisterDriver("ql+file", &Driver{})
 	driver.RegisterDriver("ql+memory", &Driver{})
-}
\ No newline at end of file
+}
diff --git a/driver/registry.go b/driver/registry.go
index 638891849..0a90e38c9 100644
--- a/driver/registry.go
+++ b/driver/registry.go
@@ -8,7 +8,7 @@ import (
 var driversMu sync.Mutex
 var drivers = make(map[string]Driver)
 
-// Registers a driver so it can be created from its name. Drivers should
+// RegisterDriver register a driver so it can be created from its name. Drivers should
 // call this from an init() function so that they registers themselves on
 // import
 func RegisterDriver(name string, driver Driver) {
@@ -23,7 +23,7 @@ func RegisterDriver(name string, driver Driver) {
 	drivers[name] = driver
 }
 
-// Retrieves a registered driver by name
+// GetDriver retrieves a registered driver by name
 func GetDriver(name string) Driver {
 	driversMu.Lock()
 	defer driversMu.Unlock()
diff --git a/driver/sqlite3/sqlite3.go b/driver/sqlite3/sqlite3.go
index a92b14d87..b245eb187 100644
--- a/driver/sqlite3/sqlite3.go
+++ b/driver/sqlite3/sqlite3.go
@@ -96,9 +96,9 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 
 		if isErr {
 			// The sqlite3 library only provides error codes, not position information. Output what we do know
-			pipe <- errors.New(fmt.Sprintf("SQLite Error (%s); Extended (%s)\nError: %s", sqliteErr.Code.Error(), sqliteErr.ExtendedCode.Error(), sqliteErr.Error()))
+			pipe <- fmt.Errorf("SQLite Error (%s); Extended (%s)\nError: %s", sqliteErr.Code.Error(), sqliteErr.ExtendedCode.Error(), sqliteErr.Error())
 		} else {
-			pipe <- errors.New(fmt.Sprintf("An error occurred: %s", err.Error()))
+			pipe <- fmt.Errorf("An error occurred: %s", err.Error())
 		}
 
 		if err := tx.Rollback(); err != nil {
diff --git a/driver/sqlite3/sqlite3_test.go b/driver/sqlite3/sqlite3_test.go
index 7f50095a2..57dc77928 100644
--- a/driver/sqlite3/sqlite3_test.go
+++ b/driver/sqlite3/sqlite3_test.go
@@ -17,7 +17,7 @@ func TestMigrate(t *testing.T) {
 	}
 
 	driverFile := ":memory:"
-	driverUrl := "sqlite3://" + driverFile
+	driverURL := "sqlite3://" + driverFile
 
 	// prepare clean database
 	connection, err := sql.Open("sqlite3", driverFile)
@@ -31,7 +31,7 @@ func TestMigrate(t *testing.T) {
 	}
 
 	d := &Driver{}
-	if err := d.Initialize(driverUrl); err != nil {
+	if err := d.Initialize(driverURL); err != nil {
 		t.Fatal(err)
 	}
 
diff --git a/file/file.go b/file/file.go
index 54992a48b..ccda7d6b0 100644
--- a/file/file.go
+++ b/file/file.go
@@ -5,7 +5,6 @@ import (
 	"bytes"
 	"errors"
 	"fmt"
-	"github.com/mattes/migrate/migrate/direction"
 	"go/token"
 	"io/ioutil"
 	"path"
@@ -13,6 +12,8 @@ import (
 	"sort"
 	"strconv"
 	"strings"
+
+	"github.com/mattes/migrate/migrate/direction"
 )
 
 var filenameRegex = `^([0-9]+)_(.*)\.(up|down)\.%s$`
@@ -137,10 +138,10 @@ func (mf *MigrationFiles) From(version uint64, relativeN int) (Files, error) {
 
 			if d == direction.Up && migrationFile.Version > version && migrationFile.UpFile != nil {
 				files = append(files, *migrationFile.UpFile)
-				counter -= 1
+				counter--
 			} else if d == direction.Down && migrationFile.Version <= version && migrationFile.DownFile != nil {
 				files = append(files, *migrationFile.DownFile)
-				counter -= 1
+				counter--
 			}
 		} else {
 			break
@@ -258,7 +259,7 @@ func parseFilenameSchema(filename string, filenameRegex *regexp.Regexp) (version
 
 	version, err = strconv.ParseUint(matches[1], 10, 0)
 	if err != nil {
-		return 0, "", 0, errors.New(fmt.Sprintf("Unable to parse version '%v' in filename schema", matches[0]))
+		return 0, "", 0, fmt.Errorf("Unable to parse version '%v' in filename schema", matches[0])
 	}
 
 	if matches[3] == "up" {
@@ -266,7 +267,7 @@ func parseFilenameSchema(filename string, filenameRegex *regexp.Regexp) (version
 	} else if matches[3] == "down" {
 		d = direction.Down
 	} else {
-		return 0, "", 0, errors.New(fmt.Sprintf("Unable to parse up|down '%v' in filename schema", matches[3]))
+		return 0, "", 0, fmt.Errorf("Unable to parse up|down '%v' in filename schema", matches[3])
 	}
 
 	return version, matches[2], d, nil
@@ -333,7 +334,7 @@ func LinesBeforeAndAfter(data []byte, line, before, after int, lineNumbers bool)
 			lNew = append([]byte(lineCounterStr+": "), lNew...)
 		}
 		newLines = append(newLines, lNew)
-		lineCounter += 1
+		lineCounter++
 	}
 
 	return bytes.Join(newLines, []byte("\n"))
diff --git a/file/file_test.go b/file/file_test.go
index b9ddeabd8..b55f05c8e 100644
--- a/file/file_test.go
+++ b/file/file_test.go
@@ -1,11 +1,12 @@
 package file
 
 import (
-	"github.com/mattes/migrate/migrate/direction"
 	"io/ioutil"
 	"os"
 	"path"
 	"testing"
+
+	"github.com/mattes/migrate/migrate/direction"
 )
 
 func TestParseFilenameSchema(t *testing.T) {
@@ -61,7 +62,7 @@ func TestFiles(t *testing.T) {
 	}
 	defer os.RemoveAll(tmpdir)
 
-	if err := ioutil.WriteFile(path.Join(tmpdir, "nonsense.txt"), nil, 0755); err != nil {
+	if err = ioutil.WriteFile(path.Join(tmpdir, "nonsense.txt"), nil, 0755); err != nil {
 		t.Fatal("Unable to write files in tmpdir", err)
 	}
 	ioutil.WriteFile(path.Join(tmpdir, "002_migrationfile.up.sql"), nil, 0755)
@@ -133,7 +134,7 @@ func TestFiles(t *testing.T) {
 	}
 
 	// test read
-	if err := files[4].DownFile.ReadContent(); err != nil {
+	if err = files[4].DownFile.ReadContent(); err != nil {
 		t.Error("Unable to read file", err)
 	}
 	if files[4].DownFile.Content == nil {
@@ -169,7 +170,8 @@ func TestFiles(t *testing.T) {
 	}
 
 	for _, test := range tests {
-		rangeFiles, err := files.From(test.from, test.relative)
+		var rangeFiles Files
+		rangeFiles, err = files.From(test.from, test.relative)
 		if err != nil {
 			t.Error("Unable to fetch range:", err)
 		}
diff --git a/main.go b/main.go
index 673102649..06cbfac05 100644
--- a/main.go
+++ b/main.go
@@ -176,32 +176,31 @@ func writePipe(pipe chan interface{}) (ok bool) {
 			case item, more := <-pipe:
 				if !more {
 					return okFlag
-				} else {
-					switch item.(type) {
-
-					case string:
-						fmt.Println(item.(string))
-
-					case error:
+				}
+				switch item.(type) {
+
+				case string:
+					fmt.Println(item.(string))
+
+				case error:
+					c := color.New(color.FgRed)
+					c.Printf("%s\n\n", item.(error).Error())
+					okFlag = false
+
+				case file.File:
+					f := item.(file.File)
+					if f.Direction == direction.Up {
+						c := color.New(color.FgGreen)
+						c.Print(">")
+					} else if f.Direction == direction.Down {
 						c := color.New(color.FgRed)
-						c.Println(item.(error).Error(), "\n")
-						okFlag = false
-
-					case file.File:
-						f := item.(file.File)
-						if f.Direction == direction.Up {
-							c := color.New(color.FgGreen)
-							c.Print(">")
-						} else if f.Direction == direction.Down {
-							c := color.New(color.FgRed)
-							c.Print("<")
-						}
-						fmt.Printf(" %s\n", f.FileName)
-
-					default:
-						text := fmt.Sprint(item)
-						fmt.Println(text)
+						c.Print("<")
 					}
+					fmt.Printf(" %s\n", f.FileName)
+
+				default:
+					text := fmt.Sprint(item)
+					fmt.Println(text)
 				}
 			}
 		}
diff --git a/migrate/direction/direction.go b/migrate/direction/direction.go
index ed5e5ece4..9516636ec 100644
--- a/migrate/direction/direction.go
+++ b/migrate/direction/direction.go
@@ -1,9 +1,12 @@
 // Package direction just holds convenience constants for Up and Down migrations.
 package direction
 
+// Direction - type that indicates direction of migration(up or down)
 type Direction int
 
 const (
-	Up   Direction = +1
-	Down           = -1
+	// Up - up migration
+	Up Direction = +1
+	// Down - down migration
+	Down Direction = -1
 )
diff --git a/migrate/migrate.go b/migrate/migrate.go
index 0c976be9c..3a9aa1b1a 100644
--- a/migrate/migrate.go
+++ b/migrate/migrate.go
@@ -51,13 +51,12 @@ func Up(pipe chan interface{}, url, migrationsPath string) {
 		}
 		go pipep.Close(pipe, nil)
 		return
-	} else {
-		if err := d.Close(); err != nil {
-			pipe <- err
-		}
-		go pipep.Close(pipe, nil)
-		return
 	}
+	if err := d.Close(); err != nil {
+		pipe <- err
+	}
+	go pipep.Close(pipe, nil)
+	return
 }
 
 // UpSync is synchronous version of Up
@@ -101,13 +100,12 @@ func Down(pipe chan interface{}, url, migrationsPath string) {
 		}
 		go pipep.Close(pipe, nil)
 		return
-	} else {
-		if err2 := d.Close(); err2 != nil {
-			pipe <- err2
-		}
-		go pipep.Close(pipe, nil)
-		return
 	}
+	if err2 := d.Close(); err2 != nil {
+		pipe <- err2
+	}
+	go pipep.Close(pipe, nil)
+	return
 }
 
 // DownSync is synchronous version of Down
@@ -129,9 +127,8 @@ func Redo(pipe chan interface{}, url, migrationsPath string) {
 	if ok := pipep.WaitAndRedirect(pipe1, pipe, signals); !ok {
 		go pipep.Close(pipe, nil)
 		return
-	} else {
-		go Migrate(pipe, url, migrationsPath, +1)
 	}
+	go Migrate(pipe, url, migrationsPath, +1)
 }
 
 // RedoSync is synchronous version of Redo
@@ -153,9 +150,8 @@ func Reset(pipe chan interface{}, url, migrationsPath string) {
 	if ok := pipep.WaitAndRedirect(pipe1, pipe, signals); !ok {
 		go pipep.Close(pipe, nil)
 		return
-	} else {
-		go Up(pipe, url, migrationsPath)
 	}
+	go Up(pipe, url, migrationsPath)
 }
 
 // ResetSync is synchronous version of Reset
diff --git a/migrate/migrate_test.go b/migrate/migrate_test.go
index c7b43adb4..8801ff81b 100644
--- a/migrate/migrate_test.go
+++ b/migrate/migrate_test.go
@@ -9,18 +9,18 @@ import (
 	// Ensure imports for each driver we wish to test
 
 	_ "github.com/mattes/migrate/driver/postgres"
-	_ "github.com/mattes/migrate/driver/sqlite3"
 	_ "github.com/mattes/migrate/driver/ql"
+	_ "github.com/mattes/migrate/driver/sqlite3"
 )
 
 // Add Driver URLs here to test basic Up, Down, .. functions.
-var driverUrls = []string{
+var driverURLs = []string{
 	"postgres://postgres@" + os.Getenv("POSTGRES_PORT_5432_TCP_ADDR") + ":" + os.Getenv("POSTGRES_PORT_5432_TCP_PORT") + "/template1?sslmode=disable",
 	"ql+file://./test.db",
 }
 
-func tearDown(driverUrl, tmpdir string) {
-	DownSync(driverUrl, tmpdir)
+func tearDown(driverURL, tmpdir string) {
+	DownSync(driverURL, tmpdir)
 	os.RemoveAll(tmpdir)
 }
 
@@ -28,18 +28,18 @@ func TestCreate(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		if _, err := Create(driverUrl, tmpdir, "test_migration"); err != nil {
+		if _, err = Create(driverURL, tmpdir, "test_migration"); err != nil {
 			t.Fatal(err)
 		}
-		if _, err := Create(driverUrl, tmpdir, "another migration"); err != nil {
+		if _, err = Create(driverURL, tmpdir, "another migration"); err != nil {
 			t.Fatal(err)
 		}
 
@@ -83,25 +83,25 @@ func TestReset(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		Create(driverUrl, tmpdir, "migration1")
-		f, err := Create(driverUrl, tmpdir, "migration2")
+		Create(driverURL, tmpdir, "migration1")
+		f, err := Create(driverURL, tmpdir, "migration2")
 		if err != nil {
 			t.Fatal(err)
 		}
 
-		if err, ok := ResetSync(driverUrl, tmpdir); !ok {
+		if err, ok := ResetSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != f.Version {
 			t.Fatalf("Expected version %v, got %v", version, f.Version)
@@ -113,36 +113,36 @@ func TestDown(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		initVersion, _ := Version(driverUrl, tmpdir)
+		initVersion, _ := Version(driverURL, tmpdir)
 
-		firstMigration, _ := Create(driverUrl, tmpdir, "migration1")
-		secondMigration, _ := Create(driverUrl, tmpdir, "migration2")
+		firstMigration, _ := Create(driverURL, tmpdir, "migration1")
+		secondMigration, _ := Create(driverURL, tmpdir, "migration2")
 
 		t.Logf("init %v first %v second %v", initVersion, firstMigration.Version, secondMigration.Version)
 
-		if err, ok := ResetSync(driverUrl, tmpdir); !ok {
+		if err, ok := ResetSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != secondMigration.Version {
 			t.Fatalf("Expected version %v, got %v", version, secondMigration.Version)
 		}
 
-		if err, ok := DownSync(driverUrl, tmpdir); !ok {
+		if err, ok := DownSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != 0 {
 			t.Fatalf("Expected 0, got %v", version)
@@ -154,36 +154,36 @@ func TestUp(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		initVersion, _ := Version(driverUrl, tmpdir)
+		initVersion, _ := Version(driverURL, tmpdir)
 
-		firstMigration, _ := Create(driverUrl, tmpdir, "migration1")
-		secondMigration, _ := Create(driverUrl, tmpdir, "migration2")
+		firstMigration, _ := Create(driverURL, tmpdir, "migration1")
+		secondMigration, _ := Create(driverURL, tmpdir, "migration2")
 
 		t.Logf("init %v first %v second %v", initVersion, firstMigration.Version, secondMigration.Version)
 
-		if err, ok := DownSync(driverUrl, tmpdir); !ok {
+		if err, ok := DownSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != initVersion {
 			t.Fatalf("Expected initial version %v, got %v", initVersion, version)
 		}
 
-		if err, ok := UpSync(driverUrl, tmpdir); !ok {
+		if err, ok := UpSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != secondMigration.Version {
 			t.Fatalf("Expected migrated version %v, got %v", secondMigration.Version, version)
@@ -195,36 +195,36 @@ func TestRedo(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		initVersion, _ := Version(driverUrl, tmpdir)
+		initVersion, _ := Version(driverURL, tmpdir)
 
-		firstMigration, _ := Create(driverUrl, tmpdir, "migration1")
-		secondMigration, _ := Create(driverUrl, tmpdir, "migration2")
+		firstMigration, _ := Create(driverURL, tmpdir, "migration1")
+		secondMigration, _ := Create(driverURL, tmpdir, "migration2")
 
 		t.Logf("init %v first %v second %v", initVersion, firstMigration.Version, secondMigration.Version)
 
-		if err, ok := ResetSync(driverUrl, tmpdir); !ok {
+		if err, ok := ResetSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != secondMigration.Version {
 			t.Fatalf("Expected migrated version %v, got %v", secondMigration.Version, version)
 		}
 
-		if err, ok := RedoSync(driverUrl, tmpdir); !ok {
+		if err, ok := RedoSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != secondMigration.Version {
 			t.Fatalf("Expected migrated version %v, got %v", secondMigration.Version, version)
@@ -236,46 +236,46 @@ func TestMigrate(t *testing.T) {
 	if testing.Short() {
 		t.Skip("skipping test in short mode.")
 	}
-	for _, driverUrl := range driverUrls {
-		t.Logf("Test driver: %s", driverUrl)
+	for _, driverURL := range driverURLs {
+		t.Logf("Test driver: %s", driverURL)
 		tmpdir, err := ioutil.TempDir("/tmp", "migrate-test")
 		if err != nil {
 			t.Fatal(err)
 		}
-		defer tearDown(driverUrl, tmpdir)
+		defer tearDown(driverURL, tmpdir)
 
-		initVersion, _ := Version(driverUrl, tmpdir)
+		initVersion, _ := Version(driverURL, tmpdir)
 
-		firstMigration, _ := Create(driverUrl, tmpdir, "migration1")
-		secondMigration, _ := Create(driverUrl, tmpdir, "migration2")
+		firstMigration, _ := Create(driverURL, tmpdir, "migration1")
+		secondMigration, _ := Create(driverURL, tmpdir, "migration2")
 
 		t.Logf("init %v first %v second %v", initVersion, firstMigration.Version, secondMigration.Version)
 
-		if err, ok := ResetSync(driverUrl, tmpdir); !ok {
+		if err, ok := ResetSync(driverURL, tmpdir); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != secondMigration.Version {
 			t.Fatalf("Expected migrated version %v, got %v", secondMigration.Version, version)
 		}
 
-		if err, ok := MigrateSync(driverUrl, tmpdir, -2); !ok {
+		if err, ok := MigrateSync(driverURL, tmpdir, -2); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != 0 {
 			t.Fatalf("Expected 0, got %v", version)
 		}
 
-		if err, ok := MigrateSync(driverUrl, tmpdir, +1); !ok {
+		if err, ok := MigrateSync(driverURL, tmpdir, +1); !ok {
 			t.Fatal(err)
 		}
 
-		if version, err := Version(driverUrl, tmpdir); err != nil {
+		if version, err := Version(driverURL, tmpdir); err != nil {
 			t.Fatal(err)
 		} else if version != firstMigration.Version {
 			t.Fatalf("Expected first version %v, got %v", firstMigration.Version, version)
diff --git a/pipe/pipe.go b/pipe/pipe.go
index 02979fc92..3888b352b 100644
--- a/pipe/pipe.go
+++ b/pipe/pipe.go
@@ -32,7 +32,7 @@ func WaitAndRedirect(pipe, redirectPipe chan interface{}, interrupt chan os.Sign
 			select {
 
 			case <-interrupt:
-				interruptsReceived += 1
+				interruptsReceived++
 				if interruptsReceived > 1 {
 					os.Exit(5)
 				} else {
@@ -43,12 +43,11 @@ func WaitAndRedirect(pipe, redirectPipe chan interface{}, interrupt chan os.Sign
 			case item, ok := <-pipe:
 				if !ok {
 					return !errorReceived && interruptsReceived == 0
-				} else {
-					redirectPipe <- item
-					switch item.(type) {
-					case error:
-						errorReceived = true
-					}
+				}
+				redirectPipe <- item
+				switch item.(type) {
+				case error:
+					errorReceived = true
 				}
 			}
 		}
@@ -66,11 +65,10 @@ func ReadErrors(pipe chan interface{}) []error {
 			case item, ok := <-pipe:
 				if !ok {
 					return err
-				} else {
-					switch item.(type) {
-					case error:
-						err = append(err, item.(error))
-					}
+				}
+				switch item.(type) {
+				case error:
+					err = append(err, item.(error))
 				}
 			}
 		}
diff --git a/version.go b/version.go
index 082af71ae..cc9748fe3 100644
--- a/version.go
+++ b/version.go
@@ -1,3 +1,4 @@
 package main
 
+// Version - version of tool
 const Version string = "1.3.0"

From adf1cff65973259b58152c255a487a3a5f0c9f8b Mon Sep 17 00:00:00 2001
From: Pavel Sapezhko <pavel.sapezhko@synesis.ru>
Date: Fri, 17 Feb 2017 17:59:38 +0300
Subject: [PATCH 04/23] drivers: cassandra: rewrite

---
 driver/cassandra/cassandra.go | 87 ++++++++++++++---------------------
 1 file changed, 35 insertions(+), 52 deletions(-)

diff --git a/driver/cassandra/cassandra.go b/driver/cassandra/cassandra.go
index 500d81f74..fd69c1c36 100644
--- a/driver/cassandra/cassandra.go
+++ b/driver/cassandra/cassandra.go
@@ -14,44 +14,16 @@ import (
 	"github.com/mattes/migrate/migrate/direction"
 )
 
+// Driver implements migrate Driver interface
 type Driver struct {
 	session *gocql.Session
 }
 
 const (
-	tableName  = "schema_migrations"
-	versionRow = 1
+	tableName = "schema_migrations"
 )
 
-type counterStmt bool
-
-func (c counterStmt) Exec(session *gocql.Session) error {
-	var version int64
-	if err := session.Query("SELECT version FROM "+tableName+" WHERE versionRow = ?", versionRow).Scan(&version); err != nil {
-		return err
-	}
-
-	if bool(c) {
-		version++
-	} else {
-		version--
-	}
-
-	return session.Query("UPDATE "+tableName+" SET version = ? WHERE versionRow = ?", version, versionRow).Exec()
-}
-
-const (
-	up   counterStmt = true
-	down counterStmt = false
-)
-
-// Cassandra Driver URL format:
-// cassandra://host:port/keyspace?protocol=version&consistency=level
-//
-// Examples:
-// cassandra://localhost/SpaceOfKeys?protocol=4
-// cassandra://localhost/SpaceOfKeys?protocol=4&consistency=all
-// cassandra://localhost/SpaceOfKeys?consistency=quorum
+// Initialize will be called first
 func (driver *Driver) Initialize(rawurl string) error {
 	u, err := url.Parse(rawurl)
 	if err != nil {
@@ -114,53 +86,63 @@ func (driver *Driver) Initialize(rawurl string) error {
 	return nil
 }
 
+// Close last function to be called. Closes cassandra session
 func (driver *Driver) Close() error {
 	driver.session.Close()
 	return nil
 }
 
 func (driver *Driver) ensureVersionTableExists() error {
-	err := driver.session.Query("CREATE TABLE IF NOT EXISTS " + tableName + " (version int, versionRow bigint primary key);").Exec()
+	err := driver.session.Query(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (id uuid primary key, version bigint)", tableName)).Exec()
 	if err != nil {
 		return err
 	}
 
-	_, err = driver.Version()
-	if err != nil {
-		if err.Error() == "not found" {
-			return driver.session.Query("UPDATE "+tableName+" SET version = ? WHERE versionRow = ?", 1, versionRow).Exec()
-		}
+	if _, err = driver.Version(); err != nil {
 		return err
 	}
 
 	return nil
 }
 
+// FilenameExtension return extension of migrations files
 func (driver *Driver) FilenameExtension() string {
 	return "cql"
 }
 
-func (driver *Driver) version(d direction.Direction, invert bool) error {
-	var stmt counterStmt
-	switch d {
-	case direction.Up:
-		stmt = up
-	case direction.Down:
-		stmt = down
+func (driver *Driver) updateVersion(version uint64, dir direction.Direction) error {
+	var ids []string
+	var id string
+	var err error
+	iter := driver.session.Query(fmt.Sprintf("SELECT id FROM %s WHERE version >= ? ALLOW FILTERING", tableName), version).Iter()
+	for iter.Scan(&id) {
+		ids = append(ids, id)
+	}
+	if len(ids) > 0 {
+		err = driver.session.Query(fmt.Sprintf("DELETE FROM %s WHERE id IN ?", tableName), ids).Exec()
+		if err != nil {
+			return err
+		}
 	}
-	if invert {
-		stmt = !stmt
+	if dir == direction.Up {
+		return driver.session.Query(fmt.Sprintf("INSERT INTO %s (id, version) VALUES (uuid(), ?)", tableName), version).Exec()
 	}
-	return stmt.Exec(driver.session)
+	return nil
 }
 
+// Migrate run migration file. Restore previous version in case of fail
 func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 	var err error
+	previousVersion, err := driver.Version()
+	if err != nil {
+		close(pipe)
+		return
+	}
 	defer func() {
 		if err != nil {
 			// Invert version direction if we couldn't apply the changes for some reason.
-			if err := driver.version(f.Direction, true); err != nil {
-				pipe <- err
+			if updErr := driver.updateVersion(previousVersion, direction.Up); updErr != nil {
+				pipe <- updErr
 			}
 			pipe <- err
 		}
@@ -168,7 +150,7 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 	}()
 
 	pipe <- f
-	if err = driver.version(f.Direction, false); err != nil {
+	if err = driver.updateVersion(f.Version, f.Direction); err != nil {
 		return
 	}
 
@@ -188,10 +170,11 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 	}
 }
 
+// Version return current version
 func (driver *Driver) Version() (uint64, error) {
 	var version int64
-	err := driver.session.Query("SELECT version FROM "+tableName+" WHERE versionRow = ?", versionRow).Scan(&version)
-	return uint64(version) - 1, err
+	err := driver.session.Query(fmt.Sprintf("SELECT max(version) FROM %s", tableName)).Scan(&version)
+	return uint64(version), err
 }
 
 func init() {

From fe6711645ac46346f6062e132c38e6b8e4a822ee Mon Sep 17 00:00:00 2001
From: Masa Sekimura <sekimura@gmail.com>
Date: Mon, 20 Feb 2017 23:36:31 +0000
Subject: [PATCH 05/23] Fix for go vet

Avoid getting caught by go vet for using "\n" with Println

	main.go:187: Println call ends with newline
---
 main.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.go b/main.go
index 673102649..6d8fcbfb5 100644
--- a/main.go
+++ b/main.go
@@ -184,7 +184,7 @@ func writePipe(pipe chan interface{}) (ok bool) {
 
 					case error:
 						c := color.New(color.FgRed)
-						c.Println(item.(error).Error(), "\n")
+						c.Printf("%s\n\n", item.(error).Error())
 						okFlag = false
 
 					case file.File:

From 21ccec2aa1f1d8ceb5d52c95f0319f6b7eb22b39 Mon Sep 17 00:00:00 2001
From: Pavel Sapezhko <pavel.sapezhko@synesis.ru>
Date: Tue, 21 Feb 2017 09:13:22 +0300
Subject: [PATCH 06/23] allow create migration files without db connection

---
 driver/driver.go   | 16 ++++++++++++++++
 migrate/migrate.go |  8 ++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/driver/driver.go b/driver/driver.go
index 2844e1a86..ddf4cb453 100644
--- a/driver/driver.go
+++ b/driver/driver.go
@@ -53,6 +53,22 @@ func New(url string) (Driver, error) {
 	return d, nil
 }
 
+// FilenameExtensionFromURL return extension for migration files. Used for create migrations
+func FilenameExtensionFromURL(url string) (string, error) {
+	u, err := neturl.Parse(url)
+	if err != nil {
+		return "", err
+	}
+
+	d := GetDriver(u.Scheme)
+	if d == nil {
+		return "", fmt.Errorf("Driver '%s' not found", u.Scheme)
+	}
+	verifyFilenameExtension(u.Scheme, d)
+
+	return d.FilenameExtension(), nil
+}
+
 // verifyFilenameExtension panics if the driver's filename extension
 // is not correct or empty.
 func verifyFilenameExtension(driverName string, d Driver) {
diff --git a/migrate/migrate.go b/migrate/migrate.go
index 3a9aa1b1a..8aae88e7c 100644
--- a/migrate/migrate.go
+++ b/migrate/migrate.go
@@ -222,12 +222,12 @@ func Version(url, migrationsPath string) (version uint64, err error) {
 
 // Create creates new migration files on disk
 func Create(url, migrationsPath, name string) (*file.MigrationFile, error) {
-	d, err := driver.New(url)
+	ext, err := driver.FilenameExtensionFromURL(url)
 	if err != nil {
 		return nil, err
 	}
 
-	files, err := file.ReadMigrationFiles(migrationsPath, file.FilenameRegex(d.FilenameExtension()))
+	files, err := file.ReadMigrationFiles(migrationsPath, file.FilenameRegex(ext))
 	if err != nil {
 		return nil, err
 	}
@@ -254,14 +254,14 @@ func Create(url, migrationsPath, name string) (*file.MigrationFile, error) {
 		Version: version,
 		UpFile: &file.File{
 			Path:      migrationsPath,
-			FileName:  fmt.Sprintf(filenamef, versionStr, name, "up", d.FilenameExtension()),
+			FileName:  fmt.Sprintf(filenamef, versionStr, name, "up", ext),
 			Name:      name,
 			Content:   []byte(""),
 			Direction: direction.Up,
 		},
 		DownFile: &file.File{
 			Path:      migrationsPath,
-			FileName:  fmt.Sprintf(filenamef, versionStr, name, "down", d.FilenameExtension()),
+			FileName:  fmt.Sprintf(filenamef, versionStr, name, "down", ext),
 			Name:      name,
 			Content:   []byte(""),
 			Direction: direction.Down,

From 528bc5bbbb215bee21db3c2a2272d26d1dda78f6 Mon Sep 17 00:00:00 2001
From: Chris S <chris@axiomzen.co>
Date: Thu, 2 Mar 2017 12:48:31 -0800
Subject: [PATCH 07/23] close driver

---
 migrate/migrate.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/migrate/migrate.go b/migrate/migrate.go
index 8aae88e7c..4fdef5d47 100644
--- a/migrate/migrate.go
+++ b/migrate/migrate.go
@@ -217,6 +217,9 @@ func Version(url, migrationsPath string) (version uint64, err error) {
 	if err != nil {
 		return 0, err
 	}
+	defer func() {
+		err = d.Close()
+	}()
 	return d.Version()
 }
 

From f4979054e23773600cfac859c9a4e35e6c20be8b Mon Sep 17 00:00:00 2001
From: Adrian Duke <adrian.duke@gmail.com>
Date: Mon, 20 Mar 2017 16:07:01 +0000
Subject: [PATCH 08/23] driver/sqlite3 fix for upstream change sqlite3.Error{}
 Error() now takes a pointer receiver

---
 driver/sqlite3/sqlite3.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/driver/sqlite3/sqlite3.go b/driver/sqlite3/sqlite3.go
index b245eb187..83edc7ed9 100644
--- a/driver/sqlite3/sqlite3.go
+++ b/driver/sqlite3/sqlite3.go
@@ -92,7 +92,7 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 	}
 
 	if _, err := tx.Exec(string(f.Content)); err != nil {
-		sqliteErr, isErr := err.(sqlite3.Error)
+		sqliteErr, isErr := err.(*sqlite3.Error)
 
 		if isErr {
 			// The sqlite3 library only provides error codes, not position information. Output what we do know

From 7ca71e567d8b01ec9f985c24d921bba9c9428f0b Mon Sep 17 00:00:00 2001
From: Nathan Davies <ndavies@iparadigms.com>
Date: Wed, 29 Mar 2017 14:06:38 +0100
Subject: [PATCH 09/23] fixing error cast for sqlite3

Seems the sqlite3 packaged reverted to using non-pointer Error. This patch corrects the use of it here.
---
 driver/sqlite3/sqlite3.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/driver/sqlite3/sqlite3.go b/driver/sqlite3/sqlite3.go
index 83edc7ed9..b245eb187 100644
--- a/driver/sqlite3/sqlite3.go
+++ b/driver/sqlite3/sqlite3.go
@@ -92,7 +92,7 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 	}
 
 	if _, err := tx.Exec(string(f.Content)); err != nil {
-		sqliteErr, isErr := err.(*sqlite3.Error)
+		sqliteErr, isErr := err.(sqlite3.Error)
 
 		if isErr {
 			// The sqlite3 library only provides error codes, not position information. Output what we do know

From b7845a779efaa895c48c38894655382d634736fc Mon Sep 17 00:00:00 2001
From: Andras Laczi <andras.laczi@sainsburys.co.uk>
Date: Thu, 30 Mar 2017 11:25:39 +0100
Subject: [PATCH 10/23] Add MSSQL support

---
 README.md                  |   1 +
 docker-compose.yml         |   6 ++
 driver/mssql/README.md     |  22 ++++++
 driver/mssql/mssql.go      | 128 ++++++++++++++++++++++++++++++++
 driver/mssql/mssql_test.go | 148 +++++++++++++++++++++++++++++++++++++
 main.go                    |   1 +
 6 files changed, 306 insertions(+)
 create mode 100644 driver/mssql/README.md
 create mode 100644 driver/mssql/mssql.go
 create mode 100644 driver/mssql/mssql_test.go

diff --git a/README.md b/README.md
index d233696f6..b12bf77bf 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ __Features__
  * [Ql](driver/ql)
  * [MongoDB](driver/mongodb)
  * [CrateDB](driver/crate)
+ * [MSSQL](driver/mssql)
 
 Need another driver? Just implement the [Driver interface](http://godoc.org/github.com/mattes/migrate/driver#Driver) and open a PR.
 
diff --git a/docker-compose.yml b/docker-compose.yml
index 274783935..dfbc1c3da 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,6 +7,7 @@ go-test:
   <<: *go
   command: sh -c 'go get -t -v ./... && go test -v ./...'
   links:
+    - mssql
     - postgres
     - mysql
     - cassandra
@@ -30,3 +31,8 @@ crate:
   image: crate
 mongo:
   image: mongo:3.2.6
+mssql:
+  image: microsoft/mssql-server-linux
+  environment:
+    SA_PASSWORD: Passw0rd
+    ACCEPT_EULA: "Y"
diff --git a/driver/mssql/README.md b/driver/mssql/README.md
new file mode 100644
index 000000000..26a573075
--- /dev/null
+++ b/driver/mssql/README.md
@@ -0,0 +1,22 @@
+# MSSQL Driver
+
+* Runs migrations in transactions.
+  That means that if a migration fails, it will be safely rolled back.
+* Tries to return helpful error messages.
+* Stores migration version details in table ``schema_migrations``.
+  This table will be auto-generated.
+
+
+## Usage
+
+```bash
+migrate -url="sqlserver://sa:Passw0rd@localhost:1433?database=master" -path ./db/migrations create add_field_to_table
+migrate -url="sqlserver://sa:Passw0rd@localhost:1433?database=master" -path ./db/migrations up
+migrate help # for more info
+
+# see more docs: https://github.com/denisenkom/go-mssqldb
+```
+
+## Authors
+
+* Andras Laczi, https://github.com/alaczi
diff --git a/driver/mssql/mssql.go b/driver/mssql/mssql.go
new file mode 100644
index 000000000..05516526d
--- /dev/null
+++ b/driver/mssql/mssql.go
@@ -0,0 +1,128 @@
+// Package mssql implements the Driver interface.
+package mssql
+
+import (
+	"database/sql"
+	"errors"
+	"fmt"
+
+	"github.com/denisenkom/go-mssqldb"
+	"github.com/mattes/migrate/driver"
+	"github.com/mattes/migrate/file"
+	"github.com/mattes/migrate/migrate/direction"
+)
+
+type Driver struct {
+	db *sql.DB
+}
+
+const tableName = "schema_migrations"
+
+func (driver *Driver) Initialize(url string) error {
+	db, err := sql.Open("mssql", url)
+	if err != nil {
+		return err
+	}
+	if err := db.Ping(); err != nil {
+		return err
+	}
+	driver.db = db
+
+	if err := driver.ensureVersionTableExists(); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (driver *Driver) Close() error {
+	if err := driver.db.Close(); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (driver *Driver) ensureVersionTableExists() error {
+	if _, err := driver.db.Exec("if object_id('" + tableName + "') is null create table [" + tableName + "] ([version] BIGINT NOT NULL PRIMARY KEY);"); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (driver *Driver) FilenameExtension() string {
+	return "sql"
+}
+
+func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
+	defer close(pipe)
+	pipe <- f
+
+	tx, err := driver.db.Begin()
+	if err != nil {
+		pipe <- err
+		return
+	}
+
+	if f.Direction == direction.Up {
+		if _, err := tx.Exec("INSERT INTO "+tableName+" (version) VALUES (?)", f.Version); err != nil {
+			pipe <- err
+			if err := tx.Rollback(); err != nil {
+				pipe <- err
+			}
+			return
+		}
+	} else if f.Direction == direction.Down {
+		if _, err := tx.Exec("DELETE FROM "+tableName+" WHERE version=?", f.Version); err != nil {
+			pipe <- err
+			if err := tx.Rollback(); err != nil {
+				pipe <- err
+			}
+			return
+		}
+	}
+
+	if err := f.ReadContent(); err != nil {
+		pipe <- err
+		return
+	}
+
+	if _, err := tx.Exec(string(f.Content)); err != nil {
+		switch msErr := err.(type) {
+		case *mssql.Error:
+			errorPart := file.LinesBeforeAndAfter(f.Content, int(msErr.LineNo), 5, 5, true)
+			pipe <- errors.New(fmt.Sprintf("%v: %s in line %v:\n\n%s", msErr.Number, msErr.Message, msErr.LineNo, string(errorPart)))
+			if err := tx.Rollback(); err != nil {
+				pipe <- err
+			}
+			return
+		default:
+			pipe <- err
+			if err := tx.Rollback(); err != nil {
+				pipe <- err
+			}
+			return
+		}
+	}
+
+	if err := tx.Commit(); err != nil {
+		pipe <- err
+		return
+	}
+}
+
+func (driver *Driver) Version() (uint64, error) {
+	var version uint64
+	err := driver.db.QueryRow("SELECT version FROM " + tableName + " ORDER BY version OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY").Scan(&version)
+	switch {
+	case err == sql.ErrNoRows:
+		return 0, nil
+	case err != nil:
+		return 0, err
+	default:
+		return version, nil
+	}
+}
+
+func init() {
+	driver.RegisterDriver("mssql", &Driver{})
+	driver.RegisterDriver("sqlserver", &Driver{})
+}
diff --git a/driver/mssql/mssql_test.go b/driver/mssql/mssql_test.go
new file mode 100644
index 000000000..91b82ffcc
--- /dev/null
+++ b/driver/mssql/mssql_test.go
@@ -0,0 +1,148 @@
+package mssql
+
+import (
+	"database/sql"
+	"os"
+	"testing"
+
+	"fmt"
+	"github.com/mattes/migrate/file"
+	"github.com/mattes/migrate/migrate/direction"
+	pipep "github.com/mattes/migrate/pipe"
+)
+
+// TestMigrate runs some additional tests on Migrate().
+// Basic testing is already done in migrate/migrate_test.go
+func TestMigrate(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping test in short mode.")
+	}
+
+	host := os.Getenv("MSSQL_PORT_1433_TCP_ADDR")
+	port := os.Getenv("MSSQL_PORT_1433_TCP_PORT")
+	driverURL := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;encrypt=disable;log=2;TrustServerCertificate=true",
+		host,
+		"sa",
+		"Passw0rd",
+		port,
+		"master",
+	)
+	// prepare clean database
+	connection, err := sql.Open("mssql", driverURL)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if _, err := connection.Exec(`
+				DROP TABLE IF EXISTS yolo;
+				DROP TABLE IF EXISTS ` + tableName + `;`); err != nil {
+		t.Fatal(err)
+	}
+
+	d := &Driver{}
+	if err := d.Initialize(driverURL); err != nil {
+		t.Fatal(err)
+	}
+
+	// testing idempotency: second call should be a no-op, since table already exists
+	if err := d.Initialize(driverURL); err != nil {
+		t.Fatal(err)
+	}
+
+	files := []file.File{
+		{
+			Path:      "/foobar",
+			FileName:  "001_foobar.up.sql",
+			Version:   1,
+			Name:      "foobar",
+			Direction: direction.Up,
+			Content: []byte(`
+				CREATE TABLE yolo (
+					id BIGINT IDENTITY NOT NULL PRIMARY KEY
+				);
+			`),
+		},
+		{
+			Path:      "/foobar",
+			FileName:  "002_foobar.down.sql",
+			Version:   1,
+			Name:      "foobar",
+			Direction: direction.Down,
+			Content: []byte(`
+				DROP TABLE yolo;
+			`),
+		},
+		{
+			Path:      "/foobar",
+			FileName:  "002_foobar.up.sql",
+			Version:   2,
+			Name:      "foobar",
+			Direction: direction.Up,
+			Content: []byte(`
+				CREATE TABLE error (
+					id THIS WILL CAUSE AN ERROR
+				)
+			`),
+		},
+		{
+			Path:      "/foobar",
+			FileName:  "20170118205923_demo.up.sql",
+			Version:   20170118205923,
+			Name:      "demo",
+			Direction: direction.Up,
+			Content: []byte(`
+			CREATE TABLE demo (
+				id BIGINT IDENTITY NOT NULL PRIMARY KEY
+			)
+			`),
+		},
+		{
+			Path:      "/foobar",
+			FileName:  "20170118205923_demo.down.sql",
+			Version:   20170118205923,
+			Name:      "demo",
+			Direction: direction.Down,
+			Content: []byte(`
+				DROP TABLE demo
+			`),
+		},
+	}
+
+	pipe := pipep.New()
+	go d.Migrate(files[0], pipe)
+	errs := pipep.ReadErrors(pipe)
+	if len(errs) > 0 {
+		t.Fatal(errs)
+	}
+
+	pipe = pipep.New()
+	go d.Migrate(files[1], pipe)
+	errs = pipep.ReadErrors(pipe)
+	if len(errs) > 0 {
+		t.Fatal(errs)
+	}
+
+	pipe = pipep.New()
+	go d.Migrate(files[2], pipe)
+	errs = pipep.ReadErrors(pipe)
+	if len(errs) == 0 {
+		t.Error("Expected test case to fail")
+	}
+
+	pipe = pipep.New()
+	go d.Migrate(files[3], pipe)
+	errs = pipep.ReadErrors(pipe)
+	if len(errs) > 0 {
+		t.Fatal(errs)
+	}
+
+	pipe = pipep.New()
+	go d.Migrate(files[4], pipe)
+	errs = pipep.ReadErrors(pipe)
+	if len(errs) > 0 {
+		t.Fatal(errs)
+	}
+
+	if err := d.Close(); err != nil {
+		t.Fatal(err)
+	}
+}
diff --git a/main.go b/main.go
index 06cbfac05..9d7f2b6cd 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,7 @@ import (
 	_ "github.com/mattes/migrate/driver/bash"
 	_ "github.com/mattes/migrate/driver/cassandra"
 	_ "github.com/mattes/migrate/driver/crate"
+	_ "github.com/mattes/migrate/driver/mssql"
 	_ "github.com/mattes/migrate/driver/mysql"
 	_ "github.com/mattes/migrate/driver/neo4j"
 	_ "github.com/mattes/migrate/driver/postgres"

From 83c703f09f092c5f3919934fdd97bcfd450d9ab2 Mon Sep 17 00:00:00 2001
From: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
Date: Mon, 3 Apr 2017 09:15:25 +0200
Subject: [PATCH 11/23] Support for alternative postgres URI scheme

According to the PostgreSQL documentation (section 32.1.1.2), postgres
library supports two URI schemes: postgresql:// and postgres://

Reference:
https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
---
 driver/postgres/postgres.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/driver/postgres/postgres.go b/driver/postgres/postgres.go
index fc6e144f0..77e2ae2ce 100644
--- a/driver/postgres/postgres.go
+++ b/driver/postgres/postgres.go
@@ -139,5 +139,7 @@ func (driver *Driver) Version() (uint64, error) {
 }
 
 func init() {
-	driver.RegisterDriver("postgres", &Driver{})
+	drv := Driver{}
+	driver.RegisterDriver("postgres", &drv)
+	driver.RegisterDriver("postgresql", &drv)
 }

From 0da98940d69072ea9e012486eabe955fabc710ad Mon Sep 17 00:00:00 2001
From: Robert Mulley <robert.mulley@jumpcloud.com>
Date: Thu, 13 Apr 2017 12:44:27 -0600
Subject: [PATCH 12/23] Add go 1.8 to test matrix

---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.travis.yml b/.travis.yml
index 6e027af6a..2b4458aa2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@ go:
   - 1.5
   - 1.6
   - 1.7
+  - 1.8
 
 services:
   - docker

From 5498e7056279a8d22f6411f5d6dfadae5e4e22a4 Mon Sep 17 00:00:00 2001
From: Robert Mulley <robert.mulley@jumpcloud.com>
Date: Thu, 13 Apr 2017 12:54:35 -0600
Subject: [PATCH 13/23] Bump docker-compose to latest, 1.11.2

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 2b4458aa2..dbbc41aa5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,7 @@ services:
   - docker
 
 before_install:
-    - curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose
+    - curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > docker-compose
     - chmod +x docker-compose
     - sudo mv docker-compose /usr/local/bin
     - sed -i -e 's/golang/golang:'"$TRAVIS_GO_VERSION"'/' docker-compose.yml

From fff063351d07f52fb4800e8de10cb7f9c726e853 Mon Sep 17 00:00:00 2001
From: Robert Mulley <robert.mulley@jumpcloud.com>
Date: Thu, 13 Apr 2017 13:01:59 -0600
Subject: [PATCH 14/23] Pull latest patch versions for each go minor version

---
 .travis.yml | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index dbbc41aa5..bbf837b55 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,11 +2,11 @@ language: go
 sudo: required
 
 go:
-  - 1.4
-  - 1.5
-  - 1.6
-  - 1.7
-  - 1.8
+  - 1.4.x
+  - 1.5.x
+  - 1.6.x
+  - 1.7.x
+  - 1.8.x
 
 services:
   - docker

From 7dde43471463c0ee6a4183e1b5a8239ae2aa3122 Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Thu, 20 Apr 2017 11:50:49 -0700
Subject: [PATCH 15/23] Update version.go

---
 version.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/version.go b/version.go
index cc9748fe3..6c96c3afd 100644
--- a/version.go
+++ b/version.go
@@ -1,4 +1,4 @@
 package main
 
 // Version - version of tool
-const Version string = "1.3.0"
+const Version string = "1.3.1"

From 9f1467677397bb50ab33acf694021fa68eff6b4e Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Thu, 20 Apr 2017 15:04:54 -0700
Subject: [PATCH 16/23] Update Readme

---
 README.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d233696f6..79e0ed1cb 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
-__[v3.0 in the making](https://github.com/mattes/migrate/tree/v3.0-prev)__
+# You are looking at a deprecated version. 
+# Use the [latest version](https://github.com/mattes/migrate) instead.
 
 ---
 

From ecd74e1ce6f1ccf52d560f234bcc3f7161f9d2c3 Mon Sep 17 00:00:00 2001
From: Andras Laczi <andras.laczi@sainsburys.co.uk>
Date: Thu, 30 Mar 2017 13:51:16 +0100
Subject: [PATCH 17/23] Add go 1.8 to travis config

Fix getting the latest version
---
 .travis.yml           | 1 +
 driver/mssql/mssql.go | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 6e027af6a..2b4458aa2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@ go:
   - 1.5
   - 1.6
   - 1.7
+  - 1.8
 
 services:
   - docker
diff --git a/driver/mssql/mssql.go b/driver/mssql/mssql.go
index 05516526d..326621d6c 100644
--- a/driver/mssql/mssql.go
+++ b/driver/mssql/mssql.go
@@ -111,7 +111,7 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
 
 func (driver *Driver) Version() (uint64, error) {
 	var version uint64
-	err := driver.db.QueryRow("SELECT version FROM " + tableName + " ORDER BY version OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY").Scan(&version)
+	err := driver.db.QueryRow("SELECT version FROM " + tableName + " ORDER BY version DESC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY").Scan(&version)
 	switch {
 	case err == sql.ErrNoRows:
 		return 0, nil

From 7f4000c0d62c660ca44acf60aa2c710dcdc47046 Mon Sep 17 00:00:00 2001
From: Andras Laczi <andras.laczi@sainsburys.co.uk>
Date: Mon, 24 Apr 2017 11:03:21 +0100
Subject: [PATCH 18/23] Add wait-retry to mssql test

---
 driver/mssql/mssql_test.go | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/driver/mssql/mssql_test.go b/driver/mssql/mssql_test.go
index 91b82ffcc..fddc4e917 100644
--- a/driver/mssql/mssql_test.go
+++ b/driver/mssql/mssql_test.go
@@ -4,8 +4,9 @@ import (
 	"database/sql"
 	"os"
 	"testing"
-
+	"time"
 	"fmt"
+
 	"github.com/mattes/migrate/file"
 	"github.com/mattes/migrate/migrate/direction"
 	pipep "github.com/mattes/migrate/pipe"
@@ -27,11 +28,30 @@ func TestMigrate(t *testing.T) {
 		port,
 		"master",
 	)
+	// retry connection for 2 minutes
+	until := time.Now().Add(time.Second * 120)
+
+	ticker := time.NewTicker(time.Second)
+	var connection *sql.DB
+	var err error
 	// prepare clean database
-	connection, err := sql.Open("mssql", driverURL)
+	for tick := range ticker.C {
+		if tick.After(until) {
+			ticker.Stop()
+			break;
+		}
+		connection, err = sql.Open("mssql", driverURL)
+		err = connection.Ping()
+		if err == nil {
+			ticker.Stop()
+			break;
+		}
+	}
+
 	if err != nil {
-		t.Fatal(err)
+		t.Fatal("Failed to connect to mssql docker container after 2 minutes", err)
 	}
+
 	if _, err := connection.Exec(`
 				DROP TABLE IF EXISTS yolo;
 				DROP TABLE IF EXISTS ` + tableName + `;`); err != nil {

From d21443f74ba6e030e9c699f925c452f78312df0e Mon Sep 17 00:00:00 2001
From: Andras Laczi <andras.laczi@sainsburys.co.uk>
Date: Tue, 25 Apr 2017 09:35:03 +0100
Subject: [PATCH 19/23] Remove go1.4 from travis as the ql package is not
 compatible and breaks the build

---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 2b4458aa2..16127c8c6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,6 @@ language: go
 sudo: required
 
 go:
-  - 1.4
   - 1.5
   - 1.6
   - 1.7

From 62dba4f8ea9ed20b66f4495179248e01d8be91be Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Tue, 25 Apr 2017 12:02:57 -0700
Subject: [PATCH 20/23] update travis branch

---
 README.md | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/README.md b/README.md
index a23277551..d0f664f1b 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,7 @@
 
 # migrate
 
-[![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=master)](https://travis-ci.org/mattes/migrate)
-[![GoDoc](https://godoc.org/github.com/mattes/migrate?status.svg)](https://godoc.org/github.com/mattes/migrate)
+[![Build Status](https://travis-ci.org/mattes/migrate.svg?branch=v1)](https://travis-ci.org/mattes/migrate)
 
 A migration helper written in Go. Use it in your existing Golang code 
 or run commands via the CLI. 

From 1887c0f3e348f809e6a5742ddab33d43354f7d37 Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Sat, 6 May 2017 16:13:08 -0700
Subject: [PATCH 21/23] rewrite paths

---
 .travis.yml                                   |  1 +
 README.md                                     |  4 +--
 docker-compose.yml                            |  4 +--
 driver/bash/README.md                         |  2 +-
 driver/bash/bash.go                           |  4 +--
 driver/cassandra/cassandra.go                 |  6 ++--
 driver/cassandra/cassandra_test.go            |  6 ++--
 driver/crate/README.md                        |  2 +-
 driver/crate/crate.go                         |  6 ++--
 driver/crate/crate_test.go                    |  6 ++--
 driver/driver.go                              |  2 +-
 driver/mongodb/README.md                      |  6 ++--
 driver/mongodb/example/mongodb_test.go        | 12 ++++----
 .../mongodb/example/sample_mongdb_migrator.go |  6 ++--
 .../mongodb/gomethods/gomethods_migrator.go   |  4 +--
 .../gomethods/gomethods_migrator_test.go      |  6 ++--
 .../mongodb/gomethods/gomethods_registry.go   |  2 +-
 driver/mongodb/mongodb.go                     |  8 +++---
 driver/mssql/mssql.go                         |  6 ++--
 driver/mssql/mssql_test.go                    | 12 ++++----
 driver/mysql/README.md                        |  2 +-
 driver/mysql/mysql.go                         |  6 ++--
 driver/mysql/mysql_test.go                    |  6 ++--
 driver/neo4j/README.md                        |  2 +-
 driver/neo4j/neo4j.go                         |  6 ++--
 driver/neo4j/neo4j_test.go                    |  6 ++--
 driver/postgres/postgres.go                   |  6 ++--
 driver/postgres/postgres_test.go              |  6 ++--
 driver/ql/ql.go                               |  6 ++--
 driver/sqlite3/sqlite3.go                     |  6 ++--
 driver/sqlite3/sqlite3_test.go                |  6 ++--
 file/file.go                                  |  2 +-
 file/file_test.go                             |  2 +-
 main.go                                       | 28 +++++++++----------
 migrate/migrate.go                            |  8 +++---
 migrate/migrate_test.go                       |  6 ++--
 36 files changed, 105 insertions(+), 104 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 16127c8c6..f130a0383 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,4 +16,5 @@ before_install:
     - sudo mv docker-compose /usr/local/bin
     - sed -i -e 's/golang/golang:'"$TRAVIS_GO_VERSION"'/' docker-compose.yml
 
+      
 script: make test
diff --git a/README.md b/README.md
index d0f664f1b..81f45ed63 100644
--- a/README.md
+++ b/README.md
@@ -84,10 +84,10 @@ migrate -url driver://url -path ./migrations goto v
 See GoDoc here: http://godoc.org/github.com/mattes/migrate/migrate
 
 ```go
-import "github.com/mattes/migrate/migrate"
+import "gopkg.in/mattes/migrate.v1/migrate"
 
 // Import any required drivers so that they are registered and available
-import _ "github.com/mattes/migrate/driver/mysql"
+import _ "gopkg.in/mattes/migrate.v1/driver/mysql"
 
 // use synchronous versions of migration functions ...
 allErrors, ok := migrate.UpSync("driver://url", "./path")
diff --git a/docker-compose.yml b/docker-compose.yml
index dfbc1c3da..c58accf60 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,8 +1,8 @@
 go: &go
   image: golang
-  working_dir: /go/src/github.com/mattes/migrate
+  working_dir: /go/src/gopkg.in/mattes/migrate.v1
   volumes:
-    - $GOPATH:/go
+    - $GOPATH/src/github.com/mattes/migrate:/go/src/gopkg.in/mattes/migrate.v1  
 go-test:
   <<: *go
   command: sh -c 'go get -t -v ./... && go test -v ./...'
diff --git a/driver/bash/README.md b/driver/bash/README.md
index 1f3e79904..f1d099b84 100644
--- a/driver/bash/README.md
+++ b/driver/bash/README.md
@@ -8,4 +8,4 @@
 migrate -url bash://xxx -path ./migrations create increment_xyz
 migrate -url bash://xxx -path ./migrations up
 migrate help # for more info
-```
\ No newline at end of file
+```
diff --git a/driver/bash/bash.go b/driver/bash/bash.go
index 031f9bb47..2bc61949d 100644
--- a/driver/bash/bash.go
+++ b/driver/bash/bash.go
@@ -2,8 +2,8 @@
 package bash
 
 import (
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
 )
 
 type Driver struct {
diff --git a/driver/cassandra/cassandra.go b/driver/cassandra/cassandra.go
index fd69c1c36..04581f1a6 100644
--- a/driver/cassandra/cassandra.go
+++ b/driver/cassandra/cassandra.go
@@ -9,9 +9,9 @@ import (
 	"time"
 
 	"github.com/gocql/gocql"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 // Driver implements migrate Driver interface
diff --git a/driver/cassandra/cassandra_test.go b/driver/cassandra/cassandra_test.go
index 7218ba23a..caf9d56e3 100644
--- a/driver/cassandra/cassandra_test.go
+++ b/driver/cassandra/cassandra_test.go
@@ -7,9 +7,9 @@ import (
 	"time"
 
 	"github.com/gocql/gocql"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 func TestMigrate(t *testing.T) {
diff --git a/driver/crate/README.md b/driver/crate/README.md
index a43d01330..042a7d57e 100644
--- a/driver/crate/README.md
+++ b/driver/crate/README.md
@@ -12,4 +12,4 @@ limitation of Crate. So handle situations with failed migrations with care!
 migrate -url http://host:port -path ./db/migrations create add_field_to_table
 migrate -url http://host:port -path ./db/migrations up
 migrate help # for more info
-```
\ No newline at end of file
+```
diff --git a/driver/crate/crate.go b/driver/crate/crate.go
index 56fc50e9d..711eac976 100644
--- a/driver/crate/crate.go
+++ b/driver/crate/crate.go
@@ -7,9 +7,9 @@ import (
 	"strings"
 
 	_ "github.com/herenow/go-crate"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 func init() {
diff --git a/driver/crate/crate_test.go b/driver/crate/crate_test.go
index 164cd57a2..2ac412033 100644
--- a/driver/crate/crate_test.go
+++ b/driver/crate/crate_test.go
@@ -5,9 +5,9 @@ import (
 	"os"
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 func TestContentSplit(t *testing.T) {
diff --git a/driver/driver.go b/driver/driver.go
index ddf4cb453..bd9b45a93 100644
--- a/driver/driver.go
+++ b/driver/driver.go
@@ -5,7 +5,7 @@ import (
 	"fmt"
 	neturl "net/url" // alias to allow `url string` func signature in New
 
-	"github.com/mattes/migrate/file"
+	"gopkg.in/mattes/migrate.v1/file"
 )
 
 // Driver is the interface type that needs to implemented by all drivers.
diff --git a/driver/mongodb/README.md b/driver/mongodb/README.md
index d7d8351d9..0c49aa638 100644
--- a/driver/mongodb/README.md
+++ b/driver/mongodb/README.md
@@ -10,7 +10,7 @@
 ## Usage in Go
 
 ```go
-import "github.com/mattes/migrate/migrate"
+import "gopkg.in/mattes/migrate.v1/migrate"
 
 // Import your migration methods package so that they are registered and available for the MongoDB driver.
 // There is no need to import the MongoDB driver explicitly, as it should already be imported by your migration methods package.
@@ -65,8 +65,8 @@ For a detailed example see: [sample_mongodb_migrator.go](https://github.com/matt
 package my_mongo_db_migrator
 
 import (
-  "github.com/mattes/migrate/driver/mongodb"
-  "github.com/mattes/migrate/driver/mongodb/gomethods"
+  "gopkg.in/mattes/migrate.v1/driver/mongodb"
+  "gopkg.in/mattes/migrate.v1/driver/mongodb/gomethods"
   "gopkg.in/mgo.v2"
 )
 
diff --git a/driver/mongodb/example/mongodb_test.go b/driver/mongodb/example/mongodb_test.go
index 6070ed73b..dc1076359 100644
--- a/driver/mongodb/example/mongodb_test.go
+++ b/driver/mongodb/example/mongodb_test.go
@@ -3,17 +3,17 @@ package example
 import (
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 
 	"os"
 	"reflect"
 	"time"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/driver/mongodb"
-	"github.com/mattes/migrate/driver/mongodb/gomethods"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/driver/mongodb"
+	"gopkg.in/mattes/migrate.v1/driver/mongodb/gomethods"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 type ExpectedMigrationResult struct {
diff --git a/driver/mongodb/example/sample_mongdb_migrator.go b/driver/mongodb/example/sample_mongdb_migrator.go
index 227874e7b..ec0135e84 100644
--- a/driver/mongodb/example/sample_mongdb_migrator.go
+++ b/driver/mongodb/example/sample_mongdb_migrator.go
@@ -3,12 +3,12 @@ package example
 import (
 	"time"
 
-	"github.com/mattes/migrate/driver/mongodb/gomethods"
-	_ "github.com/mattes/migrate/driver/mongodb/gomethods"
+	"gopkg.in/mattes/migrate.v1/driver/mongodb/gomethods"
+	_ "gopkg.in/mattes/migrate.v1/driver/mongodb/gomethods"
 	"gopkg.in/mgo.v2"
 	"gopkg.in/mgo.v2/bson"
 
-	"github.com/mattes/migrate/driver/mongodb"
+	"gopkg.in/mattes/migrate.v1/driver/mongodb"
 )
 
 type SampleMongoDbMigrator struct {
diff --git a/driver/mongodb/gomethods/gomethods_migrator.go b/driver/mongodb/gomethods/gomethods_migrator.go
index d53f7d91a..bf0432dc1 100644
--- a/driver/mongodb/gomethods/gomethods_migrator.go
+++ b/driver/mongodb/gomethods/gomethods_migrator.go
@@ -7,8 +7,8 @@ import (
 	"path"
 	"strings"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
 )
 
 type MethodNotFoundError string
diff --git a/driver/mongodb/gomethods/gomethods_migrator_test.go b/driver/mongodb/gomethods/gomethods_migrator_test.go
index d94506ee2..a0c3505a9 100644
--- a/driver/mongodb/gomethods/gomethods_migrator_test.go
+++ b/driver/mongodb/gomethods/gomethods_migrator_test.go
@@ -4,10 +4,10 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 
-	pipep "github.com/mattes/migrate/pipe"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 type FakeGoMethodsInvoker struct {
diff --git a/driver/mongodb/gomethods/gomethods_registry.go b/driver/mongodb/gomethods/gomethods_registry.go
index d9a19eed8..b2a73262b 100644
--- a/driver/mongodb/gomethods/gomethods_registry.go
+++ b/driver/mongodb/gomethods/gomethods_registry.go
@@ -4,7 +4,7 @@ import (
 	"fmt"
 	"sync"
 
-	"github.com/mattes/migrate/driver"
+	"gopkg.in/mattes/migrate.v1/driver"
 )
 
 var methodsReceiversMu sync.Mutex
diff --git a/driver/mongodb/mongodb.go b/driver/mongodb/mongodb.go
index 473d2566f..799c9b341 100644
--- a/driver/mongodb/mongodb.go
+++ b/driver/mongodb/mongodb.go
@@ -5,10 +5,10 @@ import (
 	"reflect"
 	"strings"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/driver/mongodb/gomethods"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/driver/mongodb/gomethods"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 	"gopkg.in/mgo.v2"
 	"gopkg.in/mgo.v2/bson"
 )
diff --git a/driver/mssql/mssql.go b/driver/mssql/mssql.go
index 326621d6c..b2aa692cd 100644
--- a/driver/mssql/mssql.go
+++ b/driver/mssql/mssql.go
@@ -7,9 +7,9 @@ import (
 	"fmt"
 
 	"github.com/denisenkom/go-mssqldb"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 type Driver struct {
diff --git a/driver/mssql/mssql_test.go b/driver/mssql/mssql_test.go
index fddc4e917..67acb0fb4 100644
--- a/driver/mssql/mssql_test.go
+++ b/driver/mssql/mssql_test.go
@@ -2,14 +2,14 @@ package mssql
 
 import (
 	"database/sql"
+	"fmt"
 	"os"
 	"testing"
 	"time"
-	"fmt"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // TestMigrate runs some additional tests on Migrate().
@@ -38,13 +38,13 @@ func TestMigrate(t *testing.T) {
 	for tick := range ticker.C {
 		if tick.After(until) {
 			ticker.Stop()
-			break;
+			break
 		}
 		connection, err = sql.Open("mssql", driverURL)
 		err = connection.Ping()
 		if err == nil {
 			ticker.Stop()
-			break;
+			break
 		}
 	}
 
diff --git a/driver/mysql/README.md b/driver/mysql/README.md
index 3977f1c3f..74e097cb8 100644
--- a/driver/mysql/README.md
+++ b/driver/mysql/README.md
@@ -21,4 +21,4 @@ See full [DSN (Data Source Name) documentation](https://github.com/go-sql-driver
 
 ## Authors
 
-* Matthias Kadenbach, https://github.com/mattes
\ No newline at end of file
+* Matthias Kadenbach, https://github.com/mattes
diff --git a/driver/mysql/mysql.go b/driver/mysql/mysql.go
index 2bbbc1317..5e29174fc 100644
--- a/driver/mysql/mysql.go
+++ b/driver/mysql/mysql.go
@@ -12,9 +12,9 @@ import (
 	"strings"
 
 	"github.com/go-sql-driver/mysql"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 type Driver struct {
diff --git a/driver/mysql/mysql_test.go b/driver/mysql/mysql_test.go
index ec1927166..4d42370ad 100644
--- a/driver/mysql/mysql_test.go
+++ b/driver/mysql/mysql_test.go
@@ -6,9 +6,9 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // TestMigrate runs some additional tests on Migrate().
diff --git a/driver/neo4j/README.md b/driver/neo4j/README.md
index 5a708cf06..5396c6716 100644
--- a/driver/neo4j/README.md
+++ b/driver/neo4j/README.md
@@ -17,4 +17,4 @@ migrate help # for more info
 ```
 ## Author
 
-* Carlos Forero, https://github.com/carlosforero
\ No newline at end of file
+* Carlos Forero, https://github.com/carlosforero
diff --git a/driver/neo4j/neo4j.go b/driver/neo4j/neo4j.go
index 6446473ab..e7b3edf6e 100644
--- a/driver/neo4j/neo4j.go
+++ b/driver/neo4j/neo4j.go
@@ -6,9 +6,9 @@ import (
 	"errors"
 	"fmt"
 	"github.com/jmcvetta/neoism"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 	"strings"
 )
 
diff --git a/driver/neo4j/neo4j_test.go b/driver/neo4j/neo4j_test.go
index b1a86eebf..49462c082 100644
--- a/driver/neo4j/neo4j_test.go
+++ b/driver/neo4j/neo4j_test.go
@@ -5,9 +5,9 @@ import (
 	"testing"
 
 	"github.com/jmcvetta/neoism"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // TestMigrate runs some additional tests on Migrate().
diff --git a/driver/postgres/postgres.go b/driver/postgres/postgres.go
index 77e2ae2ce..a7c2397d0 100644
--- a/driver/postgres/postgres.go
+++ b/driver/postgres/postgres.go
@@ -8,9 +8,9 @@ import (
 	"strconv"
 
 	"github.com/lib/pq"
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 type Driver struct {
diff --git a/driver/postgres/postgres_test.go b/driver/postgres/postgres_test.go
index 1a5c4d7cb..983708715 100644
--- a/driver/postgres/postgres_test.go
+++ b/driver/postgres/postgres_test.go
@@ -5,9 +5,9 @@ import (
 	"os"
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // TestMigrate runs some additional tests on Migrate().
diff --git a/driver/ql/ql.go b/driver/ql/ql.go
index 898ed7d25..21e40bfe4 100644
--- a/driver/ql/ql.go
+++ b/driver/ql/ql.go
@@ -3,9 +3,9 @@ package ql
 import (
 	"database/sql"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 
 	"fmt"
 	"strings"
diff --git a/driver/sqlite3/sqlite3.go b/driver/sqlite3/sqlite3.go
index b245eb187..103f6de92 100644
--- a/driver/sqlite3/sqlite3.go
+++ b/driver/sqlite3/sqlite3.go
@@ -7,10 +7,10 @@ import (
 	"fmt"
 	"strings"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
 	"github.com/mattn/go-sqlite3"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 type Driver struct {
diff --git a/driver/sqlite3/sqlite3_test.go b/driver/sqlite3/sqlite3_test.go
index 57dc77928..8d0fc5355 100644
--- a/driver/sqlite3/sqlite3_test.go
+++ b/driver/sqlite3/sqlite3_test.go
@@ -4,9 +4,9 @@ import (
 	"database/sql"
 	"testing"
 
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // TestMigrate runs some additional tests on Migrate()
diff --git a/file/file.go b/file/file.go
index ccda7d6b0..b79b2b955 100644
--- a/file/file.go
+++ b/file/file.go
@@ -13,7 +13,7 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 var filenameRegex = `^([0-9]+)_(.*)\.(up|down)\.%s$`
diff --git a/file/file_test.go b/file/file_test.go
index b55f05c8e..e237c91bf 100644
--- a/file/file_test.go
+++ b/file/file_test.go
@@ -6,7 +6,7 @@ import (
 	"path"
 	"testing"
 
-	"github.com/mattes/migrate/migrate/direction"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
 )
 
 func TestParseFilenameSchema(t *testing.T) {
diff --git a/main.go b/main.go
index 9d7f2b6cd..18c7afca3 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,6 @@
 // Package main is the CLI.
 // You can use the CLI via Terminal.
-// import "github.com/mattes/migrate/migrate" for usage within Go.
+// import "gopkg.in/mattes/migrate.v1/migrate" for usage within Go.
 package main
 
 import (
@@ -11,19 +11,19 @@ import (
 	"time"
 
 	"github.com/fatih/color"
-	_ "github.com/mattes/migrate/driver/bash"
-	_ "github.com/mattes/migrate/driver/cassandra"
-	_ "github.com/mattes/migrate/driver/crate"
-	_ "github.com/mattes/migrate/driver/mssql"
-	_ "github.com/mattes/migrate/driver/mysql"
-	_ "github.com/mattes/migrate/driver/neo4j"
-	_ "github.com/mattes/migrate/driver/postgres"
-	_ "github.com/mattes/migrate/driver/ql"
-	_ "github.com/mattes/migrate/driver/sqlite3"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	_ "gopkg.in/mattes/migrate.v1/driver/bash"
+	_ "gopkg.in/mattes/migrate.v1/driver/cassandra"
+	_ "gopkg.in/mattes/migrate.v1/driver/crate"
+	_ "gopkg.in/mattes/migrate.v1/driver/mssql"
+	_ "gopkg.in/mattes/migrate.v1/driver/mysql"
+	_ "gopkg.in/mattes/migrate.v1/driver/neo4j"
+	_ "gopkg.in/mattes/migrate.v1/driver/postgres"
+	_ "gopkg.in/mattes/migrate.v1/driver/ql"
+	_ "gopkg.in/mattes/migrate.v1/driver/sqlite3"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 var url = flag.String("url", os.Getenv("MIGRATE_URL"), "")
diff --git a/migrate/migrate.go b/migrate/migrate.go
index 4fdef5d47..f7c9c9628 100644
--- a/migrate/migrate.go
+++ b/migrate/migrate.go
@@ -12,10 +12,10 @@ import (
 	"strings"
 	"time"
 
-	"github.com/mattes/migrate/driver"
-	"github.com/mattes/migrate/file"
-	"github.com/mattes/migrate/migrate/direction"
-	pipep "github.com/mattes/migrate/pipe"
+	"gopkg.in/mattes/migrate.v1/driver"
+	"gopkg.in/mattes/migrate.v1/file"
+	"gopkg.in/mattes/migrate.v1/migrate/direction"
+	pipep "gopkg.in/mattes/migrate.v1/pipe"
 )
 
 // Up applies all available migrations
diff --git a/migrate/migrate_test.go b/migrate/migrate_test.go
index 8801ff81b..594f4f594 100644
--- a/migrate/migrate_test.go
+++ b/migrate/migrate_test.go
@@ -8,9 +8,9 @@ import (
 
 	// Ensure imports for each driver we wish to test
 
-	_ "github.com/mattes/migrate/driver/postgres"
-	_ "github.com/mattes/migrate/driver/ql"
-	_ "github.com/mattes/migrate/driver/sqlite3"
+	_ "gopkg.in/mattes/migrate.v1/driver/postgres"
+	_ "gopkg.in/mattes/migrate.v1/driver/ql"
+	_ "gopkg.in/mattes/migrate.v1/driver/sqlite3"
 )
 
 // Add Driver URLs here to test basic Up, Down, .. functions.

From 964e6bc070748b85e90cf0cd443cecf513172db1 Mon Sep 17 00:00:00 2001
From: Matthias Kadenbach <matthias.kadenbach@gmail.com>
Date: Sat, 6 May 2017 16:18:32 -0700
Subject: [PATCH 22/23] rewrite in readmes

---
 README.md                | 12 ++++++------
 driver/mongodb/README.md |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 81f45ed63..613538451 100644
--- a/README.md
+++ b/README.md
@@ -11,13 +11,13 @@ A migration helper written in Go. Use it in your existing Golang code
 or run commands via the CLI. 
 
 ```
-GoCode   import github.com/mattes/migrate/migrate
-CLI      go get -u github.com/mattes/migrate
+GoCode   import gopkg.in/mattes/migrate.v1/migrate
+CLI      go get -u gopkg.in/mattes/migrate.v1
 ```
 
 __Features__
 
-* Super easy to implement [Driver interface](http://godoc.org/github.com/mattes/migrate/driver#Driver).
+* Super easy to implement [Driver interface](http://godoc.org/gopkg.in/mattes/migrate.v1/driver#Driver).
 * Gracefully quit running migrations on ``^C``.
 * No magic search paths routines, no hard-coded config files.
 * CLI is build on top of the ``migrate package``.
@@ -35,14 +35,14 @@ __Features__
  * [CrateDB](driver/crate)
  * [MSSQL](driver/mssql)
 
-Need another driver? Just implement the [Driver interface](http://godoc.org/github.com/mattes/migrate/driver#Driver) and open a PR.
+Need another driver? Just implement the [Driver interface](http://godoc.org/gopkg.in/mattes/migrate.v1/driver#Driver) and open a PR.
 
 
 ## Usage from Terminal
 
 ```bash
 # install
-go get github.com/mattes/migrate
+go get gopkg.in/mattes/migrate.v1
 
 # create new migration file in path
 migrate -url driver://url -path ./migrations create migration_file_xyz
@@ -81,7 +81,7 @@ migrate -url driver://url -path ./migrations goto v
 
 ## Usage in Go
 
-See GoDoc here: http://godoc.org/github.com/mattes/migrate/migrate
+See GoDoc here: http://godoc.org/gopkg.in/mattes/migrate.v1/migrate
 
 ```go
 import "gopkg.in/mattes/migrate.v1/migrate"
diff --git a/driver/mongodb/README.md b/driver/mongodb/README.md
index 0c49aa638..799159d61 100644
--- a/driver/mongodb/README.md
+++ b/driver/mongodb/README.md
@@ -59,7 +59,7 @@ V001_some_migration_operation_down
 
 ## Methods registration
 
-For a detailed example see: [sample_mongodb_migrator.go](https://github.com/mattes/migrate/blob/master/driver/mongodb/example/sample_mongdb_migrator.go)
+For a detailed example see: [sample_mongodb_migrator.go](https://github.com/mattes/migrate/blob/v1/driver/mongodb/example/sample_mongdb_migrator.go)
 
 ```go
 package my_mongo_db_migrator

From 250543a561b25fa0cc1af2fb151de8265a1bd34c Mon Sep 17 00:00:00 2001
From: Sam Mulube <sam@thingful.net>
Date: Mon, 8 May 2017 17:53:28 +0100
Subject: [PATCH 23/23] Register neo4j driver using a pseudo `neo4js` protocol
 scheme.

Neo4J supports both `http` and `https` connections, however `https`
connections weren't supported previously as the `neo4j` URL scheme
currently used to identify the driver type is always substituted for
just `http`.

This PR also registers the driver under an alternate key: `neo4js` which
given the way the scheme substitution happens, should allow the driver
to correctly create an `https` connection URL. This will allow the
library to be used for cases where we don't have access to the plain
`http` endpoint.
---
 driver/neo4j/neo4j.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/driver/neo4j/neo4j.go b/driver/neo4j/neo4j.go
index 6446473ab..14d118333 100644
--- a/driver/neo4j/neo4j.go
+++ b/driver/neo4j/neo4j.go
@@ -163,4 +163,5 @@ func (driver *Driver) Version() (uint64, error) {
 
 func init() {
 	driver.RegisterDriver("neo4j", &Driver{})
+	driver.RegisterDriver("neo4js", &Driver{})
 }
