mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
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:
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user