Skip to content

Commit

Permalink
feat: rename option
Browse files Browse the repository at this point in the history
  • Loading branch information
greeflas committed Mar 5, 2023
1 parent f31bf73 commit 9353a3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions migrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr

type goMigrationConfig struct {
packageName string
content string
goTemplate string
}

type GoMigrationOption func(cfg *goMigrationConfig)
Expand All @@ -228,9 +228,9 @@ func WithPackageName(name string) GoMigrationOption {
}
}

func WithContent(content string) GoMigrationOption {
func WithGoTemplate(template string) GoMigrationOption {
return func(cfg *goMigrationConfig) {
cfg.content = content
cfg.goTemplate = template
}
}

Expand All @@ -240,7 +240,7 @@ func (m *Migrator) CreateGoMigration(
) (*MigrationFile, error) {
cfg := &goMigrationConfig{
packageName: "migrations",
content: goTemplate,
goTemplate: goTemplate,
}
for _, opt := range opts {
opt(cfg)
Expand All @@ -253,7 +253,7 @@ func (m *Migrator) CreateGoMigration(

fname := name + ".go"
fpath := filepath.Join(m.migrations.getDirectory(), fname)
content := fmt.Sprintf(cfg.content, cfg.packageName)
content := fmt.Sprintf(cfg.goTemplate, cfg.packageName)

if err := ioutil.WriteFile(fpath, []byte(content), 0o644); err != nil {
return nil, err
Expand Down

0 comments on commit 9353a3f

Please sign in to comment.