diff options
| author | 2022-08-15 12:35:05 +0200 | |
|---|---|---|
| committer | 2022-08-15 11:35:05 +0100 | |
| commit | ac6ed3d939fe9dad81aadbd04541e905c625ca82 (patch) | |
| tree | 6116baf25675837dc99f69c49b9fec2ff112ce5c /vendor/github.com/uptrace/bun/migrate/migrator.go | |
| parent | [frontend] Sensitive media spoilers (#752) (diff) | |
| download | gotosocial-ac6ed3d939fe9dad81aadbd04541e905c625ca82.tar.xz | |
[chore] Update bun / sqlite versions; update gtsmodels (#754)
* upstep bun and sqlite versions
* allow specific columns to be updated in the db
* only update necessary columns for user
* bit tidier
* only update necessary fields of media_attachment
* only update relevant instance fields
* update tests
* update only specific account columns
* use bool pointers on gtsmodels
includes attachment, status, account, user
* update columns more selectively
* test all default fields on new account insert
* updating remaining bools on gtsmodels
* initialize pointer fields when extracting AP emoji
* copy bools properly
* add copyBoolPtr convenience function + test it
* initialize false bool ptrs a bit more neatly
Diffstat (limited to 'vendor/github.com/uptrace/bun/migrate/migrator.go')
| -rw-r--r-- | vendor/github.com/uptrace/bun/migrate/migrator.go | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/vendor/github.com/uptrace/bun/migrate/migrator.go b/vendor/github.com/uptrace/bun/migrate/migrator.go index e271b7a06..d0efca2fc 100644 --- a/vendor/github.com/uptrace/bun/migrate/migrator.go +++ b/vendor/github.com/uptrace/bun/migrate/migrator.go @@ -26,14 +26,23 @@ func WithLocksTableName(table string) MigratorOption { } } +// WithMarkAppliedOnSuccess sets the migrator to only mark migrations as applied/unapplied +// when their up/down is successful +func WithMarkAppliedOnSuccess(enabled bool) MigratorOption { + return func(m *Migrator) { + m.markAppliedOnSuccess = enabled + } +} + type Migrator struct { db *bun.DB migrations *Migrations ms MigrationSlice - table string - locksTable string + table string + locksTable string + markAppliedOnSuccess bool } func NewMigrator(db *bun.DB, migrations *Migrations, opts ...MigratorOption) *Migrator { @@ -148,9 +157,10 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra migration := &migrations[i] migration.GroupID = group.ID - // Always mark migration as applied so the rollback has a chance to fix the database. - if err := m.MarkApplied(ctx, migration); err != nil { - return group, err + if !m.markAppliedOnSuccess { + if err := m.MarkApplied(ctx, migration); err != nil { + return group, err + } } group.Migrations = migrations[:i+1] @@ -160,6 +170,12 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra return group, err } } + + if m.markAppliedOnSuccess { + if err := m.MarkApplied(ctx, migration); err != nil { + return group, err + } + } } return group, nil @@ -187,14 +203,21 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr for i := len(lastGroup.Migrations) - 1; i >= 0; i-- { migration := &lastGroup.Migrations[i] - // Always mark migration as unapplied to match migrate behavior. - if err := m.MarkUnapplied(ctx, migration); err != nil { - return nil, err + if !m.markAppliedOnSuccess { + if err := m.MarkUnapplied(ctx, migration); err != nil { + return lastGroup, err + } } if !cfg.nop && migration.Down != nil { if err := migration.Down(ctx, m.db); err != nil { - return nil, err + return lastGroup, err + } + } + + if m.markAppliedOnSuccess { + if err := m.MarkUnapplied(ctx, migration); err != nil { + return lastGroup, err } } } |
