ankane/multiverse

Schema Caching from schema_cache.yml dump does not seem to work

Closed this issue · 2 comments

With Rails 5, I'm using rails db:schema:cache:dump to generate db/schema_cache.yml files, which pre-caches your schema in a yml file. This is working properly on my main database. The database task to generate the files is working properly for my 2nd database, generating a db/second/schema_cache.yml, but this file isn't loaded by the schema cache railtie, I think, because it calls first:

File.join(app.config.paths["db"].first, "schema_cache.yml")

Here's the line: https://github.com/rails/rails/blob/v5.2.1/activerecord/lib/active_record/railtie.rb#L91.

I wanted to see if anyone who contributes to multiverse had any suggestions on how to get schema caching working for additional databases. I'd be happy to try to put a PR together, but would need some help determining the correct path forward.

Hey @a-maas, you'll basically want to create an initializer and duplicate that logic for each of the additional databases. I think it'll be tricky to do generically since:

  1. Multiverse does not maintain an list of additional databases (could be inferred by searching db/:database/schema_cache.yml)
  2. The use_schema_cache_dump is deleted from config, so we won't have access to it (could also probably be inferred if schema_cache.yml exists)
  3. There's no explicit mapping from Multiverse databases to base model, and methods in the initializer like connection and connection_pool need to be called on the base model

The approach I'd take is to get a hard-coded version working in your app, then see if it's possible to make it generic.

Added a note in the readme about this limitation.