data_migrate 9.1.1 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +1 -1
  3. data/.gitignore +0 -1
  4. data/Appraisals +5 -5
  5. data/Changelog.md +4 -0
  6. data/Gemfile.lock +148 -0
  7. data/README.md +3 -3
  8. data/data_migrate.gemspec +1 -1
  9. data/gemfiles/rails_6.1.gemfile +1 -1
  10. data/gemfiles/rails_6.1.gemfile.lock +227 -0
  11. data/gemfiles/rails_7.0.gemfile.lock +229 -0
  12. data/gemfiles/{rails_6.0.gemfile → rails_7.1.gemfile} +1 -1
  13. data/gemfiles/rails_7.1.gemfile.lock +262 -0
  14. data/lib/data_migrate/data_migrator.rb +11 -23
  15. data/lib/data_migrate/data_schema.rb +1 -1
  16. data/lib/data_migrate/data_schema_migration.rb +24 -7
  17. data/lib/data_migrate/database_tasks.rb +6 -4
  18. data/lib/data_migrate/migration_context.rb +11 -8
  19. data/lib/data_migrate/rails_helper.rb +79 -0
  20. data/lib/data_migrate/schema_dumper.rb +1 -1
  21. data/lib/data_migrate/schema_migration.rb +5 -4
  22. data/lib/data_migrate/status_service.rb +3 -3
  23. data/lib/data_migrate/tasks/data_migrate_tasks.rb +3 -3
  24. data/lib/data_migrate/version.rb +1 -1
  25. data/lib/data_migrate.rb +1 -1
  26. data/spec/data_migrate/data_migrator_spec.rb +16 -13
  27. data/spec/data_migrate/data_schema_migration_spec.rb +25 -8
  28. data/spec/data_migrate/data_spec.rb +1 -1
  29. data/spec/data_migrate/database_tasks_spec.rb +34 -18
  30. data/spec/data_migrate/migration_context_spec.rb +15 -8
  31. data/spec/data_migrate/schema_dumper_spec.rb +6 -3
  32. data/spec/data_migrate/schema_migration_spec.rb +13 -6
  33. data/spec/data_migrate/status_service_spec.rb +6 -3
  34. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +8 -8
  35. data/spec/db/data/20091231235959_some_name.rb +1 -1
  36. data/spec/db/data/20171231235959_super_update.rb +1 -1
  37. data/spec/db/migrate/20131111111111_late_migration.rb +1 -1
  38. data/spec/db/migrate/20202020202011_db_migration.rb +1 -1
  39. metadata +12 -9
  40. data/lib/data_migrate/legacy_migrator.rb +0 -22
  41. data/spec/data_migrate/legacy_migrator_spec.rb +0 -38
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0"
6
5
  gem "sqlite3", "~> 1.4"
6
+ gem "rails", "7.1.0"
7
7
 
8
8
  gemspec path: "../"
