[chore] Update a bunch of database dependencies (#1772)

* [chore] Update a bunch of database dependencies

* fix lil thing
This commit is contained in:
tobi 2023-05-12 14:33:40 +02:00 committed by GitHub
commit ec325fee14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
402 changed files with 35068 additions and 35401 deletions

View file

@ -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
}
}

View file

@ -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)

View file

@ -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