Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use schema.rb in gem

I'd like rake db:schema:load to use a db/schema.rb that's not located in my app, but in one of my gems. This already works for db:seed by putting config.paths['db/seeds'] = Core::Engine.paths['db/seeds'].existent in my application.rb. (Core is a gem that's also a Rails engine).

However, there is no db/schema.rb path in config.paths and config.paths['db'] = Core::Engine.paths['db'].existent has no effect.

What's the easiest way to get this done?

like image 553
Michiel de Mare Avatar asked Dec 15 '22 12:12

Michiel de Mare


1 Answers

For anyone who stumbles upon this, as of Rails 4.0 you can set the 'db' key in your engine configuration and the main app will look for your schema there.

active_record/railties/databases.rake

module MyEngine
  class Engine < ::Rails::Engine
    initializer :override_db_dir do |app|
      app.config.paths["db"] = config.paths['db'].expanded
    end
  end
end
like image 80
awilkening Avatar answered Dec 18 '22 02:12

awilkening