fix: Remove required Close from database.Migrate (#25)

* fix: Remove required Close from database.Migrate

* Remove dbName from Migrate function arguments

* Fix func call
This commit is contained in:
Kyle Carberry
2022-01-14 10:30:26 -06:00
committed by GitHub
parent a461bc1454
commit 5c49f1f15f
5 changed files with 13 additions and 16 deletions

View File

@ -25,7 +25,7 @@ func main() {
if err != nil {
panic(err)
}
err = database.Migrate(context.Background(), "postgres", db)
err = database.Migrate(context.Background(), db)
if err != nil {
panic(err)
}

View File

@ -16,7 +16,7 @@ import (
var migrations embed.FS
// Migrate runs SQL migrations to ensure the database schema is up-to-date.
func Migrate(ctx context.Context, dbName string, db *sql.DB) error {
func Migrate(ctx context.Context, db *sql.DB) error {
sourceDriver, err := iofs.New(migrations, "migrations")
if err != nil {
return xerrors.Errorf("create iofs: %w", err)
@ -25,7 +25,7 @@ func Migrate(ctx context.Context, dbName string, db *sql.DB) error {
if err != nil {
return xerrors.Errorf("wrap postgres connection: %w", err)
}
m, err := migrate.NewWithInstance("", sourceDriver, dbName, dbDriver)
m, err := migrate.NewWithInstance("", sourceDriver, "", dbDriver)
if err != nil {
return xerrors.Errorf("migrate: %w", err)
}
@ -37,12 +37,5 @@ func Migrate(ctx context.Context, dbName string, db *sql.DB) error {
}
return xerrors.Errorf("up: %w", err)
}
srcErr, dbErr := m.Close()
if srcErr != nil {
return xerrors.Errorf("close source: %w", err)
}
if dbErr != nil {
return xerrors.Errorf("close database: %w", err)
}
return nil
}

View File

@ -7,10 +7,11 @@ import (
"database/sql"
"testing"
"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
)
func TestMain(m *testing.M) {
@ -25,6 +26,7 @@ func TestMigrate(t *testing.T) {
defer closeFn()
db, err := sql.Open("postgres", connection)
require.NoError(t, err)
err = database.Migrate(context.Background(), "postgres", db)
defer db.Close()
err = database.Migrate(context.Background(), db)
require.NoError(t, err)
}

View File

@ -4,9 +4,10 @@ import (
"context"
"testing"
"github.com/coder/coder/database"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/database"
)
func TestPubsubMemory(t *testing.T) {

View File

@ -7,10 +7,11 @@ import (
"database/sql"
"testing"
"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/database"
"github.com/coder/coder/database/postgres"
)
func TestPubsub(t *testing.T) {