Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(migrate): use initialized pgx driver #1473

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: export unexported options
GAlexIHU committed Sep 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4bc487a2964c8b86c145a24ac0ea7b8cd1b9308d
28 changes: 14 additions & 14 deletions tools/migrate/migrate.go
Original file line number Diff line number Diff line change
@@ -21,20 +21,20 @@ type Migrate = migrate.Migrate
var OMMigrations embed.FS

type Options struct {
db *sql.DB
fs fs.FS
fsPath string
pgConfig *postgres.Config
DB *sql.DB
FS fs.FS
FSPath string
PGConfig *postgres.Config
}

// NewMigrate creates a new migrate instance.
func NewMigrate(opt Options) (*Migrate, error) {
d, err := iofs.New(opt.fs, opt.fsPath)
d, err := iofs.New(opt.FS, opt.FSPath)
if err != nil {
return nil, err
}

driver, err := postgres.WithInstance(opt.db, opt.pgConfig)
driver, err := postgres.WithInstance(opt.DB, opt.PGConfig)
if err != nil {
return nil, err
}
@@ -44,21 +44,21 @@ func NewMigrate(opt Options) (*Migrate, error) {

func Default(db *sql.DB) (*Migrate, error) {
return NewMigrate(Options{
db: db,
fs: OMMigrations,
fsPath: "migrations",
pgConfig: &postgres.Config{
DB: db,
FS: OMMigrations,
FSPath: "migrations",
PGConfig: &postgres.Config{
MigrationsTable: MigrationsTable,
},
})
}

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