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
4 changes: 2 additions & 2 deletions database/cockroachdb/cockroachdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (c *CockroachDb) Close() error {
func (c *CockroachDb) Lock() error {
return database.CasRestoreOnErr(&c.isLocked, false, true, database.ErrLocked, func() (err error) {
return crdb.ExecuteTx(context.Background(), c.db, nil, func(tx *sql.Tx) (err error) {
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
if err != nil {
return err
}
Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *CockroachDb) Lock() error {
// See: https://github.com/cockroachdb/cockroach/issues/13546
func (c *CockroachDb) Unlock() error {
return database.CasRestoreOnErr(&c.isLocked, true, false, database.ErrNotLocked, func() (err error) {
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (m *Mysql) Lock() error {
if m.config.NoLock {
return nil
}
aid, err := database.GenerateAdvisoryLockId(
aid, err := database.GenerateAdvisoryLockID(
fmt.Sprintf("%s:%s", m.config.DatabaseName, m.config.MigrationsTable))
if err != nil {
return err
Expand All @@ -313,7 +313,7 @@ func (m *Mysql) Unlock() error {
return nil
}

aid, err := database.GenerateAdvisoryLockId(
aid, err := database.GenerateAdvisoryLockID(
fmt.Sprintf("%s:%s", m.config.DatabaseName, m.config.MigrationsTable))
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions database/pgx/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (p *Postgres) Unlock() error {

// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
func (p *Postgres) applyAdvisoryLock() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand All @@ -299,7 +299,7 @@ func (p *Postgres) applyTableLock() error {
}
}()

aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName)
if err != nil {
return err
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func (p *Postgres) applyTableLock() error {
}

func (p *Postgres) releaseAdvisoryLock() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand All @@ -345,7 +345,7 @@ func (p *Postgres) releaseAdvisoryLock() error {
}

func (p *Postgres) releaseTableLock() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions database/pgx/v5/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (p *Postgres) Close() error {
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
func (p *Postgres) Lock() error {
return database.CasRestoreOnErr(&p.isLocked, false, true, database.ErrLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand All @@ -236,7 +236,7 @@ func (p *Postgres) Lock() error {

func (p *Postgres) Unlock() error {
return database.CasRestoreOnErr(&p.isLocked, true, false, database.ErrNotLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (p *Postgres) Close() error {
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
func (p *Postgres) Lock() error {
return database.CasRestoreOnErr(&p.isLocked, false, true, database.ErrLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand All @@ -249,7 +249,7 @@ func (p *Postgres) Lock() error {

func (p *Postgres) Unlock() error {
return database.CasRestoreOnErr(&p.isLocked, true, false, database.ErrNotLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions database/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (ss *SQLServer) Close() error {
// Lock creates an advisory local on the database to prevent multiple migrations from running at the same time.
func (ss *SQLServer) Lock() error {
return database.CasRestoreOnErr(&ss.isLocked, false, true, database.ErrLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(ss.config.DatabaseName, ss.config.SchemaName)
aid, err := database.GenerateAdvisoryLockID(ss.config.DatabaseName, ss.config.SchemaName)
if err != nil {
return err
}
Expand Down Expand Up @@ -222,7 +222,7 @@ func (ss *SQLServer) Lock() error {
// Unlock froms the migration lock from the database
func (ss *SQLServer) Unlock() error {
return database.CasRestoreOnErr(&ss.isLocked, true, false, database.ErrNotLocked, func() error {
aid, err := database.GenerateAdvisoryLockId(ss.config.DatabaseName, ss.config.SchemaName)
aid, err := database.GenerateAdvisoryLockID(ss.config.DatabaseName, ss.config.SchemaName)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion database/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestDrop(t *testing.T, d database.Driver) {
}

func TestSetVersion(t *testing.T, d database.Driver) {
// nolint:maligned
testCases := []struct {
name string
version int
Expand Down
4 changes: 2 additions & 2 deletions database/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

const advisoryLockIDSalt uint = 1486364155

// GenerateAdvisoryLockId inspired by rails migrations, see https://goo.gl/8o9bCT
func GenerateAdvisoryLockId(databaseName string, additionalNames ...string) (string, error) { // nolint: golint
// GenerateAdvisoryLockID inspired by rails migrations, see https://goo.gl/8o9bCT
func GenerateAdvisoryLockID(databaseName string, additionalNames ...string) (string, error) {
if len(additionalNames) > 0 {
databaseName = strings.Join(append(additionalNames, databaseName), "\x00")
}
Expand Down
4 changes: 2 additions & 2 deletions database/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
)

func TestGenerateAdvisoryLockId(t *testing.T) {
func TestGenerateAdvisoryLockID(t *testing.T) {
testcases := []struct {
dbname string
additional []string
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestGenerateAdvisoryLockId(t *testing.T) {

for _, tc := range testcases {
t.Run(tc.dbname, func(t *testing.T) {
if id, err := GenerateAdvisoryLockId(tc.dbname, tc.additional...); err == nil {
if id, err := GenerateAdvisoryLockID(tc.dbname, tc.additional...); err == nil {
if id != tc.expectedID {
t.Error("Generated incorrect ID:", id, "!=", tc.expectedID)
}
Expand Down
9 changes: 5 additions & 4 deletions database/yugabytedb/yugabytedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (c *YugabyteDB) Close() error {
func (c *YugabyteDB) Lock() error {
return database.CasRestoreOnErr(&c.isLocked, false, true, database.ErrLocked, func() (err error) {
return c.doTxWithRetry(context.Background(), &sql.TxOptions{Isolation: sql.LevelSerializable}, func(tx *sql.Tx) (err error) {
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
if err != nil {
return err
}
Expand Down Expand Up @@ -230,7 +230,7 @@ func (c *YugabyteDB) Lock() error {
// See: https://github.com/yugabyte/yugabyte-db/issues/3642
func (c *YugabyteDB) Unlock() error {
return database.CasRestoreOnErr(&c.isLocked, true, false, database.ErrNotLocked, func() (err error) {
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
if err != nil {
return err
}
Expand Down Expand Up @@ -420,8 +420,9 @@ func (c *YugabyteDB) doTxWithRetry(
}

// If we've tried to commit the transaction Rollback just returns sql.ErrTxDone.
//nolint:errcheck
defer tx.Rollback()
defer func() {
_ = tx.Rollback()
}()

if err := fn(tx); err != nil {
if errIsRetryable(err) {
Expand Down
5 changes: 0 additions & 5 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,11 +1339,6 @@ func newMigSeq(migr ...*Migration) migrationSequence {
return migr
}

func (m *migrationSequence) add(migr ...*Migration) migrationSequence { // nolint:unused
*m = append(*m, migr...)
return *m
}

func (m *migrationSequence) bodySequence() []string {
r := make([]string, 0)
for _, v := range *m {
Expand Down
21 changes: 10 additions & 11 deletions testing/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (d *DockerContainer) Logs() (io.ReadCloser, error) {
})
}

func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (containerPort uint, hostIP string, hostPort uint, err error) { // nolint:unparam
func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (hostIP string, hostPort uint, err error) {
if !d.containerInspected {
if err := d.Inspect(); err != nil {
d.t.Fatal(err)
Expand All @@ -212,29 +212,28 @@ func (d *DockerContainer) portMapping(selectFirst bool, cPort int) (containerPor
// Skip ahead until we find the port we want
continue
}
for _, binding := range bindings {

if len(bindings) > 0 {
binding := bindings[0]
hostPortUint, err := strconv.ParseUint(binding.HostPort, 10, 64)
if err != nil {
return 0, "", 0, err
return "", 0, err
}

return uint(port.Int()), binding.HostIP, uint(hostPortUint), nil // nolint: staticcheck
return bindings[0].HostIP, uint(hostPortUint), nil
}
}

if selectFirst {
return 0, "", 0, errors.New("no port binding")
return "", 0, errors.New("no port binding")
} else {
return 0, "", 0, errors.New("specified port not bound")
return "", 0, errors.New("specified port not bound")
}
}

func (d *DockerContainer) Host() string {
if d == nil {
panic("Cannot get host for a nil *DockerContainer")
}
_, hostIP, _, err := d.portMapping(true, -1)
hostIP, _, err := d.portMapping(true, -1)
if err != nil {
d.t.Fatal(err)
}
Expand All @@ -250,7 +249,7 @@ func (d *DockerContainer) Port() uint {
if d == nil {
panic("Cannot get port for a nil *DockerContainer")
}
_, _, port, err := d.portMapping(true, -1)
_, port, err := d.portMapping(true, -1)
if err != nil {
d.t.Fatal(err)
}
Expand All @@ -261,7 +260,7 @@ func (d *DockerContainer) PortFor(cPort int) uint {
if d == nil {
panic("Cannot get port for a nil *DockerContainer")
}
_, _, port, err := d.portMapping(false, cPort)
_, port, err := d.portMapping(false, cPort)
if err != nil {
d.t.Fatal(err)
}
Expand Down