tobinjim
tobinjim

Reputation: 1852

Can Rails schema table be outside the database?

We have a legacy PostgreSQL database that is perfectly accessible from a Rails app except that when the vendor provides an update one of the consistency checks they perform against the database fails because Rails has built a "new" table there, the schema migrations table. Is it possible to direct creation of this table elsewhere? Or is it possible to use the schema cache in Rails 4 to effect this? The release notes section 3.3 on General things says "Schema cache dump (commit) - To improve Rails boot time, instead of loading the schema directly from the database, load the schema from a dump file."

Upvotes: 1

Views: 358

Answers (1)

Waynn Lue
Waynn Lue

Reputation: 11375

I found an old blog post about this last time I tried it here. Copying the relevant parts:

To make a dump of your schema, execute the following rake task:

RAILS_ENV=production bundle exec rake db:schema:cache:dump

This will generate a file db/schema_cache.dump, that Rails will use to load the internal state of the SchemaCache instance.

To disable the schema cache dump, add the following to your config/production.rb file:

config.active_record.use_schema_cache_dump = false 

If you would like to clear the schema cache, execute:

RAILS_ENV=production bundle exec rake db:schema:cache:clear

Upvotes: 1

Related Questions