Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
enable:
- goconst
- misspell
- modernize
- nakedret
- prealloc
- revive
Expand Down
2 changes: 1 addition & 1 deletion database/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *mockDriver) Drop() error {
func TestRegisterTwice(t *testing.T) {
Register("mock", &mockDriver{})

var err interface{}
var err any
func() {
defer func() {
err = recover()
Expand Down
6 changes: 3 additions & 3 deletions database/neo4j/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (n *Neo4j) Run(migration io.Reader) (err error) {
}()

if n.config.MultiStatement {
_, err = session.WriteTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
_, err = session.WriteTransaction(func(transaction neo4j.Transaction) (any, error) {
var stmtRunErr error
if err := multistmt.Parse(migration, StatementSeparator, n.config.MultiStatementMaxSize, func(stmt []byte) bool {
trimStmt := bytes.TrimSpace(stmt)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (n *Neo4j) SetVersion(version int, dirty bool) (err error) {

query := fmt.Sprintf("MERGE (sm:%s {version: $version}) SET sm.dirty = $dirty, sm.ts = datetime()",
n.config.MigrationsLabel)
_, err = neo4j.Collect(session.Run(query, map[string]interface{}{"version": version, "dirty": dirty}))
_, err = neo4j.Collect(session.Run(query, map[string]any{"version": version, "dirty": dirty}))
if err != nil {
return err
}
Expand All @@ -220,7 +220,7 @@ func (n *Neo4j) Version() (version int, dirty bool, err error) {
query := fmt.Sprintf(`MATCH (sm:%s) RETURN sm.version AS version, sm.dirty AS dirty
ORDER BY COALESCE(sm.ts, datetime({year: 0})) DESC, sm.version DESC LIMIT 1`,
n.config.MigrationsLabel)
result, err := session.ReadTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
result, err := session.ReadTransaction(func(transaction neo4j.Transaction) (any, error) {
result, err := transaction.Run(query, nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion database/pgx/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand Down
2 changes: 1 addition & 1 deletion database/pgx/v5/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand Down
2 changes: 1 addition & 1 deletion database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func testWithInstanceConcurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand Down
2 changes: 1 addition & 1 deletion database/rqlite/rqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (r *Rqlite) SetVersion(version int, dirty bool) error {
if version >= 0 || (version == database.NilVersion && dirty) {
statements = append(statements, gorqlite.ParameterizedStatement{
Query: insertQuery,
Arguments: []interface{}{
Arguments: []any{
version,
dirty,
},
Expand Down
2 changes: 1 addition & 1 deletion database/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (s *Spanner) SetVersion(version int, dirty bool) error {
spanner.Delete(s.config.MigrationsTable, spanner.AllKeys()),
spanner.Insert(s.config.MigrationsTable,
[]string{"Version", "Dirty"},
[]interface{}{version, dirty},
[]any{version, dirty},
)}
return txn.BufferWrite(m)
})
Expand Down
4 changes: 2 additions & 2 deletions database/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {

type Stub struct {
Url string
Instance interface{}
Instance any
CurrentVersion int
MigrationSequence []string
LastRunMigration []byte // todo: make []string
Expand All @@ -35,7 +35,7 @@ func (s *Stub) Open(url string) (database.Driver, error) {

type Config struct{}

func WithInstance(instance interface{}, config *Config) (database.Driver, error) {
func WithInstance(instance any, config *Config) (database.Driver, error) {
return &Stub{
Instance: instance,
CurrentVersion: database.NilVersion,
Expand Down
1 change: 0 additions & 1 deletion dktesting/dktesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func ParallelTest(t *testing.T, specs []ContainerSpec,
testFunc func(*testing.T, dktest.ContainerInfo)) {

for i, spec := range specs {
spec := spec // capture range variable, see https://goo.gl/60w3p2

// Only test against one version in short mode
// TODO: order is random, maybe always pick first version instead?
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Log struct {
}

// Printf prints out formatted string into a log
func (l *Log) Printf(format string, v ...interface{}) {
func (l *Log) Printf(format string, v ...any) {
if l.verbose {
logpkg.Printf(format, v...)
} else {
Expand All @@ -21,7 +21,7 @@ func (l *Log) Printf(format string, v ...interface{}) {
}

// Println prints out args into a log
func (l *Log) Println(args ...interface{}) {
func (l *Log) Println(args ...any) {
if l.verbose {
logpkg.Println(args...)
} else {
Expand All @@ -34,7 +34,7 @@ func (l *Log) Verbose() bool {
return l.verbose
}

func (l *Log) fatal(args ...interface{}) {
func (l *Log) fatal(args ...any) {
l.Println(args...)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package migrate
type Logger interface {

// Printf is like fmt.Printf
Printf(format string, v ...interface{})
Printf(format string, v ...any)

// Verbose should return true when verbose logging output is wanted
Verbose() bool
Expand Down
22 changes: 11 additions & 11 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (m *Migrate) Migrate(version uint) error {
return m.unlockErr(ErrDirty{curVersion})
}

ret := make(chan interface{}, m.PrefetchMigrations)
ret := make(chan any, m.PrefetchMigrations)
go m.read(curVersion, int(version), ret)

return m.unlockErr(m.runMigrations(ret))
Expand All @@ -249,7 +249,7 @@ func (m *Migrate) Steps(n int) error {
return m.unlockErr(ErrDirty{curVersion})
}

ret := make(chan interface{}, m.PrefetchMigrations)
ret := make(chan any, m.PrefetchMigrations)

if n > 0 {
go m.readUp(curVersion, n, ret)
Expand All @@ -276,7 +276,7 @@ func (m *Migrate) Up() error {
return m.unlockErr(ErrDirty{curVersion})
}

ret := make(chan interface{}, m.PrefetchMigrations)
ret := make(chan any, m.PrefetchMigrations)

go m.readUp(curVersion, -1, ret)
return m.unlockErr(m.runMigrations(ret))
Expand All @@ -298,7 +298,7 @@ func (m *Migrate) Down() error {
return m.unlockErr(ErrDirty{curVersion})
}

ret := make(chan interface{}, m.PrefetchMigrations)
ret := make(chan any, m.PrefetchMigrations)
go m.readDown(curVersion, -1, ret)
return m.unlockErr(m.runMigrations(ret))
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func (m *Migrate) Run(migration ...*Migration) error {
return m.unlockErr(ErrDirty{curVersion})
}

ret := make(chan interface{}, m.PrefetchMigrations)
ret := make(chan any, m.PrefetchMigrations)

go func() {
defer close(ret)
Expand Down Expand Up @@ -397,7 +397,7 @@ func (m *Migrate) Version() (version uint, dirty bool, err error) {
// Each migration is then written to the ret channel.
// If an error occurs during reading, that error is written to the ret channel, too.
// Once read is done reading it will close the ret channel.
func (m *Migrate) read(from int, to int, ret chan<- interface{}) {
func (m *Migrate) read(from int, to int, ret chan<- any) {
defer close(ret)

// check if from version exists
Expand Down Expand Up @@ -529,7 +529,7 @@ func (m *Migrate) read(from int, to int, ret chan<- interface{}) {
// Each migration is then written to the ret channel.
// If an error occurs during reading, that error is written to the ret channel, too.
// Once readUp is done reading it will close the ret channel.
func (m *Migrate) readUp(from int, limit int, ret chan<- interface{}) {
func (m *Migrate) readUp(from int, limit int, ret chan<- any) {
defer close(ret)

// check if from version exists
Expand Down Expand Up @@ -629,7 +629,7 @@ func (m *Migrate) readUp(from int, limit int, ret chan<- interface{}) {
// Each migration is then written to the ret channel.
// If an error occurs during reading, that error is written to the ret channel, too.
// Once readDown is done reading it will close the ret channel.
func (m *Migrate) readDown(from int, limit int, ret chan<- interface{}) {
func (m *Migrate) readDown(from int, limit int, ret chan<- any) {
defer close(ret)

// check if from version exists
Expand Down Expand Up @@ -720,7 +720,7 @@ func (m *Migrate) readDown(from int, limit int, ret chan<- interface{}) {
// Before running a newly received migration it will check if it's supposed
// to stop execution because it might have received a stop signal on the
// GracefulStop channel.
func (m *Migrate) runMigrations(ret <-chan interface{}) error {
func (m *Migrate) runMigrations(ret <-chan any) error {
for r := range ret {

if m.stop() {
Expand Down Expand Up @@ -958,14 +958,14 @@ func (m *Migrate) unlockErr(prevErr error) error {
}

// logPrintf writes to m.Log if not nil
func (m *Migrate) logPrintf(format string, v ...interface{}) {
func (m *Migrate) logPrintf(format string, v ...any) {
if m.Log != nil {
m.Log.Printf(format, v...)
}
}

// logVerbosePrintf writes to m.Log if not nil. Use for verbose logging output.
func (m *Migrate) logVerbosePrintf(format string, v ...interface{}) {
func (m *Migrate) logVerbosePrintf(format string, v ...any) {
if m.Log != nil && m.Log.Verbose() {
m.Log.Printf(format, v...)
}
Expand Down
10 changes: 5 additions & 5 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ func TestRead(t *testing.T) {
}

for i, v := range tt {
ret := make(chan interface{})
ret := make(chan any)
go m.read(v.from, v.to, ret)
migrations, err := migrationsFromChannel(ret)

Expand Down Expand Up @@ -1216,7 +1216,7 @@ func TestReadUp(t *testing.T) {
}

for i, v := range tt {
ret := make(chan interface{})
ret := make(chan any)
go m.readUp(v.from, v.limit, ret)
migrations, err := migrationsFromChannel(ret)

Expand Down Expand Up @@ -1293,7 +1293,7 @@ func TestReadDown(t *testing.T) {
}

for i, v := range tt {
ret := make(chan interface{})
ret := make(chan any)
go m.readDown(v.from, v.limit, ret)
migrations, err := migrationsFromChannel(ret)

Expand All @@ -1319,7 +1319,7 @@ func TestLock(t *testing.T) {
}
}

func migrationsFromChannel(ret chan interface{}) ([]*Migration, error) {
func migrationsFromChannel(ret chan any) ([]*Migration, error) {
slice := make([]*Migration, 0)
for r := range ret {
switch t := r.(type) {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ func equalMigSeq(t *testing.T, i int, expected, got migrationSequence) {
t.Errorf("expected migrations %v, got %v, in %v", expected, got, i)

} else {
for ii := 0; ii < len(expected); ii++ {
for ii := range expected {
if expected[ii].Version != got[ii].Version {
t.Errorf("expected version %v, got %v, in %v", expected[ii].Version, got[ii].Version, i)
}
Expand Down
10 changes: 5 additions & 5 deletions source/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func mustWriteFile(t testing.TB, dir, file string, body string) {
func mustCreateBenchmarkDir(t *testing.B) (dir string) {
tmpDir := t.TempDir()

for i := 0; i < 1000; i++ {
for i := range 1000 {
mustWriteFile(t, tmpDir, fmt.Sprintf("%v_foobar.up.sql", i), "")
mustWriteFile(t, tmpDir, fmt.Sprintf("%v_foobar.down.sql", i), "")
}
Expand All @@ -171,8 +171,8 @@ func BenchmarkOpen(b *testing.B) {
b.Error(err)
}
}()
b.ResetTimer()
for n := 0; n < b.N; n++ {

for b.Loop() {
f := &File{}
_, err := f.Open(scheme + dir)
if err != nil {
Expand All @@ -191,9 +191,9 @@ func BenchmarkNext(b *testing.B) {
}()
f := &File{}
d, _ := f.Open(scheme + dir)
b.ResetTimer()

v, err := d.First()
for n := 0; n < b.N; n++ {
for b.Loop() {
for !errors.Is(err, os.ErrNotExist) {
v, err = d.Next(v)
}
Expand Down
2 changes: 1 addition & 1 deletion source/go_bindata/go-bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
ErrNoAssetSource = fmt.Errorf("expects *AssetSource")
)

func WithInstance(instance interface{}) (source.Driver, error) {
func WithInstance(instance any) (source.Driver, error) {
if _, ok := instance.(*AssetSource); !ok {
return nil, ErrNoAssetSource
}
Expand Down
5 changes: 2 additions & 3 deletions source/migration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package source

import (
"slices"
"sort"
)

Expand Down Expand Up @@ -70,9 +71,7 @@ func (i *Migrations) buildIndex() {
for version := range i.migrations {
i.index = append(i.index, version)
}
sort.Slice(i.index, func(x, y int) bool {
return i.index[x] < i.index[y]
})
slices.Sort(i.index)
}

func (i *Migrations) First() (version uint, ok bool) {
Expand Down
4 changes: 2 additions & 2 deletions source/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct{}

type Stub struct {
Url string
Instance interface{}
Instance any
Migrations *source.Migrations
Config *Config
}
Expand All @@ -33,7 +33,7 @@ func (s *Stub) Open(url string) (source.Driver, error) {
}, nil
}

func WithInstance(instance interface{}, config *Config) (source.Driver, error) {
func WithInstance(instance any, config *Config) (source.Driver, error) {
return &Stub{
Instance: instance,
Migrations: source.NewMigrations(),
Expand Down
1 change: 0 additions & 1 deletion testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn
}

for i, version := range versions {
version := version // capture range variable, see https://goo.gl/60w3p2

// Only test against one version in short mode
// TODO: order is random, maybe always pick first version instead?
Expand Down
Loading