Pending Migration Error usability concerns

Moving some talk from other threads about pending migration errors into here.

Since you choose the generous title ā€œDatabase migrationsā€, I am gonna add my WTF:

You happily create a new rails project or startup your existing one.

rails new blog
rails server # You are even greeted with a happy landing page on a new project!

now you decide to create some code.

rails generate scaffold posts title content:text

You reload the page and you are greeted with a wonderfully aggressive exception in red.

This seems to be acceptable if you start a project and need to setup your database. But now consider the following context. Your app exists already. You decide itā€™s time to create a new db migration to add new field:

rails generate migration add_hidden_flag_to_posts

Does the app really need to come to a full stop just because I am in the process of adding a column to any table in my database? Should it really affect every view in my whole app, WTF? I canā€™t even check some related views anymore. I certainly would love a banner with a warning and might deal with some additional errors in some views. Of course, I still have to be notified that migrations are pending, but not like this.

This is not a big issue at all but it does affect my developer experience every single time.

1 Like

I really dislike that big error message as well. We should be able to catch the Pending Migrations Error and give it a dedicated page that shows WHAT is pending, and a clear button to migrate, or, better yet, perhaps just ignore for now.

Anyway, would love starting from the point of giving this error a dedicated screen. In fact, I think a lot of exceptions should have dedicated screens where we can explain exactly why youā€™re likely to hit them, give you some pointers on where to go next, etc.

13 Likes

Feels like I wasnā€™t the first one who had this thought:

1 Like

If you ask me, pending migration pains are a symptom of schema modifications not being adapted to the development workflow. I still think the point is really worthwile ā€“ seems like thereā€™s some wide desire to improve on that, we might want to split off the thread for this topic if that helps.

I wonder if we should catch this on boot in dev, if we can get away catching it in an intializer we could even just prompt the user to run migrations when they run rails s

% RAILS_ENV=development bin/rails s

You have pending migrations, would you like to run them now? Y/n

Clearly not something for any other environment except for dev.

2 Likes

Donā€™t know about others, but I usually have a long running rails s which only gets restarted when absolutely needed. This approach wouldnā€™t show up much in my use case.

3 Likes

Iā€™d go so far as to say that pending migrations should indeed just run by default in development and test, but those environments only. Iā€™ve never once not wanted to run pending migrations.

5 Likes

I want to agree with this but I can also see this sequence and what happens when we just run them without waiting for confirmation:

  • have rails dev server running
  • generate new migration but I want write some extra lines in it
  • refresh app page in browser and trigger the migration by accident
  • modify migration file.
  • Ups, you need to redo the migration as it was already run.

And in this scenario we have a very unpleasant tango where I need to rollback the migration in state before I updated it (A lot of ā€œUndoā€ actions in an editor), update migration again and then run it again.

So overall simple prompt with actionable Y/N to run the migration at will seems to be less risky approach and will still solve the big Exception roadlock we have now.

2 Likes

Iā€™m not sure if this fits within the spirit of the month, but I thought Iā€™d raise something thatā€™s bugged me since it was first introduced and that is the ActiveRecord::PendingMigrationError exception that is rendered in development mode for pending migrations.

In my workflow, I often find myself generating a new migration but then needing to still navigate around my app while I work out what fields are required. The pending migrations error is a road block that I feel like I keep running into. I am aware of the config.active_record.migration_error setting but Iā€™m often creating new apps for testing gems, bugs, etc and forgetting to set it again.

What Iā€™d love to see, now that we have actionable errors, is an action alongside the existing ā€˜Run pending migrationsā€™, that would allow me to ignore the exception for that migration for the duration of the session.

4 Likes

I think this (or something similar) would be really nice to see as within the last two weeks I have found myself temporarily changing config.active_record.migration_error while crafting some more delicate migrations in an existing application.

Itā€™s not in the public API, but wouldnā€™t ActionDispatch::ActionableExceptions be useful for that?

3 Likes