rails-data-migrations 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecadfdf1ff6e4b9a293770e5f333f7c297cb6821a946a89d698e829a68f5ed5b
4
- data.tar.gz: 665d7d252f71febca0da708f838808b1e165a8f94b7e8fa4f8bd6dcc891339b5
3
+ metadata.gz: 81e0b46ee1de39f2886005424fe92edf73f00bd0eff85ab897609275446faa3b
4
+ data.tar.gz: 8ad2ee73f8fbfecbe5f3ad0eee390bb2585f33d08fbdc8599d0d90a694da6fe0
5
5
  SHA512:
6
- metadata.gz: 1663219b32be0c3803b827d25a2e5ebb8359324ccd78ba65c7b5eea0e8b0119bd95ee854205767b3aa6beb2ab939dc9202f1811c3dce757a94a23043a2c37913
7
- data.tar.gz: 7fcac514b7b565bfcd936d975877188a7fc8c9a52baa74ec64c56ce918cf5376bb3a4f632c835027c95d3c1cb05514c15311ee8ddd34b858cdf9402421584b84
6
+ metadata.gz: e6601d3a3337fb9e3d15c854bb91eec58ad2665260615eadf4bbddc8b03123f7dc755c9a2a64e7ce8c82d9c132c8821ab5386013e30d45e4da386b540c7e7368
7
+ data.tar.gz: dcc120a18ff836d3f6ea0149e3c9ca3c1ae820473b70e95a5e7f80393741581f05bbefee8fd55a3b94baa39974daf4b2404a028a8043592ccad2b96fd85e5db2
@@ -0,0 +1,34 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+
8
+ pull_request:
9
+ branches:
10
+ - master
11
+
12
+ jobs:
13
+ rubocop:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - name: Cancel previous runs
18
+ uses: styfle/cancel-workflow-action@0.12.1
19
+ with:
20
+ access_token: ${{ github.token }}
21
+
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Set up Ruby ${{ matrix.ruby-version }}
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 3.2
28
+ bundler-cache: true
29
+
30
+ - name: Install rubocop
31
+ run: gem install rubocop -v "~>1.63"
32
+
33
+ - name: Run rubocop
34
+ run: rubocop --parallel --fail-level R
@@ -0,0 +1,53 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+
8
+ pull_request:
9
+ branches:
10
+ - master
11
+
12
+ jobs:
13
+ test:
14
+ name: Test
15
+
16
+ runs-on: ubuntu-latest
17
+
18
+ timeout-minutes: 15
19
+
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3]
24
+
25
+ steps:
26
+ - name: Cancel previous runs
27
+ uses: styfle/cancel-workflow-action@0.12.1
28
+ with:
29
+ access_token: ${{ github.token }}
30
+
31
+ - uses: actions/checkout@v4
32
+
33
+ - name: Set up Ruby ${{ matrix.ruby-version }}
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby-version }}
37
+ bundler: 1
38
+
39
+ - uses: actions/cache@v4
40
+ with:
41
+ path: vendor/bundle
42
+ key: ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3-${{ hashFiles('rails-data-migrations.gemspec', 'Appraisals') }}
43
+ restore-keys: |
44
+ ${{ runner.os }}-bundle-${{ matrix.ruby-version }}-v3-
45
+
46
+ - name: Install dependencies
47
+ run: |
48
+ bundle config path vendor/bundle
49
+ bundle install --jobs 4 --retry 3
50
+ bundle exec appraisal install --path vendor/bundle
51
+
52
+ - name: Run tests
53
+ run: bundle exec appraisal rake
data/.gitignore CHANGED
@@ -10,4 +10,5 @@
10
10
  /.idea/
11
11
  spec/db/
12
12
  gemfiles/
13
+ vendor/
13
14
  *.gem
data/.rubocop.yml CHANGED
@@ -1,10 +1,36 @@
1
- Layout/TrailingBlankLines:
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ - 'gemfiles/**/*'
5
+ TargetRubyVersion: 2.7
6
+
7
+ Gemspec/RequiredRubyVersion:
2
8
  Enabled: false
