summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/migrate
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace/bun/migrate')
-rw-r--r--vendor/github.com/uptrace/bun/migrate/migration.go12
-rw-r--r--vendor/github.com/uptrace/bun/migrate/migrations.go2
-rw-r--r--vendor/github.com/uptrace/bun/migrate/migrator.go10
3 files changed, 19 insertions, 5 deletions
diff --git a/vendor/github.com/uptrace/bun/migrate/migration.go b/vendor/github.com/uptrace/bun/migrate/migration.go
index 6f395b7b4..1a4a67511 100644
--- a/vendor/github.com/uptrace/bun/migrate/migration.go
+++ b/vendor/github.com/uptrace/bun/migrate/migration.go
@@ -97,10 +97,15 @@ func Exec(ctx context.Context, db *bun.DB, f io.Reader, isTx bool) error {
}
var retErr error
+ var execErr error
defer func() {
if tx, ok := idb.(bun.Tx); ok {
- retErr = tx.Commit()
+ if execErr != nil {
+ retErr = tx.Rollback()
+ } else {
+ retErr = tx.Commit()
+ }
return
}
@@ -113,8 +118,9 @@ func Exec(ctx context.Context, db *bun.DB, f io.Reader, isTx bool) error {
}()
for _, q := range queries {
- if _, err := idb.ExecContext(ctx, q); err != nil {
- return err
+ _, execErr = idb.ExecContext(ctx, q)
+ if execErr != nil {
+ return execErr
}
}
diff --git a/vendor/github.com/uptrace/bun/migrate/migrations.go b/vendor/github.com/uptrace/bun/migrate/migrations.go
index 0e26a09cc..289735270 100644
--- a/vendor/github.com/uptrace/bun/migrate/migrations.go
+++ b/vendor/github.com/uptrace/bun/migrate/migrations.go
@@ -157,7 +157,7 @@ func migrationFile() string {
return ""
}
-var fnameRE = regexp.MustCompile(`^(\d{14})_([0-9a-z_\-]+)\.`)
+var fnameRE = regexp.MustCompile(`^(\d{1,14})_([0-9a-z_\-]+)\.`)
func extractMigrationName(fpath string) (string, string, error) {
fname := filepath.Base(fpath)
diff --git a/vendor/github.com/uptrace/bun/migrate/migrator.go b/vendor/github.com/uptrace/bun/migrate/migrator.go
index e24dba808..5cae6ccb9 100644
--- a/vendor/github.com/uptrace/bun/migrate/migrator.go
+++ b/vendor/github.com/uptrace/bun/migrate/migrator.go
@@ -217,6 +217,7 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr
type goMigrationConfig struct {
packageName string
+ goTemplate string
}
type GoMigrationOption func(cfg *goMigrationConfig)
@@ -227,12 +228,19 @@ func WithPackageName(name string) GoMigrationOption {
}
}
+func WithGoTemplate(template string) GoMigrationOption {
+ return func(cfg *goMigrationConfig) {
+ cfg.goTemplate = template
+ }
+}
+
// CreateGoMigration creates a Go migration file.
func (m *Migrator) CreateGoMigration(
ctx context.Context, name string, opts ...GoMigrationOption,
) (*MigrationFile, error) {
cfg := &goMigrationConfig{
packageName: "migrations",
+ goTemplate: goTemplate,
}
for _, opt := range opts {
opt(cfg)
@@ -245,7 +253,7 @@ func (m *Migrator) CreateGoMigration(
fname := name + ".go"
fpath := filepath.Join(m.migrations.getDirectory(), fname)
- content := fmt.Sprintf(goTemplate, cfg.packageName)
+ content := fmt.Sprintf(cfg.goTemplate, cfg.packageName)
if err := ioutil.WriteFile(fpath, []byte(content), 0o644); err != nil {
return nil, err