Skip to content

Commit

Permalink
Specialize Rails7 Database setup
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
schneems committed Jan 4, 2022
1 parent b2b6a99 commit 5cd2c55
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Main (unreleased)

* Fix deprecated rake tasks for Rails 7 on Heroku CI (https://github.com/heroku/heroku-buildpack-ruby/pull/1257)

## v235 (2022/01/03)

* Bundler 2.x is now 2.2.33 (https://github.com/heroku/heroku-buildpack-ruby/pull/1248)
Expand Down
3 changes: 3 additions & 0 deletions lib/language_pack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
module LanguagePack::Test
end

# Behavior changes for the test pack work by opening existing language_pack
# classes and over-writing their behavior to extend test functionality
require "language_pack/test/ruby"
require "language_pack/test/rails2"
require "language_pack/test/rails7"
4 changes: 2 additions & 2 deletions lib/language_pack/test/rails2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#module LanguagePack::Test::Rails2
# Opens up the class of the Rails2 language pack and
# overwrites methods defined in `language_pack/test/ruby.rb`
class LanguagePack::Rails2
# sets up the profile.d script for this buildpack
def setup_profiled(ruby_layer_path: , gem_layer_path: )
Expand Down Expand Up @@ -51,7 +52,6 @@ def clear_db_test_tasks
end
end

private
def db_prepare_test_rake_tasks
schema_load = rake.task("db:schema:load_if_ruby")
structure_load = rake.task("db:structure:load_if_sql")
Expand Down
9 changes: 9 additions & 0 deletions lib/language_pack/test/rails7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Opens up the class of the Rails7 language pack and
# overwrites methods defined in `language_pack/test/ruby.rb` or `language_pack/test/rails2.rb`
class LanguagePack::Rails7
# Rails removed the db:schema:load_if_ruby and `db:structure:load_if_sql` tasks
# they've been replaced by `db:schema:load` instead
def db_prepare_test_rake_tasks
["db:schema:load", "db:migrate"].map {|name| rake.task(name) }
end
end
7 changes: 5 additions & 2 deletions lib/language_pack/test/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#module LanguagePack::Test::Ruby
# Opens up the class of the Ruby language pack and
# overwrites methods defined in `language_pack/ruby.rb`
#
# Other "test packs" futher extend this behavior by hooking into
# methods or over writing methods defined here.
class LanguagePack::Ruby
def compile
new_app?
Expand Down Expand Up @@ -26,7 +30,6 @@ def compile
super
end

private
def db_prepare_test_rake_tasks
["db:schema:load", "db:migrate"].map {|name| rake.task(name) }
end
Expand Down

0 comments on commit 5cd2c55

Please sign in to comment.