heroku / heroku/heroku-buildpack-ruby
Find a way to generate schema cache: `db/schema_cache.yml`
- Dominant language
- Ruby
- Stars
- 785
- Forks
- 1.8k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 8
Description
There's a cool feature called the schema cache: https://kirshatrov.com/2016/12/13/schema-cache/
Here's some problems with using this feature on Heroku.
## Problem 1
The officially sanctioned method to run database migrations is via release phase:
```
release: rake db:migrate
```
That is because this fires on slug promotion from staging to production and other times when no build is triggered. In short it fires every time your app is released.
The big limitation is that modifications to disk are not preserved in the release phase. So if you run migrations and then generate a schema cache, welp, that schema cache isn't going to do anything because it's saved as a disk modification which is discarded via release phase.
## ~~Problem 2~~ See update at the bottom
Original:
We could generate the schema dump at build time instead of at release time, however what happens if you are deploying with a new migration. What will happen is this:
- app deploys
- schema cache is generated
- release phase fires
- new schema is updated
- app boots using the data from the schema cache that is outdated.
Update: It turns out this is not correct. The schema cache falls back to the old behavior if it detects that the versions are not up to date https://github.com/rails/rails/blob/1d2f553d16d8e3ee1dd6622b96ad98a72ea98d2d/activerecord/lib/active_record/railtie.rb#L136-L141.
So in the best case, after deploys that migrate the database you'll not take advantage of the schema cache. In the worst case if you're deploying with a migration on every deploy, you would be no worse off.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.