Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to check for pending data migrations automatically? #294

Open
matttarantino opened this issue Nov 8, 2023 · 1 comment
Open

Comments

@matttarantino
Copy link

Like schema migrations, you will get an error locally if you have pending schema migrations to run. Is this possible for data migrations as well? It looks like it once existed (#199) but I am not seeing any code anymore.

Do you otherwise need to use the rake tasks to check manually?

@jwoldan
Copy link

jwoldan commented Sep 5, 2024

I'm using this approach plus this check to make sure I'm not currently running a rake task in the development environment file to achieve this. I'd love to know if there's a better approach, but this seems to be working for our use case so sharing in case it's helpful to others. You end up with something like this:

  config.after_initialize do
    # Check if we are currently in a rake task, see https://stackoverflow.com/questions/15538587
    unless (ENV['RACK_ENV'].blank? || ENV['RAILS_ENV'].blank? || !("#{ENV.inspect}" =~ /worker/i).blank?)
      Rails.application.load_tasks
      Rake::Task['data:abort_if_pending_migrations'].invoke
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants