data_migrate 9.4.2 → 10.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +3 -3
  3. data/.github/workflows/gempush.yml +8 -6
  4. data/.gitignore +2 -3
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +14 -0
  7. data/Appraisals +5 -5
  8. data/Changelog.md +2 -46
  9. data/Gemfile +1 -0
  10. data/Gemfile.rails6.1 +11 -0
  11. data/README.md +5 -7
  12. data/data_migrate.gemspec +2 -2
  13. data/gemfiles/{rails_7.1.gemfile → rails_6.0.gemfile} +2 -1
  14. data/gemfiles/rails_6.1.gemfile +1 -0
  15. data/gemfiles/rails_7.0.gemfile +2 -1
  16. data/lib/data_migrate/data_migrator.rb +23 -15
  17. data/lib/data_migrate/data_schema.rb +2 -2
  18. data/lib/data_migrate/data_schema_migration.rb +7 -24
  19. data/lib/data_migrate/database_tasks.rb +48 -194
  20. data/lib/data_migrate/legacy_migrator.rb +22 -0
  21. data/lib/data_migrate/migration_context.rb +8 -11
  22. data/lib/data_migrate/schema_dumper.rb +1 -1
  23. data/lib/data_migrate/schema_migration.rb +4 -5
  24. data/lib/data_migrate/status_service.rb +4 -4
  25. data/lib/data_migrate/tasks/data_migrate_tasks.rb +15 -14
  26. data/lib/data_migrate/version.rb +1 -1
  27. data/lib/data_migrate.rb +1 -2
  28. data/spec/data_migrate/data_migrator_spec.rb +14 -17
  29. data/spec/data_migrate/data_schema_migration_spec.rb +8 -25
  30. data/spec/data_migrate/data_spec.rb +1 -1
  31. data/spec/data_migrate/database_tasks_spec.rb +19 -34
  32. data/spec/data_migrate/legacy_migrator_spec.rb +38 -0
  33. data/spec/data_migrate/migration_context_spec.rb +8 -15
  34. data/spec/data_migrate/schema_dumper_spec.rb +3 -6
  35. data/spec/data_migrate/schema_migration_spec.rb +6 -13
  36. data/spec/data_migrate/status_service_spec.rb +4 -7
  37. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +14 -13
  38. data/spec/db/data/20091231235959_some_name.rb +1 -1
  39. data/spec/db/data/20171231235959_super_update.rb +1 -1
  40. data/spec/db/migrate/20131111111111_late_migration.rb +1 -1
  41. data/spec/db/migrate/20202020202011_db_migration.rb +1 -1
  42. data/tasks/databases.rake +83 -25
  43. metadata +19 -21
  44. data/Gemfile.lock +0 -184
  45. data/gemfiles/rails_6.1.gemfile.lock +0 -229
  46. data/gemfiles/rails_7.0.gemfile.lock +0 -230
  47. data/gemfiles/rails_7.1.gemfile.lock +0 -263
  48. data/lib/data_migrate/database_configurations_wrapper.rb +0 -11
  49. data/lib/data_migrate/rails_helper.rb +0 -79
  50. data/lib/data_migrate/test.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b061a1b90d162a48df5225719ec96da94aaa77d0580d952a1ff0f4cb895e452e
4
- data.tar.gz: bc78e03d816377c6a784b8102ce9f6c9504ee4650839436a92b1a949bce6a45d
3
+ metadata.gz: d212f0e6fa0c9b767cbdf17854c7c52d640a9c8611d0b10ed6c0460de68985cd
4
+ data.tar.gz: ac338ef447f1942d64eb5cf6c0fe520f71089968c04fb03fb829a1318534b4eb
5
5
  SHA512:
6
- metadata.gz: 5c612eefd1985b3935c79c87039f1f67db81088a1984fb4e90d15c361d9c0fd90b9acefaeb131ec4b77f22a56f6524a99444e663b5e2e2a820115864b09471ed
7
- data.tar.gz: b2ce56c6fd8510adb0eb465fc765df93fdce42f6d7f81e809276bbaf29f7e1891dd7638191e395af0afb774f1ced8fc33387a9619b09edf24cde824b03aa00a6
6
+ metadata.gz: 01ae940433e4cd51a2f421297fb3ffb72372503971ee906164129c035c89aedb6c18d5003cd083930c24245f16728c38c93aed94fb8d9b2f7d0288895362a3d4
7
+ data.tar.gz: 9d94ff40ed274256247960c0dd1325645b638ac2198d29b3bce2c3c11f842b4b0a2b381bd73fcb17af308ab366cdca16c7f99c9e2fa778da7ab6103352e50ba1
@@ -11,14 +11,14 @@ jobs:
11
11
  matrix:
