Down runs all down SQL migrations.
(db *sql.DB)
| 150 | |
| 151 | // Down runs all down SQL migrations. |
| 152 | func Down(db *sql.DB) error { |
| 153 | _, m, err := setup(db, migrations) |
| 154 | if err != nil { |
| 155 | return xerrors.Errorf("migrate setup: %w", err) |
| 156 | } |
| 157 | |
| 158 | err = m.Down() |
| 159 | if err != nil { |
| 160 | if errors.Is(err, migrate.ErrNoChange) { |
| 161 | // It's OK if no changes happened! |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | return xerrors.Errorf("down: %w", err) |
| 166 | } |
| 167 | |
| 168 | return nil |
| 169 | } |
| 170 | |
| 171 | // EnsureClean checks whether all migrations for the current version have been |
| 172 | // applied, without making any changes to the database. If not, returns a |