Skip to content

Fix table error from BG migration rake task

Patrick Bair requested to merge pb-fix-rake-error-with-no-table into master

What does this MR do and why?

Fix an error that can occur when running db:migrate during development. If we rollback the schema too far, the db:migrate task will fail, due to trying to process batched background migrations against a database state where the batched_background_migrations table doesn't exist.

It's pretty uncommon to run into this, but I hit it frequently when working/testing through the removal of old migrations recently.

How to set up and validate locally

  1. On master, roll back migrations to the beginning, and you'll see the error about the missing table
    bundle exec rails db:migrate VERSION=20181228175414
    
    rails aborted!
    ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "batched_background_migrations" does not exist
    LINE 8:  WHERE a.attrelid = '"batched_background_migrations"'::regcl...
  2. On this branch, run the same command, and it should be fine

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports

Loading