12
12
  os: [ "ubuntu-20.04" ]
13
13
  ruby:
14
+ - '2.7'
14
15
  - '3.0'
15
16
  - '3.1'
16
17
  - '3.2'
17
- - '3.3'
18
18
  gemfile:
19
+ - gemfiles/rails_6.0.gemfile
19
20
  - gemfiles/rails_6.1.gemfile
20
21
  - gemfiles/rails_7.0.gemfile
21
- - gemfiles/rails_7.1.gemfile
22
22
  runs-on: ubuntu-latest
23
23
  env:
24
24
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
@@ -32,4 +32,4 @@ jobs:
32
32
  ruby-version: ${{ matrix.ruby }}
33
33
  bundler-cache: true
34
34
  - name: Run tests
35
- run: bundle exec rspec
35
+ run: bundle exec rspec
@@ -1,8 +1,10 @@
1
- name: Release Gem
1
+ name: Ruby Gem
2
2
 
3
3
  on:
4
- release:
5
- types: [released]
4
+ push:
5
+ branches:
6
+ - main
7
+ - chaunce-multiple_connection_support
6
8
 
7
9
  jobs:
8
10
  build:
@@ -11,10 +13,10 @@ jobs:
11
13
 
12
14
  steps:
13
15
  - uses: actions/checkout@master
14
- - name: Set up Ruby 3.2
15
- uses: ruby/setup-ruby@v1
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
16
18
  with:
17
- ruby-version: '3.2'
19
+ version: 2.6.x
18
20
 
19
21
  - name: Publish to RubyGems
20
22
  run: |
data/.gitignore CHANGED
@@ -1,12 +1,11 @@
1
1
  /.rvmrc
2
2
  *.gem
3
+ *.lock
3
4
  gemfiles/.bundle
4
5
  spec/db/test.db
5
6
  spec/db/other_test.db
6
7
  spec/db/data_schema.rb
7
8
  .vscode/
8
9
  .DS_Store
9
- .ruby-gemset
10
- .ruby-version
11
10
  .idea/
12
- vendor/
11
+ vendor/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.5
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.7
4
+ - 3.0
5
+ - 3.2
6
+ script: bundle exec rspec
7
+ gemfile:
8
+ - gemfiles/rails_6.0.gemfile
9
+ - gemfiles/rails_6.1.gemfile
10
+ - gemfiles/rails_7.0.gemfile
11
+ jobs:
12
+ exclude:
13
+ - rvm: 3.0
14
+ - rvm: 3.2
data/Appraisals CHANGED
@@ -1,11 +1,11 @@
1
+ appraise 'rails-6.0' do
2
+ gem 'rails', '~> 6.0.0'
3
+ end
4
+
1
5
  appraise 'rails-6.1' do
2
6
  gem 'rails', '~> 6.1.0'
3
7
  end
4
8
 
5
9
  appraise 'rails-7.0' do
6
- gem 'rails', '~> 7.0.0'
7
- end
8
-
9
- appraise 'rails-7.1' do
10
- gem 'rails', '7.1.0'
10
+ gem 'rails', '~> 7.0'
11
11
  end