@@ -0,0 +1,262 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ data_migrate (9.2.0)
5
+ activerecord (>= 6.1)
6
+ railties (>= 6.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actioncable (7.1.0)
12
+ actionpack (= 7.1.0)
13
+ activesupport (= 7.1.0)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (7.1.0)
18
+ actionpack (= 7.1.0)
19
+ activejob (= 7.1.0)
20
+ activerecord (= 7.1.0)
21
+ activestorage (= 7.1.0)
22
+ activesupport (= 7.1.0)
23
+ mail (>= 2.7.1)
24
+ net-imap
25
+ net-pop
26
+ net-smtp
27
+ actionmailer (7.1.0)
28
+ actionpack (= 7.1.0)
29
+ actionview (= 7.1.0)
30
+ activejob (= 7.1.0)
31
+ activesupport (= 7.1.0)
32
+ mail (~> 2.5, >= 2.5.4)
33
+ net-imap
34
+ net-pop
35
+ net-smtp
36
+ rails-dom-testing (~> 2.2)
37
+ actionpack (7.1.0)
38
+ actionview (= 7.1.0)
39
+ activesupport (= 7.1.0)
40
+ nokogiri (>= 1.8.5)
41
+ rack (>= 2.2.4)
42
+ rack-session (>= 1.0.1)
43
+ rack-test (>= 0.6.3)
44
+ rails-dom-testing (~> 2.2)
45
+ rails-html-sanitizer (~> 1.6)
46
+ actiontext (7.1.0)
47
+ actionpack (= 7.1.0)
48
+ activerecord (= 7.1.0)
49
+ activestorage (= 7.1.0)
50
+ activesupport (= 7.1.0)
51
+ globalid (>= 0.6.0)
52
+ nokogiri (>= 1.8.5)
53
+ actionview (7.1.0)
54
+ activesupport (= 7.1.0)
55
+ builder (~> 3.1)
56
+ erubi (~> 1.11)
57
+ rails-dom-testing (~> 2.2)
58
+ rails-html-sanitizer (~> 1.6)
59
+ activejob (7.1.0)
60
+ activesupport (= 7.1.0)
61
+ globalid (>= 0.3.6)
62
+ activemodel (7.1.0)
63
+ activesupport (= 7.1.0)
64
+ activerecord (7.1.0)
65
+ activemodel (= 7.1.0)
66
+ activesupport (= 7.1.0)
67
+ timeout (>= 0.4.0)
68
+ activestorage (7.1.0)
69
+ actionpack (= 7.1.0)
70
+ activejob (= 7.1.0)
71
+ activerecord (= 7.1.0)
72
+ activesupport (= 7.1.0)
73
+ marcel (~> 1.0)
74
+ activesupport (7.1.0)
75
+ base64
76
+ bigdecimal
77
+ concurrent-ruby (~> 1.0, >= 1.0.2)
78
+ connection_pool (>= 2.2.5)
79
+ drb
80
+ i18n (>= 1.6, < 2)
81
+ minitest (>= 5.1)
82
+ mutex_m
83
+ tzinfo (~> 2.0)
84
+ appraisal (2.5.0)
85
+ bundler
86
+ rake
87
+ thor (>= 0.14.0)
88
+ ast (2.4.2)
89
+ base64 (0.1.1)
90
+ bigdecimal (3.1.4)
91
+ builder (3.2.4)
92
+ childprocess (4.1.0)
93
+ coderay (1.1.3)
94
+ concurrent-ruby (1.2.2)
95
+ connection_pool (2.4.1)
96
+ crass (1.0.6)
97
+ date (3.3.3)
98
+ diff-lcs (1.5.0)
99
+ drb (2.1.1)
100
+ ruby2_keywords
101
+ erubi (1.12.0)
102
+ globalid (1.2.1)
103
+ activesupport (>= 6.1)
104
+ i18n (1.14.1)
105
+ concurrent-ruby (~> 1.0)
106
+ iniparse (1.5.0)
107
+ io-console (0.6.0)
108
+ irb (1.8.1)
109
+ rdoc
110
+ reline (>= 0.3.8)
111
+ json (2.6.3)
112
+ language_server-protocol (3.17.0.3)
113
+ loofah (2.21.3)
114
+ crass (~> 1.0.2)
115
+ nokogiri (>= 1.12.0)
116
+ mail (2.8.1)
117
+ mini_mime (>= 0.1.1)
118
+ net-imap
119
+ net-pop
120
+ net-smtp
121
+ marcel (1.0.2)
122
+ method_source (1.0.0)
123
+ mini_mime (1.1.5)
124
+ minitest (5.20.0)
125
+ mutex_m (0.1.2)
126
+ net-imap (0.4.0)
127
+ date
128
+ net-protocol
129
+ net-pop (0.1.2)
130
+ net-protocol
131
+ net-protocol (0.2.1)
132
+ timeout
133
+ net-smtp (0.4.0)
134
+ net-protocol
135
+ nio4r (2.5.9)
136
+ nokogiri (1.15.4-arm64-darwin)
137
+ racc (~> 1.4)
138
+ nokogiri (1.15.4-x86_64-linux)
139
+ racc (~> 1.4)
140
+ overcommit (0.60.0)
141
+ childprocess (>= 0.6.3, < 5)
142
+ iniparse (~> 1.4)
143
+ rexml (~> 3.2)
144
+ parallel (1.23.0)
145
+ parser (3.2.2.3)
146
+ ast (~> 2.4.1)
147
+ racc
148
+ pry (0.14.2)
149
+ coderay (~> 1.1)
150
+ method_source (~> 1.0)
151
+ psych (5.1.0)
152
+ stringio
153
+ racc (1.7.1)
154
+ rack (3.0.8)
155
+ rack-session (2.0.0)
156
+ rack (>= 3.0.0)
157
+ rack-test (2.1.0)
158
+ rack (>= 1.3)
159
+ rackup (2.1.0)
160
+ rack (>= 3)
161
+ webrick (~> 1.8)
162
+ rails (7.1.0)
163
+ actioncable (= 7.1.0)
164
+ actionmailbox (= 7.1.0)
165
+ actionmailer (= 7.1.0)
166
+ actionpack (= 7.1.0)
167
+ actiontext (= 7.1.0)
168
+ actionview (= 7.1.0)
169
+ activejob (= 7.1.0)
170
+ activemodel (= 7.1.0)
171
+ activerecord (= 7.1.0)
172
+ activestorage (= 7.1.0)
173
+ activesupport (= 7.1.0)
174
+ bundler (>= 1.15.0)
175
+ railties (= 7.1.0)
176
+ rails-dom-testing (2.2.0)
177
+ activesupport (>= 5.0.0)
178
+ minitest
179
+ nokogiri (>= 1.6)
180
+ rails-html-sanitizer (1.6.0)
181
+ loofah (~> 2.21)
182
+ nokogiri (~> 1.14)
183
+ railties (7.1.0)
184
+ actionpack (= 7.1.0)
185
+ activesupport (= 7.1.0)
186
+ irb
187
+ rackup (>= 1.0.0)
188
+ rake (>= 12.2)
189
+ thor (~> 1.0, >= 1.2.2)
190
+ zeitwerk (~> 2.6)
191
+ rainbow (3.1.1)
192
+ rake (13.0.6)
193
+ rb-readline (0.5.5)
194
+ rdoc (6.5.0)
195
+ psych (>= 4.0.0)
196
+ regexp_parser (2.8.1)
197
+ reline (0.3.9)
198
+ io-console (~> 0.5)
199
+ rexml (3.2.5)
200
+ rspec (3.12.0)
201
+ rspec-core (~> 3.12.0)
202
+ rspec-expectations (~> 3.12.0)
203
+ rspec-mocks (~> 3.12.0)
204
+ rspec-core (3.12.2)
205
+ rspec-support (~> 3.12.0)
206
+ rspec-expectations (3.12.3)
207
+ diff-lcs (>= 1.2.0, < 2.0)
208
+ rspec-support (~> 3.12.0)
209
+ rspec-mocks (3.12.6)
210
+ diff-lcs (>= 1.2.0, < 2.0)
211
+ rspec-support (~> 3.12.0)
212
+ rspec-support (3.12.1)
213
+ rubocop (1.54.2)
214
+ json (~> 2.3)
215
+ language_server-protocol (>= 3.17.0)
216
+ parallel (~> 1.10)
217
+ parser (>= 3.2.2.3)
218
+ rainbow (>= 2.2.2, < 4.0)
219
+ regexp_parser (>= 1.8, < 3.0)
220
+ rexml (>= 3.2.5, < 4.0)
221
+ rubocop-ast (>= 1.28.0, < 2.0)
222
+ ruby-progressbar (~> 1.7)
223
+ unicode-display_width (>= 2.4.0, < 3.0)
224
+ rubocop-ast (1.29.0)
225
+ parser (>= 3.2.1.0)
226
+ ruby-progressbar (1.13.0)
227
+ ruby2_keywords (0.0.5)
228
+ sqlite3 (1.6.3-arm64-darwin)
229
+ sqlite3 (1.6.3-x86_64-linux)
230
+ stringio (3.0.8)
231
+ thor (1.2.2)
232
+ timecop (0.9.6)
233
+ timeout (0.4.0)
234
+ tzinfo (2.0.6)
235
+ concurrent-ruby (~> 1.0)
236
+ unicode-display_width (2.4.2)
237
+ webrick (1.8.1)
238
+ websocket-driver (0.7.6)
239
+ websocket-extensions (>= 0.1.0)
240
+ websocket-extensions (0.1.5)
241
+ zeitwerk (2.6.12)
242
+
243
+ PLATFORMS
244
+ arm64-darwin-22
245
+ x86_64-linux
246
+
247
+ DEPENDENCIES
248
+ appraisal
249
+ data_migrate!
250
+ overcommit
251
+ pry
252
+ rails (= 7.1.0)
253
+ rake
254
+ rb-readline
255
+ rspec
256
+ rspec-core
257
+ rubocop
258
+ sqlite3 (~> 1.4)
259
+ timecop
260
+
261
+ BUNDLED WITH
262
+ 2.4.17
@@ -5,32 +5,20 @@ 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.create_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
-
28
8
  def load_migrated
29
9
  @migrated_versions =
30
- DataMigrate::DataSchemaMigration.normalized_versions.map(&:to_i).sort
10
+ DataMigrate::RailsHelper.data_schema_migration.normalized_versions.map(&:to_i).sort
31
11
  end
32
12
 
33
13
  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
+
34
22
  def current_version
35
23
  DataMigrate::MigrationContext.new(migrations_paths).current_version
36
24
  end
@@ -79,10 +67,10 @@ module DataMigrate
79
67
  def record_version_state_after_migrating(version)
80
68
  if down?
81
69
  migrated.delete(version)
82
- DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all
70
+ DataMigrate::RailsHelper.data_schema_delete_version(version.to_s)
83
71
  else
84
72
  migrated << version
85
- DataMigrate::DataSchemaMigration.create!(version: version.to_s)
73
+ DataMigrate::RailsHelper.data_schema_migration.create_version(version.to_s)
86
74
  end
87
75
  end
88
76
  end
@@ -57,7 +57,7 @@ module DataMigrate
57
57
  end
58
58
 
59
59
  def table_name
60
- DataMigrate::DataSchemaMigration.table_name
60
+ DataMigrate::RailsHelper.data_schema_migration.table_name
61
61
  end
62
62
  end
63
63
  end
@@ -1,12 +1,29 @@
1
1
  module DataMigrate
2
- class DataSchemaMigration
3
- class << self
4
- delegate :table_name, :primary_key, :create_table, :normalized_versions, :create, :create!, :table_exists?, :exists?, :where, to: :instance
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
5
22
 
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" }
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)
10
27
  end
