From 77e0814d36071d1e3c9f3db7b4fcce557e91c782 Mon Sep 17 00:00:00 2001 From: Arkadiy Zabazhanov Date: Sun, 5 Nov 2023 20:40:23 +0700 Subject: [PATCH] Add support for Rails 7.1 --- .github/workflows/main.yml | 25 +- .gitignore | 2 + .rubocop.yml | 3 +- Appraisals | 8 + Gemfile | 6 +- Gemfile.lock | 240 ++++++++++-------- Rakefile | 2 +- actual_db_schema.gemspec | 6 +- gemfiles/rails.6.0.gemfile | 13 + gemfiles/rails.6.1.gemfile | 13 + gemfiles/rails.7.0.gemfile | 13 + gemfiles/rails.7.1.gemfile | 13 + .../patches/migration_context.rb | 4 +- test/dummy_app/db/schema.rb | 2 +- test/rake_task_test.rb | 10 +- 15 files changed, 243 insertions(+), 117 deletions(-) create mode 100644 Appraisals create mode 100644 gemfiles/rails.6.0.gemfile create mode 100644 gemfiles/rails.6.1.gemfile create mode 100644 gemfiles/rails.7.0.gemfile create mode 100644 gemfiles/rails.7.1.gemfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b5deb2..d29a866 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,19 +3,23 @@ name: Ruby on: push: branches: - - master + - main pull_request: jobs: build: runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} + name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }} strategy: matrix: - ruby: - - '3.1.2' - + include: + - { ruby: '2.7', rails: '6.0' } + - { ruby: '3.0', rails: '6.1' } + - { ruby: '3.1', rails: '7.0' } + - { ruby: '3.2', rails: '7.1' } + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails.${{ matrix.rails }}.gemfile steps: - uses: actions/checkout@v2 - name: Set up Ruby @@ -25,3 +29,14 @@ jobs: bundler-cache: true - name: Run the default task run: bundle exec rake + + rubocop: + runs-on: ubuntu-latest + name: Rubocop + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + - run: bundle exec rubocop diff --git a/.gitignore b/.gitignore index 46dea40..fa63788 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ /tmp/ /test/dummy_app/tmp/ /test/dummy_app/db/migrate/*.rb +.ruby-version +.ruby-gemset diff --git a/.rubocop.yml b/.rubocop.yml index 6968528..c62aebb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 2.7 Exclude: + - gemfiles/* - test/dummy_app/**/* - vendor/**/* diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..53b1d0b --- /dev/null +++ b/Appraisals @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +%w[6.0 6.1 7.0 7.1].each do |version| + appraise "rails.#{version}" do + gem "activerecord", "~> #{version}.0" + gem "activesupport", "~> #{version}.0" + end +end diff --git a/Gemfile b/Gemfile index e6e2f56..8930c6e 100644 --- a/Gemfile +++ b/Gemfile @@ -5,8 +5,8 @@ source "https://rubygems.org" # Specify your gem's dependencies in actual_db_schema.gemspec gemspec -gem "rake", "~> 13.0" - +gem "activerecord", "~> 7.1.0" +gem "activesupport", "~> 7.1.0" gem "minitest", "~> 5.0" - +gem "rake" gem "rubocop", "~> 1.21" diff --git a/Gemfile.lock b/Gemfile.lock index b432665..aeb1857 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,94 +2,114 @@ PATH remote: . specs: actual_db_schema (0.4.0) - activerecord + activerecord (>= 6.0.0) + activesupport (>= 6.0.0) GEM remote: https://rubygems.org/ specs: - actioncable (7.0.6) - actionpack (= 7.0.6) - activesupport (= 7.0.6) + actioncable (7.1.1) + actionpack (= 7.1.1) + activesupport (= 7.1.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.6) - actionpack (= 7.0.6) - activejob (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + zeitwerk (~> 2.6) + actionmailbox (7.1.1) + actionpack (= 7.1.1) + activejob (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.6) - actionpack (= 7.0.6) - actionview (= 7.0.6) - activejob (= 7.0.6) - activesupport (= 7.0.6) + actionmailer (7.1.1) + actionpack (= 7.1.1) + actionview (= 7.1.1) + activejob (= 7.1.1) + activesupport (= 7.1.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.6) - actionview (= 7.0.6) - activesupport (= 7.0.6) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.1) + actionview (= 7.1.1) + activesupport (= 7.1.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.6) - actionpack (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.1) + actionpack (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.6) - activesupport (= 7.0.6) + actionview (7.1.1) + activesupport (= 7.1.1) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.6) - activesupport (= 7.0.6) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.1) + activesupport (= 7.1.1) globalid (>= 0.3.6) - activemodel (7.0.6) - activesupport (= 7.0.6) - activerecord (7.0.6) - activemodel (= 7.0.6) - activesupport (= 7.0.6) - activestorage (7.0.6) - actionpack (= 7.0.6) - activejob (= 7.0.6) - activerecord (= 7.0.6) - activesupport (= 7.0.6) + activemodel (7.1.1) + activesupport (= 7.1.1) + activerecord (7.1.1) + activemodel (= 7.1.1) + activesupport (= 7.1.1) + timeout (>= 0.4.0) + activestorage (7.1.1) + actionpack (= 7.1.1) + activejob (= 7.1.1) + activerecord (= 7.1.1) + activesupport (= 7.1.1) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.6) + activesupport (7.1.1) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) ast (2.4.2) + base64 (0.1.1) + bigdecimal (3.1.4) builder (3.2.4) concurrent-ruby (1.2.2) + connection_pool (2.4.1) crass (1.0.6) date (3.3.3) debug (1.8.0) irb (>= 1.5.0) reline (>= 0.3.1) + drb (2.1.1) + ruby2_keywords erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) io-console (0.6.0) - irb (1.7.4) - reline (>= 0.3.6) - json (2.6.2) - loofah (2.21.3) + irb (1.8.3) + rdoc + reline (>= 0.3.8) + json (2.6.3) + language_server-protocol (3.17.0.3) + loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -98,98 +118,118 @@ GEM net-pop net-smtp marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.16.3) - net-imap (0.3.6) + mini_mime (1.1.5) + minitest (5.20.0) + mutex_m (0.1.2) + net-imap (0.4.4) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.1) timeout - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol nio4r (2.5.9) - nokogiri (1.15.3-x86_64-darwin) + nokogiri (1.15.4-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.3-x86_64-linux) + nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.1) + parallel (1.23.0) + parser (3.2.2.4) ast (~> 2.4.1) - racc (1.7.1) - rack (2.2.7) + racc + psych (5.1.1.1) + stringio + racc (1.7.3) + rack (3.0.8) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.6) - actioncable (= 7.0.6) - actionmailbox (= 7.0.6) - actionmailer (= 7.0.6) - actionpack (= 7.0.6) - actiontext (= 7.0.6) - actionview (= 7.0.6) - activejob (= 7.0.6) - activemodel (= 7.0.6) - activerecord (= 7.0.6) - activestorage (= 7.0.6) - activesupport (= 7.0.6) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.1) + actioncable (= 7.1.1) + actionmailbox (= 7.1.1) + actionmailer (= 7.1.1) + actionpack (= 7.1.1) + actiontext (= 7.1.1) + actionview (= 7.1.1) + activejob (= 7.1.1) + activemodel (= 7.1.1) + activerecord (= 7.1.1) + activestorage (= 7.1.1) + activesupport (= 7.1.1) bundler (>= 1.15.0) - railties (= 7.0.6) - rails-dom-testing (2.1.1) + railties (= 7.1.1) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.6) - actionpack (= 7.0.6) - activesupport (= 7.0.6) - method_source + railties (7.1.1) + actionpack (= 7.1.1) + activesupport (= 7.1.1) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.6.0) - reline (0.3.6) + rake (13.1.0) + rdoc (6.5.0) + psych (>= 4.0.0) + regexp_parser (2.8.2) + reline (0.3.9) io-console (~> 0.5) - rexml (3.2.5) - rubocop (1.36.0) + rexml (3.2.6) + rubocop (1.57.2) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.21.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) - sqlite3 (1.4.2) - thor (1.2.2) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sqlite3 (1.6.8-x86_64-darwin) + sqlite3 (1.6.8-x86_64-linux) + stringio (3.0.8) + thor (1.3.0) timeout (0.4.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.3.0) - websocket-driver (0.7.5) + unicode-display_width (2.5.0) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.8) + zeitwerk (2.6.12) PLATFORMS x86_64-darwin-20 + x86_64-darwin-22 x86_64-linux DEPENDENCIES + activerecord (~> 7.1.0) + activesupport (~> 7.1.0) actual_db_schema! + appraisal debug minitest (~> 5.0) rails - rake (~> 13.0) + rake rubocop (~> 1.21) sqlite3 diff --git a/Rakefile b/Rakefile index c51a60f..3849cc4 100644 --- a/Rakefile +++ b/Rakefile @@ -13,4 +13,4 @@ require "rubocop/rake_task" RuboCop::RakeTask.new -task default: %i[test rubocop] +task default: %i[test] diff --git a/actual_db_schema.gemspec b/actual_db_schema.gemspec index 535f48a..d139538 100644 --- a/actual_db_schema.gemspec +++ b/actual_db_schema.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| DESC spec.homepage = "https://github.com/widefix/actual_db_schema" spec.license = "MIT" - spec.required_ruby_version = ">= 2.6.0" + spec.required_ruby_version = ">= 2.7.0" # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" @@ -36,8 +36,10 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem - spec.add_dependency "activerecord" + spec.add_runtime_dependency "activerecord", ">= 6.0.0" + spec.add_runtime_dependency "activesupport", ">= 6.0.0" + spec.add_development_dependency "appraisal" spec.add_development_dependency "debug" spec.add_development_dependency "rails" spec.add_development_dependency "sqlite3" diff --git a/gemfiles/rails.6.0.gemfile b/gemfiles/rails.6.0.gemfile new file mode 100644 index 0000000..f3491e8 --- /dev/null +++ b/gemfiles/rails.6.0.gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 6.0.0" +gem "activesupport", "~> 6.0.0" +gem "minitest", "~> 5.0" +gem "rake" +gem "rubocop", "~> 1.21" + +gemspec path: "../" diff --git a/gemfiles/rails.6.1.gemfile b/gemfiles/rails.6.1.gemfile new file mode 100644 index 0000000..1443921 --- /dev/null +++ b/gemfiles/rails.6.1.gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 6.1.0" +gem "activesupport", "~> 6.1.0" +gem "minitest", "~> 5.0" +gem "rake" +gem "rubocop", "~> 1.21" + +gemspec path: "../" diff --git a/gemfiles/rails.7.0.gemfile b/gemfiles/rails.7.0.gemfile new file mode 100644 index 0000000..4b34401 --- /dev/null +++ b/gemfiles/rails.7.0.gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 7.0.0" +gem "activesupport", "~> 7.0.0" +gem "minitest", "~> 5.0" +gem "rake" +gem "rubocop", "~> 1.21" + +gemspec path: "../" diff --git a/gemfiles/rails.7.1.gemfile b/gemfiles/rails.7.1.gemfile new file mode 100644 index 0000000..80f2e5b --- /dev/null +++ b/gemfiles/rails.7.1.gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 7.1.0" +gem "activesupport", "~> 7.1.0" +gem "minitest", "~> 5.0" +gem "rake" +gem "rubocop", "~> 1.21" + +gemspec path: "../" diff --git a/lib/actual_db_schema/patches/migration_context.rb b/lib/actual_db_schema/patches/migration_context.rb index fb4e115..bdd2254 100644 --- a/lib/actual_db_schema/patches/migration_context.rb +++ b/lib/actual_db_schema/patches/migration_context.rb @@ -22,8 +22,10 @@ def rollback_branches def down_migrator_for(migration) if ActiveRecord::Migration.current_version < 6 ActiveRecord::Migrator.new(:down, [migration], migration.version) - else + elsif ActiveRecord::Migration.current_version < 7.1 ActiveRecord::Migrator.new(:down, [migration], schema_migration, migration.version) + else + ActiveRecord::Migrator.new(:down, [migration], schema_migration, internal_metadata, migration.version) end end diff --git a/test/dummy_app/db/schema.rb b/test/dummy_app/db/schema.rb index a3b0495..f23614c 100644 --- a/test/dummy_app/db/schema.rb +++ b/test/dummy_app/db/schema.rb @@ -10,5 +10,5 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 0) do +ActiveRecord::Schema[7.1].define(version: 2013_09_06_111513) do end diff --git a/test/rake_task_test.rb b/test/rake_task_test.rb index 2ab805d..207b006 100644 --- a/test/rake_task_test.rb +++ b/test/rake_task_test.rb @@ -59,7 +59,7 @@ def define_migrations second: "20130906111512_second.rb" }.each do |key, file_name| define_migration_file(file_name, <<~RUBY) - class #{key.to_s.camelize} < ActiveRecord::Migration[7.0] + class #{key.to_s.camelize} < ActiveRecord::Migration[6.0] def up TestingState.up << :#{key} end @@ -84,7 +84,11 @@ def prepare_phantom_migrations before do delete_migrations_files - ActiveRecord::SchemaMigration.create_table + if ActiveRecord::SchemaMigration.respond_to?(:create_table) + ActiveRecord::SchemaMigration.create_table + else + ActiveRecord::SchemaMigration.new(ActiveRecord::Base.connection).create_table + end run_sql("delete from schema_migrations") remove_app_dir("tmp/migrated") define_migrations @@ -119,7 +123,7 @@ def prepare_phantom_migrations describe "with irreversible migration" do before do define_migration_file("20130906111513_irreversible.rb", <<~RUBY) - class Irreversible < ActiveRecord::Migration[7.0] + class Irreversible < ActiveRecord::Migration[6.0] def up TestingState.up << :irreversible end