MigrateDown undoes all database migrations, reverting the schema to the initial state.
(engine, uri string)
| 145 | |
| 146 | // MigrateDown undoes all database migrations, reverting the schema to the initial state. |
| 147 | func MigrateDown(engine, uri string) (err error) { |
| 148 | switch engine { |
| 149 | case database.POSTGRES.String(): |
| 150 | var db *PQDatabase.Postgres |
| 151 | db, err = PQDatabase.New(uri) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | defer closeDB(db) |
| 156 | |
| 157 | goose.SetTableName(migrationsTable) |
| 158 | |
| 159 | if err = goose.SetDialect(postgresDialect); err != nil { |
| 160 | return err |
| 161 | } |
| 162 | |
| 163 | goose.SetBaseFS(postgresMigrations) |
| 164 | pool := stdlib.OpenDBFromPool(db.WritePool) |
| 165 | |
| 166 | if err = goose.Down(pool, postgresMigrationDir); err != nil { |
| 167 | return err |
| 168 | } |
| 169 | |
| 170 | return nil |
| 171 | case database.MEMORY.String(): |
| 172 | return nil |
| 173 | default: |
| 174 | return fmt.Errorf("%s connection is unsupported", engine) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // MigrateDownTo undoes database migrations down to a specific version. |
| 179 | func MigrateDownTo(engine, uri string, p int64) (err error) { |
no test coverage detected