11
28
  end
12
29
  end
@@ -101,8 +101,10 @@ module DataMigrate
101
101
 
102
102
  def self.pending_data_migrations
103
103
  data_migrations = DataMigrate::DataMigrator.migrations(data_migrations_path)
104
- sort_migrations(DataMigrate::DataMigrator.new(:up, data_migrations ).
105
- pending_migrations.map {|m| { version: m.version, name: m.name, kind: :data }})
104
+ data_migrator = DataMigrate::RailsHelper.data_migrator(:up, data_migrations)
105
+ sort_migrations(
106
+ data_migrator.pending_migrations.map { |m| { version: m.version, name: m.name, kind: :data } }
107
+ )
106
108
  end
107
109
 
108
110
  def self.pending_schema_migrations
@@ -110,8 +112,8 @@ module DataMigrate
110
112
  end
111
113
 
112
114
  def self.past_migrations(sort = nil)
113
- data_versions = DataMigrate::DataSchemaMigration.table_exists? ? DataMigrate::DataSchemaMigration.normalized_versions : []
114
- schema_versions = ActiveRecord::SchemaMigration.normalized_versions
115
+ data_versions = DataMigrate::RailsHelper.data_schema_migration.table_exists? ? DataMigrate::RailsHelper.data_schema_migration.normalized_versions : []
116
+ schema_versions = DataMigrate::RailsHelper.schema_migration.normalized_versions
115
117
  migrations = data_versions.map { |v| { version: v.to_i, kind: :data } } + schema_versions.map { |v| { version: v.to_i, kind: :schema } }
