MCPcopy
hub / github.com/hasura/graphql-engine / runMigrations

Method runMigrations

cli/migrate/migrate.go:1287–1326  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1285// to stop execution because it might have received a stop signal on the
1286// GracefulStop channel.
1287func (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
1328func (m *Migrate) runDryRun(ret <-chan interface{}) error {
1329 var op herrors.Op = "migrate.Migrate.runDryRun"

Callers 5

MigrateMethod · 0.95
StepsMethod · 0.95
UpMethod · 0.95
DownMethod · 0.95
GotoVersionMethod · 0.95

Calls 9

stopMethod · 0.95
startProgressBarFunction · 0.85
setWidthProgressBarFunction · 0.85
finishProgressBarFunction · 0.85
incrementProgressBarFunction · 0.85
ResetQueryMethod · 0.65
RunMethod · 0.65
SetVersionMethod · 0.65
RemoveVersionMethod · 0.65

Tested by

no test coverage detected