From 4a7e0e5305b9ddff60a6da502dce939bf420b556 Mon Sep 17 00:00:00 2001 From: "Sergey A. Glukhov" Date: Mon, 20 May 2024 11:27:50 +0300 Subject: [PATCH 1/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05a9b14b..a46a4d3e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rails Data Migrations -![Build](https://github.com/OffgridElectric/rails-data-migrations/workflows/Test/badge.svg?branch=master) +![Build](https://github.com/abjab/rails-data-migrations/workflows/Test/badge.svg?branch=master) ![Rubocop](https://github.com/OffgridElectric/rails-data-migrations/workflows/Rubocop/badge.svg?branch=master) [![Gem Version](https://badge.fury.io/rb/rails-data-migrations.svg)](https://badge.fury.io/rb/rails-data-migrations) From 368049dd519dc5c654e0ae8d8495746ab9c59cf8 Mon Sep 17 00:00:00 2001 From: "Sergey A. Glukhov" Date: Mon, 20 May 2024 11:29:00 +0300 Subject: [PATCH 2/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a46a4d3e..f3905d6b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Rails Data Migrations -![Build](https://github.com/abjab/rails-data-migrations/workflows/Test/badge.svg?branch=master) -![Rubocop](https://github.com/OffgridElectric/rails-data-migrations/workflows/Rubocop/badge.svg?branch=master) +![Build](https://github.com/anjlab/rails-data-migrations/workflows/Test/badge.svg?branch=master) +![Rubocop](https://github.com/anjlab/rails-data-migrations/workflows/Rubocop/badge.svg?branch=master) [![Gem Version](https://badge.fury.io/rb/rails-data-migrations.svg)](https://badge.fury.io/rb/rails-data-migrations) ## Why? From 26aebf96784b61028ba2d0fc1036bb67fbd4cbfa Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Mon, 20 May 2024 13:19:09 +0300 Subject: [PATCH 3/4] fix CI workflows, add new rubies to test matrix --- .github/workflows/checkstyle.yml | 14 ++++++++------ .github/workflows/test.yml | 15 ++++++++------- .gitignore | 1 + .rubocop.yml | 13 ++++++++++++- Appraisals | 6 ++++++ Gemfile | 2 ++ Rakefile | 2 ++ lib/active_record/data_migration.rb | 2 ++ lib/generators/data_migration_generator.rb | 4 +++- .../templates/data_migration_generator.rb | 2 ++ lib/rails-data-migrations.rb | 4 ++-- lib/rails_data_migrations/log_entry.rb | 4 +++- lib/rails_data_migrations/migrator.rb | 4 +++- lib/rails_data_migrations/railtie.rb | 2 ++ lib/rails_data_migrations/version.rb | 4 +++- lib/tasks/data_migrations.rake | 6 +++++- rails-data-migrations.gemspec | 7 ++++--- spec/data_migrations_spec.rb | 4 +++- spec/generators/data_migration_generator_spec.rb | 0 spec/spec_helper.rb | 4 +++- 20 files changed, 74 insertions(+), 26 deletions(-) delete mode 100644 spec/generators/data_migration_generator_spec.rb diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 6725cbf2..22ec0703 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -3,7 +3,7 @@ name: Rubocop on: push: branches: - - master + - "*" pull_request: branches: @@ -15,18 +15,20 @@ jobs: steps: - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.5.0 + uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - bundler: 1 + ruby-version: 3.2 bundler-cache: true + - name: Install rubocop + run: gem install rubocop -v "~>1.63" + - name: Run rubocop - run: bundle exec rubocop --parallel --fail-level R + run: rubocop --parallel --fail-level R diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b59639a..329c810f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test on: push: branches: - - master + - "*" pull_request: branches: @@ -18,16 +18,17 @@ jobs: timeout-minutes: 15 strategy: + fail-fast: false matrix: - ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0] + ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3] steps: - name: Cancel previous runs - uses: styfle/cancel-workflow-action@0.5.0 + uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 @@ -35,12 +36,12 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler: 1 - - uses: actions/cache@v2 + - uses: actions/cache@v4 with: path: vendor/bundle - key: ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v2-${{ hashFiles('rails-data-migrations.gemspec', 'Appraisals') }} + key: ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3-${{ hashFiles('rails-data-migrations.gemspec', 'Appraisals') }} restore-keys: | - ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v2- + ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3- - name: Install dependencies run: | diff --git a/.gitignore b/.gitignore index d00b8694..1ea4d7a2 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ /.idea/ spec/db/ gemfiles/ +vendor/ *.gem \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index df2edfa7..408b2d84 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,12 @@ AllCops: Exclude: - 'vendor/**/*' - 'gemfiles/**/*' + TargetRubyVersion: 2.7 -Layout/TrailingBlankLines: +Gemspec/RequiredRubyVersion: + Enabled: false + +Layout/TrailingEmptyLines: Enabled: false Metrics/BlockLength: @@ -12,8 +16,15 @@ Metrics/BlockLength: Metrics/LineLength: Max: 120 +Naming/FileName: + Exclude: + - lib/rails-data-migrations.rb + Style/Documentation: Enabled: false +Style/HashSyntax: + Enabled: false + Style/NumericLiterals: Enabled: false diff --git a/Appraisals b/Appraisals index cd62312d..f619e28b 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ruby_version = Gem::Version.new(RUBY_VERSION) if ruby_version < Gem::Version.new('2.7.0') @@ -18,19 +20,23 @@ if ruby_version < Gem::Version.new('3.0.0') appraise 'rails-5.1' do gem 'rails', '~> 5.1.0' + gem 'sqlite3', '~> 1.3.6' end appraise 'rails-5.2' do gem 'rails', '~> 5.2.0' + gem 'sqlite3', '~> 1.3.6' end end if ruby_version >= Gem::Version.new('2.5.0') appraise 'rails-6.0' do gem 'rails', '~> 6.0.0' + gem 'sqlite3', '~> 1.4.0' end appraise 'rails-6.1' do gem 'rails', '~> 6.1.0' + gem 'sqlite3', '~> 1.4.0' end end diff --git a/Gemfile b/Gemfile index a1cee85f..98c5fb20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in activerecord-data-migrations.gemspec diff --git a/Rakefile b/Rakefile index 4c774a2b..82bb534a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/lib/active_record/data_migration.rb b/lib/active_record/data_migration.rb index ee163b14..2bcc5539 100644 --- a/lib/active_record/data_migration.rb +++ b/lib/active_record/data_migration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails/version' module ActiveRecord diff --git a/lib/generators/data_migration_generator.rb b/lib/generators/data_migration_generator.rb index 231125e5..617341bb 100644 --- a/lib/generators/data_migration_generator.rb +++ b/lib/generators/data_migration_generator.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'rails/generators' require 'rails-data-migrations' class DataMigrationGenerator < Rails::Generators::NamedBase - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path('templates', __dir__) def create_migration_file migration_file_name = diff --git a/lib/generators/templates/data_migration_generator.rb b/lib/generators/templates/data_migration_generator.rb index 35cd9e88..6d13e10a 100644 --- a/lib/generators/templates/data_migration_generator.rb +++ b/lib/generators/templates/data_migration_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ClassName < ActiveRecord::DataMigration def up # put your code here diff --git a/lib/rails-data-migrations.rb b/lib/rails-data-migrations.rb index ef612e39..8eae380d 100644 --- a/lib/rails-data-migrations.rb +++ b/lib/rails-data-migrations.rb @@ -1,4 +1,5 @@ -# rubocop:disable Naming/FileName +# frozen_string_literal: true + require 'rails' require 'active_record' require 'active_record/data_migration' @@ -6,4 +7,3 @@ require 'rails_data_migrations/log_entry' require 'rails_data_migrations/migrator' require 'rails_data_migrations/railtie' -# rubocop:enable Naming/FileName diff --git a/lib/rails_data_migrations/log_entry.rb b/lib/rails_data_migrations/log_entry.rb index 3b90c97d..0fa1b0b1 100644 --- a/lib/rails_data_migrations/log_entry.rb +++ b/lib/rails_data_migrations/log_entry.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module RailsDataMigrations class LogEntry < ::ActiveRecord::SchemaMigration class << self def table_name - ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix + "#{ActiveRecord::Base.table_name_prefix}data_migrations#{ActiveRecord::Base.table_name_suffix}" end def index_name diff --git a/lib/rails_data_migrations/migrator.rb b/lib/rails_data_migrations/migrator.rb index 7725e4e2..1234fcf1 100644 --- a/lib/rails_data_migrations/migrator.rb +++ b/lib/rails_data_migrations/migrator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsDataMigrations class Migrator < ::ActiveRecord::Migrator MIGRATOR_SALT = 2053462855 @@ -61,7 +63,7 @@ def list_pending_migrations already_migrated = get_all_versions list_migrations.reject { |m| already_migrated.include?(m.version) } else - open(migrations_path).pending_migrations + open(migrations_path).pending_migrations # rubocop:disable Security/Open end end diff --git a/lib/rails_data_migrations/railtie.rb b/lib/rails_data_migrations/railtie.rb index c6cb88b1..9df6582b 100644 --- a/lib/rails_data_migrations/railtie.rb +++ b/lib/rails_data_migrations/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails' module RailsDataMigrations diff --git a/lib/rails_data_migrations/version.rb b/lib/rails_data_migrations/version.rb index 9201e431..9cf916d0 100644 --- a/lib/rails_data_migrations/version.rb +++ b/lib/rails_data_migrations/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsDataMigrations - VERSION = '1.2.0'.freeze + VERSION = '1.2.0' end diff --git a/lib/tasks/data_migrations.rake b/lib/tasks/data_migrations.rake index 65a654e2..0f4286e9 100644 --- a/lib/tasks/data_migrations.rake +++ b/lib/tasks/data_migrations.rake @@ -1,8 +1,11 @@ +# frozen_string_literal: true + require 'rake' namespace :data do def apply_single_migration(direction, version) raise 'VERSION is required' unless version + RailsDataMigrations::Migrator.run_migration( direction, RailsDataMigrations::Migrator.migrations_path, @@ -42,7 +45,8 @@ namespace :data do desc 'Skip single data migration using VERSION' task skip: :init_migration do version = ENV['VERSION'].to_i - raise 'VERSION is required' unless version > 0 + raise 'VERSION is required' unless version.positive? + if RailsDataMigrations::LogEntry.where(version: version).any? puts "data migration #{version} was already applied." else diff --git a/rails-data-migrations.gemspec b/rails-data-migrations.gemspec index dd824feb..1d65ad62 100644 --- a/rails-data-migrations.gemspec +++ b/rails-data-migrations.gemspec @@ -1,4 +1,6 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rails_data_migrations/version' @@ -17,12 +19,11 @@ Gem::Specification.new do |spec| end spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] + spec.required_ruby_version = '>= 2.3' spec.add_runtime_dependency 'rails', '>= 4.0.0' spec.add_development_dependency 'appraisal', '~> 2.1' spec.add_development_dependency 'rake', '>= 12.3.3' spec.add_development_dependency 'rspec', '3.5.0' - spec.add_development_dependency 'rubocop', '0.52.1' - spec.add_development_dependency 'sqlite3', '~> 1.3' end diff --git a/spec/data_migrations_spec.rb b/spec/data_migrations_spec.rb index 5f02138f..62fa716f 100644 --- a/spec/data_migrations_spec.rb +++ b/spec/data_migrations_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RailsDataMigrations do @@ -44,7 +46,7 @@ end def load_rake_rasks - load File.expand_path('../../lib/tasks/data_migrations.rake', __FILE__) + load File.expand_path('../lib/tasks/data_migrations.rake', __dir__) Rake::Task.define_task(:environment) end diff --git a/spec/generators/data_migration_generator_spec.rb b/spec/generators/data_migration_generator_spec.rb deleted file mode 100644 index e69de29b..00000000 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a1a9d5b6..39825a10 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails/generators' require 'rake' -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'rails-data-migrations' ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' From 3dd3d60c864a9e50f175a4522379be0244df3f72 Mon Sep 17 00:00:00 2001 From: "Sergey A. Glukhov" Date: Mon, 20 May 2024 13:40:17 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3905d6b..759d2c42 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Rails Data Migrations -![Build](https://github.com/anjlab/rails-data-migrations/workflows/Test/badge.svg?branch=master) -![Rubocop](https://github.com/anjlab/rails-data-migrations/workflows/Rubocop/badge.svg?branch=master) +[![Build](https://github.com/anjlab/rails-data-migrations/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/anjlab/rails-data-migrations/actions/workflows/test.yml) +[![Rubocop](https://github.com/anjlab/rails-data-migrations/actions/workflows/checkstyle.yml/badge.svg?branch=master)](https://github.com/anjlab/rails-data-migrations/actions/workflows/checkstyle.yml) [![Gem Version](https://badge.fury.io/rb/rails-data-migrations.svg)](https://badge.fury.io/rb/rails-data-migrations) ## Why?