116
118
 
117
119
  sort&.downcase == "asc" ? sort_migrations(migrations) : sort_migrations(migrations).reverse
@@ -11,7 +11,8 @@ module DataMigrate
11
11
  migrations
12
12
  end
13
13
 
14
- DataMigrator.new(:up, selected_migrations, target_version).migrate
14
+ data_migrator = DataMigrate::RailsHelper.data_migrator(:up, selected_migrations, DataMigrate::RailsHelper.schema_migration, DataMigrate::RailsHelper.internal_metadata, target_version)
15
+ data_migrator.migrate
15
16
  end
16
17
 
17
18
  def down(target_version = nil)
@@ -22,11 +23,13 @@ module DataMigrate
22
23
  migrations
23
24
  end
24
25
 
25
- DataMigrator.new(:down, selected_migrations, target_version).migrate
26
+ data_migrator = DataMigrate::RailsHelper.data_migrator(:down, selected_migrations, DataMigrate::RailsHelper.schema_migration, DataMigrate::RailsHelper.internal_metadata, target_version)
27
+ data_migrator.migrate
26
28
  end
27
29
 
28
30
  def run(direction, target_version)
29
- DataMigrator.new(direction, migrations, target_version).run
31
+ data_migrator = DataMigrate::RailsHelper.data_migrator(direction, migrations, DataMigrate::RailsHelper.schema_migration, DataMigrate::RailsHelper.internal_metadata, target_version)
32
+ data_migrator.run
30
33
  end
