Skip to content

Commit

Permalink
chore: remove redundant method
Browse files Browse the repository at this point in the history
  • Loading branch information
GAlexIHU committed Sep 4, 2024
1 parent 46dfb8a commit 032e138
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ require (
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w=
github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw=
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
Expand Down
29 changes: 4 additions & 25 deletions tools/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io/fs"

"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/database/pgx"
"github.com/golang-migrate/migrate/v4/source/iofs"
)

Expand All @@ -24,7 +24,7 @@ type Options struct {
DB *sql.DB
FS fs.FS
FSPath string
PGConfig *postgres.Config
PGConfig *pgx.Config
}

// NewMigrate creates a new migrate instance.
Expand All @@ -34,7 +34,7 @@ func NewMigrate(opt Options) (*Migrate, error) {
return nil, err
}

driver, err := postgres.WithInstance(opt.DB, opt.PGConfig)
driver, err := pgx.WithInstance(opt.DB, opt.PGConfig)
if err != nil {
return nil, err
}
Expand All @@ -47,29 +47,8 @@ func Default(db *sql.DB) (*Migrate, error) {
DB: db,
FS: OMMigrations,
FSPath: "migrations",
PGConfig: &postgres.Config{
PGConfig: &pgx.Config{
MigrationsTable: MigrationsTable,
},
})
}

func Up(db *sql.DB) error {
m, err := NewMigrate(Options{
DB: db,
FS: OMMigrations,
FSPath: "migrations",
PGConfig: &postgres.Config{
MigrationsTable: MigrationsTable,
},
})
if err != nil {
return err
}

defer m.Close()
err = m.Up()
if err != nil && err != migrate.ErrNoChange {
return err
}
return nil
}

0 comments on commit 032e138

Please sign in to comment.