9
+
10
+ Layout/TrailingEmptyLines:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
3
16
  Metrics/BlockLength:
4
17
  Enabled: false
18
+
5
19
  Metrics/LineLength:
6
20
  Max: 120
21
+
22
+ Metrics/MethodLength:
23
+ Enabled: false
24
+
25
+ Naming/FileName:
26
+ Exclude:
27
+ - lib/rails-data-migrations.rb
28
+
7
29
  Style/Documentation:
8
30
  Enabled: false
31
+
32
+ Style/HashSyntax:
33
+ Enabled: false
34
+
9
35
  Style/NumericLiterals:
10
36
  Enabled: false
data/Appraisals CHANGED
@@ -1,27 +1,54 @@
1
- appraise 'rails-4.0' do
2
- gem 'rails', '4.0.13'
3
- end
1
+ # frozen_string_literal: true
4
2
 
5
- appraise 'rails-4.1' do
6
- gem 'rails', '~> 4.1.0'
7
- end
3
+ ruby_version = Gem::Version.new(RUBY_VERSION)
8
4
 
9
- appraise 'rails-4.2.5' do
10
- gem 'rails', '4.2.5'
5
+ if ruby_version < Gem::Version.new('2.7.0')
6
+ ['4.0.0', '4.1.0', '4.2.0'].each do |rails_version|
7
+ appraise "rails-#{rails_version}" do
8
+ gem 'rails', "~> #{rails_version}"
9
+ gem 'bigdecimal', '1.3.5'
10
+ gem 'sqlite3', '~> 1.3.6'
11
+ end
12
+ end
11
13
  end
12
14
 
13
- appraise 'rails-4.2' do
14
- gem 'rails', '~> 4.2.0'
15
- end
15
+ if ruby_version < Gem::Version.new('3.0.0')
16
+ appraise 'rails-5.0' do
17
+ gem 'rails', '~> 5.0.0'
18
+ gem 'sqlite3', '~> 1.3.6'
19
+ end
16
20
 
17
- appraise 'rails-5.0' do
18
- gem 'rails', '~> 5.0.0'
21
+ appraise 'rails-5.1' do
22
+ gem 'rails', '~> 5.1.0'
23
+ gem 'sqlite3', '~> 1.3.6'
24
+ end
25
+
26
+ appraise 'rails-5.2' do
27
+ gem 'rails', '~> 5.2.0'
28
+ gem 'sqlite3', '~> 1.3.6'
29
+ end
19
30
  end
20
31
 
21
- appraise 'rails-5.1' do
22
- gem 'rails', '~> 5.1.0'
32
+ if ruby_version >= Gem::Version.new('2.5.0')
33
+ appraise 'rails-6.0' do
34
+ gem 'rails', '~> 6.0.0'
35
+ gem 'sqlite3', '~> 1.4.0'
36
+ end
37
+
38
+ appraise 'rails-6.1' do
39
+ gem 'rails', '~> 6.1.0'
40
+ gem 'sqlite3', '~> 1.4.0'
41
+ end
23
42
  end
24
43
 
25
- appraise 'rails-5.2' do
26
- gem 'rails', '~> 5.2.0'
44
+ if ruby_version >= Gem::Version.new('2.7.0')
45
+ appraise 'rails-7.0' do
46
+ gem 'rails', '~> 7.0.0'
47
+ gem 'sqlite3', '~> 1.4.0'
48
+ end
49
+
50
+ appraise 'rails-7.1' do
51
+ gem 'rails', '~> 7.1.0'
52
+ gem 'sqlite3', '~> 1.4.0'
53
+ end
27
54
  end
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in activerecord-data-migrations.gemspec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rails Data Migrations
2
2
 