31
34
 
32
35
  def current_version
@@ -40,12 +43,12 @@ module DataMigrate
40
43
  end
41
44
 
42
45
  def migrations_status
43
- db_list = DataSchemaMigration.normalized_versions
46
+ db_list = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
44
47
 
45
48
  file_list = migration_files.map do |file|
46
49
  version, name, scope = parse_migration_filename(file)
47
50
  raise ActiveRecord::IllegalMigrationNameError.new(file) unless version
48
- version = ActiveRecord::SchemaMigration.normalize_migration_number(version)
51
+ version = DataMigrate::RailsHelper.schema_migration.normalize_migration_number(version)
49
52
  status = db_list.delete(version) ? "up" : "down"
50
53
  [status, version, (name + scope).humanize]
51
54
  end.compact
@@ -60,15 +63,15 @@ module DataMigrate
60
63
  private
61
64
 
62
65
  def get_all_versions
63
- if DataMigrate::DataSchemaMigration.table_exists?
64
- DataSchemaMigration.normalized_versions.map(&:to_i)
66
+ if DataMigrate::RailsHelper.data_schema_migration.table_exists?
67
+ DataMigrate::RailsHelper.data_schema_migration.normalized_versions.map(&:to_i)
65
68
  else
66
69
  []
67
70
  end
68
71
  end
69
72
 
70
73
  def move(direction, steps)
71
- migrator = DataMigrator.new(direction, migrations)
74
+ migrator = DataMigrate::RailsHelper.data_migrator(direction, migrations)
72
75
 
