runMigrations reads *Migration and error from a channel. Any other type sent on this channel will result in a panic. Each migration is then proxied to the database driver and run against the database. Before running a newly received migration it will check if it's supposed to stop execution because
(ret <-chan interface{}, bar *pb.ProgressBar)
| 1285 | // to stop execution because it might have received a stop signal on the |
| 1286 | // GracefulStop channel. |
| 1287 | func (m *Migrate) runMigrations(ret <-chan interface{}, bar *pb.ProgressBar) error { |
| 1288 | var op herrors.Op = "migrate.Migrate.runMigrations" |
| 1289 | startProgressBar(bar) |
| 1290 | setWidthProgressBar(bar, m.ProgressBarLogs) |
| 1291 | defer finishProgressBar(bar) |
| 1292 | for r := range ret { |
| 1293 | if m.stop() { |
| 1294 | return nil |
| 1295 | } |
| 1296 | |
| 1297 | switch r := r.(type) { |
| 1298 | case error: |
| 1299 | // Clear Migration query |
| 1300 | m.databaseDrv.ResetQuery() |
| 1301 | return herrors.E(op, r) |
| 1302 | case *Migration: |
| 1303 | if r.Body != nil { |
| 1304 | if !m.SkipExecution { |
| 1305 | m.Logger.Debugf("applying migration: %s", r.FileName) |
| 1306 | if err := m.databaseDrv.Run(r.BufferedBody, r.FileType, r.FileName, m.NoTransaction); err != nil { |
| 1307 | return herrors.E(op, err) |
| 1308 | } |
| 1309 | } |
| 1310 | incrementProgressBar(bar) |
| 1311 | version := int64(r.Version) |
| 1312 | // Insert Version number into the table |
| 1313 | if err := m.databaseDrv.SetVersion(version, false); err != nil { |
| 1314 | return herrors.E(op, err) |
| 1315 | } |
| 1316 | if version != r.TargetVersion { |
| 1317 | // Delete Version number from the table |
| 1318 | if err := m.databaseDrv.RemoveVersion(version); err != nil { |
| 1319 | return herrors.E(op, err) |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | return nil |
| 1326 | } |
| 1327 | |
| 1328 | func (m *Migrate) runDryRun(ret <-chan interface{}) error { |
| 1329 | var op herrors.Op = "migrate.Migrate.runDryRun" |
no test coverage detected