data/Changelog.md CHANGED
@@ -1,57 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## 9.4.2
4
- - Fix db:prepare:with_data task
5
-
6
- ## 9.4.1
7
- - Add db:prepare task
8
-
9
- ## 9.4.0
10
- - Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
11
- - Run load_config rake task before db:migrate:with_data https://github.com/ilyakatz/data-migrate/pull/308
12
-
13
- ## 9.3.0
14
- - Improve with_data Rake task for multiple database https://github.com/ilyakatz/data-migrate/pull/296
15
-
16
- ## 9.2.0
17
- - Support Rails 7.1 https://github.com/ilyakatz/data-migrate/pull/278
18
- - Build and test against 7.1.0.rc1 https://github.com/ilyakatz/data-migrate/pull/286
19
-
20
- ## 9.1.0
21
-
22
- - Fix a bug that caused `schema_sha1` in `ar_internal_metadata` to be reset to the `data_schema.rb` file. (#272)
23
- - Remove the need for empty data_schema files for non-primary databases. (#273)
24
-
25
- ## [YANKED] 10.0.3.rc
26
-
27
- - Remove all travis references [leoarnold](https//:github.com/leoarnold)
28
- - Changing to rc because of ongoing discussion how to properly handle multiple database environments
29
-
30
- ## [YANKED] 10.0.2
31
-
32
- Change "rails" dependencies to "railties"
33
-
34
- ## [YANKED] 10.0.1
35
-
36
- - Bug fix for Rails 6 config [chaunce](https//:github.com/chaunce)
37
- - Railties bug fix by [opti](https://github.com/opti)
38
-
39
- ## [YANKED] 10.0.0
40
-
41
- Releasing 10.0.0
42
-
43
- !!! Breaking changes !!!
44
-
45
- - This version introduces a breaking change which may lead to undesired
46
- behavior in multi-database environments. See https://github.com/ilyakatz/data-migrate/issues/181
47
-
48
- ## [YANKED] 10.0.0.rc1
3
+ ## 10.0.0.rc1
49
4
 
50
5
  - Changes by [chaunce](https//:github.com/chaunce)
51
6
  - Multiple databases support
52
7
  - Refactor to clean things up
53
8
  - Deprecate rails 5.2 support for real
54
9
 
10
+
55
11
  ## 9.0.0
56
12
 
57
13
  Ruby 3.2 support [mehanoid](https://github.com/mehanoid)
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem 'sqlite3', "~> 1.4"
3
4
  gemspec
data/Gemfile.rails6.1 ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in data_migrate.gemspec
4
+ %w[
5
+ activerecord
6
+ railties
7
+ ].each do |rails_gem|
8
+ gem rails_gem, '~> 6.1.0'
9
+ end
10
+ gem 'sqlite3', "~> 1.4"
11
+ gemspec
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  - [![Version](http://img.shields.io/gem/v/data_migrate.svg?style=flat-square)](https://rubygems.org/gems/data_migrate)
4
4
  - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
5
- - ![.github/workflows/build.yml](https://github.com/ilyakatz/data-migrate/actions/workflows/.github/workflows/build.yml/badge.svg)
5
+ - [![Travis](https://img.shields.io/travis/ilyakatz/data-migrate.svg)](https://travis-ci.org/ilyakatz/data-migrate)
6
6
  - [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
7
7
 
8
8
  Run data migrations alongside schema migrations.
@@ -12,7 +12,7 @@ migrations, except they should be reserved for data migrations. For
12
12
  instance, if you realize you need to titleize all your titles, this
13
13
  is the place to do it.
14
14
 
15
- ![directory tree example](./screenshot.png)
15
+ ![Travis](./screenshot.png)
16
16
 
17
17
  ## Why should I use this?
18
18
 
@@ -36,7 +36,7 @@ table to track all migrations.
36
36
 
37
37
  ## Rails Support
38
38
 
39
- Support Rails 6.1 through 7.1
39
+ Support Rails 6.0 through 7.0
40
40
 
41
41
 
42
42
  #### v1
@@ -96,9 +96,7 @@ Tasks work as they would with the 'vanilla' db version. The 'with_data' addition
96
96
 
97
97
  With 'up' and 'down', you can specify the option 'BOTH', which defaults to false. Using true, will migrate both the data and schema (in the desired direction) if they both match the version provided. Again, going up, schema is given precedence. Down its data.
98
98
 
99
- When using `rake db:migrate:with_data` migrations will be run in ascending order by their version. For example, if you have a data migration with version 20230410000000 and a schema migration with version 20230415000000, expect the data migration to run first.
100
-
101
- `rake db:migrate:status:with_data` provides an additional column to indicate which type of migration.
99
+ `rake db:migrate:status:with_data` provides and additional column to indicate which type of migration.
102
100
 
103
101
  ### Configuration
104
102
 
@@ -164,9 +162,9 @@ Run tests for a specific version of Rails
164
162
 
165
163
  ```
166
164
  bundle exec appraisal install
165
+ bundle exec appraisal rails-6.0 rspec
167
166
  bundle exec appraisal rails-6.1 rspec
168
167
  bundle exec appraisal rails-7.0 rspec
169
- bundle exec appraisal rails-7.1 rspec
170
168
  ```
171
169
 
172
170
  ## Thanks
data/data_migrate.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  activerecord
20
20
  railties
21
21
  ].each do |rails_gem|
22
- s.add_dependency(rails_gem, '>= 6.1')
22
+ s.add_dependency(rails_gem, '>= 6.0')
23
23
  end
24
24
 
25
25
  s.add_development_dependency "appraisal"
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency "rspec-core"
29
29
  s.add_development_dependency "pry"
30
30
  s.add_development_dependency "rb-readline"
31
- s.add_development_dependency "sqlite3"
31
+ s.add_development_dependency "sqlite3", "~> 1.3.6"
32
32
  s.add_development_dependency "timecop"
33
33
  s.add_development_dependency "rubocop"
34
34
  s.add_development_dependency "overcommit"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "7.1.0"
5
+ gem "rails", "~> 6.0.0"
6
+ gem "sqlite3", "~> 1.4"
6
7
 
7
8
  gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 6.1.0"
6
+ gem "sqlite3", "~> 1.4"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 7.0.0"
5
+ gem "sqlite3", "~> 1.4"
6
+ gem "rails", "~> 7.0"
6
7
 
7
8
  gemspec path: "../"
@@ -5,20 +5,32 @@ require "data_migrate/config"
5
5
 
6
6
  module DataMigrate
7
7
  class DataMigrator < ActiveRecord::Migrator
8
+ def self.migrations_paths
9
+ [DataMigrate.config.data_migrations_path]
10
+ end
11
+
12
+ def self.assure_data_schema_table
13
+ DataMigrate::DataSchemaMigration.create_table
14
+ end
15
+
16
+ def initialize(direction, migrations, target_version = nil)
17
+ @direction = direction
18
+ @target_version = target_version
19
+ @migrated_versions = nil
20
+ @migrations = migrations
21
+
22
+ validate(@migrations)
23
+
24
+ DataMigrate::DataSchemaMigration.create_table
25
+ ActiveRecord::InternalMetadata.create_table
26
+ end
27
+
8
28
  def load_migrated
9
29
  @migrated_versions =
10
- DataMigrate::RailsHelper.data_schema_migration.normalized_versions.map(&:to_i).sort
30
+ DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
11
31
  end
12
32
 
13
33
  class << self
14
- def migrations_paths
15
- [DataMigrate.config.data_migrations_path]
16
- end
17
-
18
- def create_data_schema_table
19
- DataMigrate::RailsHelper.data_schema_migration.create_table
20
- end
21
-
22
34
  def current_version
23
35
  DataMigrate::MigrationContext.new(migrations_paths).current_version
24
36
  end
@@ -54,10 +66,6 @@ module DataMigrate
54
66
 
55
67
  #TODO: this was added to be backward compatible, need to re-evaluate
56
68
  def run(direction, migration_paths, version)
57
- # Ensure all Active Record model cache is reset for each data migration
58
- # As recommended in: https://github.com/rails/rails/blob/da21c2e9812e5eb0698fba4a9aa38632fc004432/activerecord/lib/active_record/migration.rb#L467-L470
59
- ActiveRecord::Base.descendants.each(&:reset_column_information)
60
-
61
69
  DataMigrate::MigrationContext.new(migration_paths).run(direction, version)
62
70
  end
63
71
 
@@ -71,10 +79,10 @@ module DataMigrate
71
79
  def record_version_state_after_migrating(version)
72
80
  if down?
73
81
  migrated.delete(version)
74
- DataMigrate::RailsHelper.data_schema_delete_version(version.to_s)
82
+ DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
75
83
  else
76
84
  migrated << version
77
- DataMigrate::RailsHelper.data_schema_migration.create_version(version.to_s)
85
+ DataMigrate::DataSchemaMigration.create!(version: version.to_s)
78
86
  end
79
87
  end
80
88
  end
@@ -9,7 +9,7 @@ module DataMigrate
9
9
  # ActiveRecord::ConnectionAdapters::SchemaStatements
10
10
  # #assume_migrated_upto_version
11
11
  def define(info)
12
- DataMigrate::DataMigrator.create_data_schema_table
12
+ DataMigrate::DataMigrator.assure_data_schema_table
13
13
 
14
14
  return if info[:version].blank?
15
15
 
@@ -57,7 +57,7 @@ module DataMigrate
57
57
  end
58
58
 
59
59
  def table_name
60
- DataMigrate::RailsHelper.data_schema_migration.table_name
60
+ DataMigrate::DataSchemaMigration.table_name
61
61
  end
62
62
  end
63
63
  end
@@ -1,29 +1,12 @@
1
1
  module DataMigrate
2
- class DataSchemaMigration < ActiveRecord::SchemaMigration
3
- # In Rails 7.1+, ActiveRecord::SchemaMigration methods are instance methods
4
- # So we only load the appropriate methods depending on Rails version.
5
- if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
6
- def table_name
7
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
8
- end
9
-
10
- def primary_key
11
- "version"
12
- end
13
- else
14
- class << self
15
- def table_name
16
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
17
- end
18
-
19
- def primary_key
20
- "version"
21
- end
2
+ class DataSchemaMigration
3
+ class << self
4
+ delegate :table_name, :primary_key, :create_table, :normalized_versions, :create, :create!, :table_exists?, :exists?, :where, to: :instance
22
5
 
23
- def create_version(version)
24
- # Note that SchemaMigration.create_version in Rails 7.1 does not
25
- # raise an error if validations fail but we retain this behaviour for now.
26
- create!(version: version)
6
+ def instance
7
+ @instance ||= Class.new(::ActiveRecord::SchemaMigration) do
8
+ define_singleton_method(:table_name) { ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix }
9
+ define_singleton_method(:primary_key) { "version" }
27
10
  end
28
11
  end
29
12
  end