73
76
  if current_version != 0 && !migrator.current_migration
74
77
  raise ActiveRecord::UnknownMigrationVersionError.new(current_version)
@@ -0,0 +1,79 @@
1
+ module DataMigrate
2
+ class RailsHelper
3
+ class << self
4
+ def rails_version_equal_to_or_higher_than_7_1
5
+ return @equal_to_or_higher_than_7_1 if defined?(@equal_to_or_higher_than_7_1)
6
+
7
+ @equal_to_or_higher_than_7_1 = Gem::Dependency.new("railties", ">= 7.1.0.alpha").match?("railties", Gem.loaded_specs["railties"].version, true)
8
+ end
9
+
10
+ def rails_version_equal_to_or_higher_than_7_0
11
+ return @rails_version_equal_to_or_higher_than_7_0 if defined?(@rails_version_equal_to_or_higher_than_7_0)
12
+
13
+ @rails_version_equal_to_or_higher_than_7_0 = Gem::Dependency.new("railties", ">= 7.0").match?("railties", Gem.loaded_specs["railties"].version, true)
14
+ end
15
+
16
+ def internal_metadata
17
+ if rails_version_equal_to_or_higher_than_7_1
18
+ ActiveRecord::Base.connection.internal_metadata
19
+ else
20
+ ActiveRecord::InternalMetadata
21
+ end
22
+ end
23
+
24
+ def schema_migration
25
+ if rails_version_equal_to_or_higher_than_7_1
26
+ ActiveRecord::Base.connection.schema_migration
27
+ else
28
+ ActiveRecord::SchemaMigration
29
+ end
30
+ end
31
+
32
+ def schema_migration_versions
33
+ if rails_version_equal_to_or_higher_than_7_1
34
+ schema_migration.versions
35
+ else
36
+ schema_migration.all.pluck(:version)
37
+ end
38
+ end
39
+
40
+ def schema_create_version(version)
41
+ if rails_version_equal_to_or_higher_than_7_1
42
+ schema_migration.create_version(version)
43
+ else
44
+ schema_migration.create(version: version)
45
+ end
46
+ end
47
+
48
+ def data_schema_delete_version(version)
49
+ if rails_version_equal_to_or_higher_than_7_1
50
+ data_schema_migration.delete_version(version)
51
+ else
52
+ data_schema_migration.where(version: version.to_s).delete_all
53
+ end
54
+ end
55
+
56
+ def data_schema_migration
57
+ if rails_version_equal_to_or_higher_than_7_1
58
+ DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection)
59
+ else
60
+ DataMigrate::DataSchemaMigration
61
+ end
62
+ end
63
+
64
+ def data_migrator(
65
+ direction,
66
+ migrations,
67
+ schema_migration = DataMigrate::RailsHelper.schema_migration,
68
+ internal_metadata = DataMigrate::RailsHelper.internal_metadata,
69
+ target_version = nil
70
+ )
71
+ if rails_version_equal_to_or_higher_than_7_1
72
+ DataMigrate::DataMigrator.new(direction, migrations, schema_migration, internal_metadata, target_version)
73
+ else
74
+ DataMigrate::DataMigrator.new(direction, migrations, schema_migration, target_version)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -26,7 +26,7 @@ module DataMigrate
26
26
 
27
27
  def initialize(connection)
28
28
  @connection = connection
29
- all_versions = DataSchemaMigration.normalized_versions
29
+ all_versions = DataMigrate::RailsHelper.data_schema_migration.normalized_versions
30
30
 
31
31
  @version = begin
32
32
  all_versions.max
@@ -7,14 +7,14 @@ module DataMigrate
7
7
  def self.pending_schema_migrations
8
8
  all_migrations = DataMigrate::MigrationContext.new(migrations_paths).migrations
