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

Add Error Actions to ActiveRecord::NoDatabaseError #42951

Closed
wants to merge 1 commit into from

Conversation

dbenton9
Copy link

@dbenton9 dbenton9 commented Aug 5, 2021

Summary

We love the actionable error for pending migrations and thought it would be beneficial to extend the functionality to ActiveRecord::NoDatabaseError. This is particularly helpful when you've pulled down a repo, fire up a server, but forget to run db:setup. This would create a shortcut to click a button instead of having to stop the server, run the db:setup and restart.

Kudos to @soberstadt for the help and the idea!

Other Information

I don't know if this needs testing assuming the methods we are calling are already tested...

Demo

# requires a config/database.yml:
# development:
#   adapter: postgresql
#   database: single_file 

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "rails", github: "dbenton/rails", branch: "main"
  gem "actionpack"
  gem "railties"
  gem "pg"
end

require "action_controller/railtie"
require "active_record/railtie"
require "rails/command"
require "rails/commands/server/server_command"

class HelloWorldApp < Rails::Application
  config.eager_load = "development"
  config.consider_all_requests_local = true

  routes.append do
    get "/" => "hello#world"
  end
end

class HelloController < ActionController::Base
  def world
    ActiveRecord::Migration.check_pending!
    render :plain => "Hello world!"
  end
end

class World < ActiveRecord::Base
end

HelloWorldApp.initialize!
Rails::Server.new(app: HelloWorldApp, Host: "0.0.0.0", Port: 3000).start

Screen Shot 2021-08-05 at 4 50 53 PM

@rafaelfranca
Copy link
Member

Thank you for the pull request but this is duplicate of #39723 which is more complete.

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

Successfully merging this pull request may close these issues.

2 participants