3
- [![Build Status](https://travis-ci.org/OffgridElectric/rails-data-migrations.svg?branch=master)](https://travis-ci.org/OffgridElectric/rails-data-migrations)
3
+ [![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)
4
+ [![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)
4
5
  [![Gem Version](https://badge.fury.io/rb/rails-data-migrations.svg)](https://badge.fury.io/rb/rails-data-migrations)
5
6
 
6
7
  ## Why?
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/version'
2
4
 
3
5
  module ActiveRecord
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
  require 'rails-data-migrations'
3
5
 
4
6
  class DataMigrationGenerator < Rails::Generators::NamedBase
5
- source_root File.expand_path('../templates', __FILE__)
7
+ source_root File.expand_path('templates', __dir__)
6
8
 
7
9
  def create_migration_file
8
10
  migration_file_name =
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ClassName < ActiveRecord::DataMigration
2
4
  def up
3
5
  # put your code here
@@ -1,4 +1,5 @@
1
- # rubocop:disable Naming/FileName
1
+ # frozen_string_literal: true
2
+
2
3
  require 'rails'
3
4
  require 'active_record'
4
5
  require 'active_record/data_migration'
@@ -6,4 +7,3 @@ require 'rails_data_migrations/version'
6
7
  require 'rails_data_migrations/log_entry'
7
8
  require 'rails_data_migrations/migrator'
8
9
  require 'rails_data_migrations/railtie'
9
- # rubocop:enable Naming/FileName
@@ -1,12 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsDataMigrations
2
- class LogEntry < ::ActiveRecord::SchemaMigration
3
- class << self
4
- def table_name
5
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
4
+ module SharedMethods
5
+ def table_name
6
+ "#{ActiveRecord::Base.table_name_prefix}data_migrations#{ActiveRecord::Base.table_name_suffix}"
7
+ end
8
+
9
+ def index_name
10
+ "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
11
+ end
12
+ end
13
+
14
+ if Gem::Version.new('7.1.0') >= Gem::Version.new(::ActiveRecord.version)
15
+ class LogEntry < ::ActiveRecord::SchemaMigration
16
+ class << self
17
+ include SharedMethods
6
18
  end
19
+ end
20
+ else
21
+ class LogEntry < ::ActiveRecord::Base
22
+ class << self
23
+ include SharedMethods
24
+ def create_table
25
+ ::ActiveRecord::SchemaMigration.define_method(:table_name) do
26
+ "#{::ActiveRecord::Base.table_name_prefix}data_migrations#{::ActiveRecord::Base.table_name_suffix}"
27
+ end
7
28
 
8
- def index_name
9
- "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
29
+ ::ActiveRecord::Base.connection.schema_migration.create_table
30
+ end
10
31
  end
11
32
  end
12
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsDataMigrations
2
4
  class Migrator < ::ActiveRecord::Migrator
3
5
  MIGRATOR_SALT = 2053462855
@@ -38,12 +40,26 @@ module RailsDataMigrations
38
40
  'db/data_migrations'
39
41
  end
40
42
 
43
+ def rails_6_0?
44
+ Rails::VERSION::MAJOR >= 6
45
+ end
46
+
41
47
  def rails_5_2?
42
48
  Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2)
43
49
  end
44
50
 
51
+ def rails_7_1?
52
+ Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1
53
+ end
54
+
45
55
  def list_migrations
46
- if rails_5_2?
56
+ if rails_7_1?
57
+ ::ActiveRecord::MigrationContext.new(
58
+ migrations_path, ::ActiveRecord::Base.connection.schema_migration
59
+ ).migrations
60
+ elsif rails_6_0?
61
+ ::ActiveRecord::MigrationContext.new(migrations_path, ::ActiveRecord::SchemaMigration).migrations
62
+ elsif rails_5_2?
47
63
  ::ActiveRecord::MigrationContext.new(migrations_path).migrations
48
64
  else
49
65
  migrations(migrations_path)
@@ -55,12 +71,22 @@ module RailsDataMigrations
55
71
  already_migrated = get_all_versions
56
72
  list_migrations.reject { |m| already_migrated.include?(m.version) }
57
73
  else
58
- open(migrations_path).pending_migrations
74
+ open(migrations_path).pending_migrations # rubocop:disable Security/Open
59
75
  end
60
76
  end
61
77
 
62
78
  def run_migration(direction, migrations_path, version)
63
- if rails_5_2?
79
+ if rails_7_1?
80
+ new(
81
+ direction,
82
+ list_migrations,
83
+ ::ActiveRecord::Base.connection.schema_migration,
84
+ ::ActiveRecord::InternalMetadata.new(ActiveRecord::Base.connection),
85
+ version
86
+ ).run
87
+ elsif rails_6_0?
88
+ new(direction, list_migrations, ::ActiveRecord::SchemaMigration, version).run
89
+ elsif rails_5_2?
64
90
  new(direction, list_migrations, version).run
65
91
  else
66
92
  run(direction, migrations_path, version)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
 
3
5
  module RailsDataMigrations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsDataMigrations
2
- VERSION = '1.1.0'.freeze
4
+ VERSION = '1.3.0'
3
5
  end
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
 
3
5
  namespace :data do
4
6
  def apply_single_migration(direction, version)
5
7
  raise 'VERSION is required' unless version
8
+
6
9
  RailsDataMigrations::Migrator.run_migration(
7
10
  direction,
8
11
  RailsDataMigrations::Migrator.migrations_path,
@@ -42,7 +45,8 @@ namespace :data do
42
45
  desc 'Skip single data migration using VERSION'
43
46
  task skip: :init_migration do
44
47
  version = ENV['VERSION'].to_i
45
- raise 'VERSION is required' unless version > 0
48
+ raise 'VERSION is required' unless version.positive?
49
+
46
50
  if RailsDataMigrations::LogEntry.where(version: version).any?
47
51
  puts "data migration #{version} was already applied."
48
52
  else
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'rails_data_migrations/version'
4
6
 
@@ -17,13 +19,11 @@ Gem::Specification.new do |spec|
17
19
  end
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
21
  spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.3'
20
23
 
21
24
  spec.add_runtime_dependency 'rails', '>= 4.0.0'
22
25
 
23
26
  spec.add_development_dependency 'appraisal', '~> 2.1'
24
- spec.add_development_dependency 'bundler', '~> 1.13'
25
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rake', '>= 12.3.3'
26
28
  spec.add_development_dependency 'rspec', '3.5.0'
27
- spec.add_development_dependency 'rubocop', '0.52.1'
28
- spec.add_development_dependency 'sqlite3', '~> 1.3'
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-data-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Glukhov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2024-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,34 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.13'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.13'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: 12.3.3
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: 12.3.3
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,45 +66,18 @@ dependencies:
80
66
  - - '='
81
67
  - !ruby/object:Gem::Version
82
68
  version: 3.5.0
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 0.52.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 0.52.1
97
- - !ruby/object:Gem::Dependency
98
- name: sqlite3
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.3'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.3'
111
- description:
69
+ description:
112
70
  email:
113
71
  - sergey.glukhov@gmail.com
114
72
  executables: []
115
73
  extensions: []
116
74
  extra_rdoc_files: []
117
75
  files:
76
+ - ".github/workflows/checkstyle.yml"
77
+ - ".github/workflows/test.yml"
118
78
  - ".gitignore"
119
79
  - ".rspec"
120
80
  - ".rubocop.yml"
121
- - ".travis.yml"
122
81
  - Appraisals
123
82
  - Gemfile
124
83
  - LICENSE.txt
@@ -138,7 +97,7 @@ homepage: https://github.com/OffgridElectric/rails-data-migrations
138
97
  licenses:
139
98
  - MIT
140
99
  metadata: {}
141
- post_install_message:
100
+ post_install_message:
142
101
  rdoc_options: []
143
102
  require_paths:
144
103
  - lib
@@ -146,16 +105,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
105
  requirements:
147
106
  - - ">="
148
107
  - !ruby/object:Gem::Version
149
- version: '0'
108
+ version: '2.3'
150
109
  required_rubygems_version: !ruby/object:Gem::Requirement
151
110
  requirements:
152
111
  - - ">="
153
112
  - !ruby/object:Gem::Version
154
113
  version: '0'
155
114
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.7.6
158
- signing_key:
115
+ rubygems_version: 3.1.6
116
+ signing_key:
159
117
  specification_version: 4
160
118
  summary: Run your data migration tasks in a db:migrate-like manner
161
119
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.4
5
- - 2.4.1
6
- - 2.5.0
7
- script: bundle exec appraisal install && bundle exec appraisal rake && rubocop --fail-level R