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

Specialize Rails7 Database setup on Heroku CI #1257

Merged
merged 3 commits into from
Jan 4, 2022

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Jan 3, 2022

Part 1: Test Rails 7 on Heroku CI

Added a test for Rails 7 to exercise behavior in #1254. Update the Rails 7 example app to use the released version instead of alpha. Also, I updated the app to be a Heroku CI compatible app (adds app.json):

Add CI tests against Rails 7. Which was needed to test specialization

Part 2: Rails 7 Rake tasks for tests

Background

The Ruby buildpack sets up a Rails app's database for a customer. In Rails there are individual migrations which will add or remove a single table/column/etc. Then there is a "schema" that captures the final result of the whole process. Running individual migrations is fragile and prone to break it's also slow. To speed things up we first apply the saved schema, then we run the migrations.

Rails has two different formats for storing schema. There is a simplified "ruby" format that uses a DSL to describe the schema of the database. This is easy to read and understand but it doesn't support database specific calls (for example a GIN index in postgres cannot be applied to a Mysql database). So before we can apply a schema we have to determine which format of schema the developer wants us to apply.

Both schema formats can live in the app at the same time and they can be switched via a config flag in the app.

We handled that previously by calling these two tasks if they existed:

    schema_load    = rake.task("db:schema:load_if_ruby")
    structure_load = rake.task("db:structure:load_if_sql")

Otherwise we would fallback on calling:

rails runner 'puts ActiveRecord::Base.schema_format'

In Rails 6.1 the tasks used for database setup in our test pack were deprecated. They were removed in Rails 7 https://edgeguides.rubyonrails.org/7_0_release_notes.html. Existing Rails 7 apps still fallback to the rails runner method but it is slower and error prone see #1254.

Fix

This PR moves to specialize the tasks for Rails7+ to use db:schema:load per deprecation instruction:

DEPRECATION WARNING: Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0. Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead. (called from <main> at /app/bin/rake:4)

That task will handle the logic for both determining the schema format and applying the schema.

GUS-W-10372684

@schneems schneems force-pushed the schneems/rails7-fix-heroku-ci branch 2 times, most recently from 074d272 to 2e98e35 Compare January 3, 2022 22:20
@schneems schneems changed the title Test Rails 7 app against Heroku CI Specialize Rails7 Database setup Jan 4, 2022
@schneems schneems changed the title Specialize Rails7 Database setup Specialize Rails7 Database setup on Heroku CI Jan 4, 2022
@schneems schneems force-pushed the schneems/rails7-fix-heroku-ci branch from 2e98e35 to 888d7da Compare January 4, 2022 15:47
@schneems
Copy link
Contributor Author

schneems commented Jan 4, 2022

Related internal ticket number: 1064070

@schneems schneems marked this pull request as ready for review January 4, 2022 15:48
@schneems schneems requested a review from a team as a code owner January 4, 2022 15:48
Added a test for Rails 7 to exercise behavior in #1254. Update the Rails 7 example app to use the released version instead of alpha. Also update the app to be Heroku CI compat app (adds app.json):

- sharpstone/rails-jsbundling@34bd25c
- sharpstone/rails-jsbundling@a98a4e4
- sharpstone/rails-jsbundling@b4ec664
- sharpstone/rails-jsbundling@1fb48b4

Add CI tests against Rails 7
In Rails 6.1 the tasks used for database setup in our test pack were deprecated. They were removed in Rails 7 https://edgeguides.rubyonrails.org/7_0_release_notes.html.

This commit moves to specialize the tasks for Rails7+ to use `db:schema:load` per deprecation instruction:

```
DEPRECATION WARNING: Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0. Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead. (called from <main> at /app/bin/rake:4)
```
@schneems schneems force-pushed the schneems/rails7-fix-heroku-ci branch from 888d7da to 5cd2c55 Compare January 4, 2022 15:53
@schneems schneems merged commit 689ec98 into main Jan 4, 2022
@schneems schneems deleted the schneems/rails7-fix-heroku-ci branch January 4, 2022 20:27
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