9
9
  sort_migrations(
10
- ActiveRecord::Migrator.new(:up, all_migrations, ActiveRecord::Base.connection.schema_migration).
10
+ ActiveRecord::Migrator.new(:up, all_migrations, DataMigrate::RailsHelper.schema_migration, DataMigrate::RailsHelper.internal_metadata).
11
11
  pending_migrations.
12
12
  map {|m| { version: m.version, kind: :schema }}
13
13
  )
14
14
  end
15
15
 
16
16
  def self.run(direction, migration_paths, version)
17
- ActiveRecord::MigrationContext.new(migration_paths, ActiveRecord::Base.connection.schema_migration).run(direction, version)
17
+ ActiveRecord::MigrationContext.new(migration_paths, DataMigrate::RailsHelper.schema_migration).run(direction, version)
18
18
  end
19
19
 
20
20
  def self.sort_migrations(set1, set2 = nil)
@@ -24,9 +24,10 @@ module DataMigrate
24
24
 
25
25
  def self.migrations_paths
26
26
  spec_name = DataMigrate.config.spec_name
27
- if spec_name && Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
27
+ # The positional argument true is to include pre-release versions, such as 7.1.0.alpha
28
+ if spec_name && Gem::Dependency.new("railties", ">= 7.0").match?("railties", Gem.loaded_specs["railties"].version, true)
28
29
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
29
- elsif spec_name && Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
30
+ elsif spec_name && Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
30
31
  ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
31
32
  else
32
33
  Rails.application.config.paths["db/migrate"].to_a
@@ -24,11 +24,11 @@ module DataMigrate
24
24
  private
25
25
 
26
26
  def table_name
27
- DataMigrate::DataSchemaMigration.table_name
27
+ DataMigrate::RailsHelper.data_schema_migration.table_name
28
28
  end
29
29
 
30
30
  def output(stream)
31
- unless DataMigrate::DataSchemaMigration.table_exists?
31
+ unless DataMigrate::RailsHelper.data_schema_migration.table_exists?
32
32
  stream.puts "Data migrations table does not exist yet."
33
33
  return
34
34
  end
@@ -46,7 +46,7 @@ module DataMigrate
46
46
  def database_name
47
47
  if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
48
48
  ActiveRecord::Base.connection_db_config.configuration_hash[:database]
49
- elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
49
+ elsif Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
50
50
  ActiveRecord::Base.connection_config[:database]
51
51
  end
52
52
  end
@@ -50,9 +50,9 @@ module DataMigrate
50
50
 
51
51
  def status_with_schema
52
52
  db_list_data = ActiveRecord::Base.connection.select_values(
53
- "SELECT version FROM #{DataMigrate::DataSchemaMigration.table_name}"
53
+ "SELECT version FROM #{DataMigrate::RailsHelper.data_schema_migration.table_name}"
54
54
  )
55
- db_list_schema = ActiveRecord::SchemaMigration.all.pluck(:version)
55
+ db_list_schema = DataMigrate::RailsHelper.schema_migration_versions
56
56
  file_list = []
57
57
 
58
58
  Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
@@ -96,7 +96,7 @@ module DataMigrate
96
96
  def database_name
97
97
  if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
98
98
  ActiveRecord::Base.connection_db_config.database
99
- elsif Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
99
+ elsif Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
100
100
  ActiveRecord::Base.connection_config[:database]
101
101
  end
102
102
  end
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "9.1.1".freeze
2
+ VERSION = "9.2.0".freeze
3
3
  end
data/lib/data_migrate.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require File.join(File.dirname(__FILE__), "data_migrate", "rails_helper")
3
4
  require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator")
4
5
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema_migration")
5
6
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema")
@@ -9,7 +10,6 @@ require File.join(File.dirname(__FILE__), "data_migrate", "status_service")
9
10
  require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
10
11
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
11
12
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
12
- require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
13
13
  require File.join(File.dirname(__FILE__), "data_migrate", "config")
14
14
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration")
15
15