data_migrate 9.4.2 → 11.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +34 -2
  3. data/README.md +23 -13
  4. data/lib/data_migrate/config.rb +2 -2
  5. data/lib/data_migrate/data_migrator.rb +1 -2
  6. data/lib/data_migrate/data_schema.rb +6 -6
  7. data/lib/data_migrate/data_schema_migration.rb +2 -2
  8. data/lib/data_migrate/database_tasks.rb +68 -23
  9. data/lib/data_migrate/rails_helper.rb +15 -3
  10. data/lib/data_migrate/schema_dumper.rb +8 -1
  11. data/lib/data_migrate/tasks/data_migrate_tasks.rb +8 -6
  12. data/lib/data_migrate/version.rb +1 -1
  13. data/lib/generators/data_migration/data_migration_generator.rb +2 -1
  14. metadata +5 -50
  15. data/.github/workflows/build.yml +0 -35
  16. data/.github/workflows/gempush.yml +0 -28
  17. data/.gitignore +0 -12
  18. data/.hound.yml +0 -4
  19. data/.overcommit.yml +0 -21
  20. data/.rbenv-gemsets +0 -2
  21. data/.rspec +0 -3
  22. data/.rubocop.yml +0 -2
  23. data/.ruby-style.yml +0 -1061
  24. data/Appraisals +0 -11
  25. data/Gemfile +0 -3
  26. data/Gemfile.lock +0 -184
  27. data/Rakefile +0 -2
  28. data/data_migrate.gemspec +0 -41
  29. data/gemfiles/rails_6.1.gemfile +0 -7
  30. data/gemfiles/rails_6.1.gemfile.lock +0 -229
  31. data/gemfiles/rails_7.0.gemfile +0 -7
  32. data/gemfiles/rails_7.0.gemfile.lock +0 -230
  33. data/gemfiles/rails_7.1.gemfile +0 -7
  34. data/gemfiles/rails_7.1.gemfile.lock +0 -263
  35. data/lib/data_migrate/test.rb +0 -14
  36. data/screenshot.png +0 -0
  37. data/spec/data_migrate/config_spec.rb +0 -69
  38. data/spec/data_migrate/data_migrator_spec.rb +0 -83
  39. data/spec/data_migrate/data_schema_migration_spec.rb +0 -33
  40. data/spec/data_migrate/data_spec.rb +0 -74
  41. data/spec/data_migrate/database_tasks_spec.rb +0 -105
  42. data/spec/data_migrate/migration.rb +0 -17
  43. data/spec/data_migrate/migration_context_spec.rb +0 -108
  44. data/spec/data_migrate/schema_dumper_spec.rb +0 -36
  45. data/spec/data_migrate/schema_migration_spec.rb +0 -104
  46. data/spec/data_migrate/status_service_spec.rb +0 -76
  47. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +0 -129
  48. data/spec/db/data/20091231235959_some_name.rb +0 -9
  49. data/spec/db/data/20171231235959_super_update.rb +0 -9
  50. data/spec/db/data/20181128000207_excluded_file.rb.other_ext +0 -1
  51. data/spec/db/data/partial_schema/data_schema.rb +0 -1
  52. data/spec/db/data/partial_schema/test_data_schema.rb +0 -1
  53. data/spec/db/data/schema/data_schema.rb +0 -1
  54. data/spec/db/data/schema/test_data_schema.rb +0 -1
  55. data/spec/db/migrate/20131111111111_late_migration.rb +0 -9
  56. data/spec/db/migrate/20202020202011_db_migration.rb +0 -9
  57. data/spec/generators/data_migration/data_migration_generator_spec.rb +0 -101
  58. data/spec/spec_helper.rb +0 -28
  59. data/tasks/.gitkeep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b061a1b90d162a48df5225719ec96da94aaa77d0580d952a1ff0f4cb895e452e
4
- data.tar.gz: bc78e03d816377c6a784b8102ce9f6c9504ee4650839436a92b1a949bce6a45d
3
+ metadata.gz: 7bef47d5608c410a0158dfd4847c065895db273e0809f8467f3cae2e4d428604
4
+ data.tar.gz: 5f1221a6c8fa70c5d095790892877e1aee369c3a06f2e145ec87534e06993065
5
5
  SHA512:
6
- metadata.gz: 5c612eefd1985b3935c79c87039f1f67db81088a1984fb4e90d15c361d9c0fd90b9acefaeb131ec4b77f22a56f6524a99444e663b5e2e2a820115864b09471ed
7
- data.tar.gz: b2ce56c6fd8510adb0eb465fc765df93fdce42f6d7f81e809276bbaf29f7e1891dd7638191e395af0afb774f1ced8fc33387a9619b09edf24cde824b03aa00a6
6
+ metadata.gz: 3df1a19a487efc065928f135dc8e372e282d300956b2172d654247d9f6bbc3edbfff279e309b1d557093e7ef44ba49217de9dbfd7d58f75c96d6e91be83fd3ec
7
+ data.tar.gz: 524ed4970e8f98a761d6b845b7d1d9be23015599be203e4aed2fb7fda68fe16b84a9dbcb29e68746de6d73559a2de584bad35307a1d60d134c8411b9f07fd75c
data/Changelog.md CHANGED
@@ -1,10 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ # 11.3.1
4
+ - Schema version -- do formatted version like activerecord https://github.com/ilyakatz/data-migrate/pull/363
5
+ - Resolve ActiveSupport::Configurable deprecation in Rails 8.2 https://github.com/ilyakatz/data-migrate/pull/365
6
+ - Add support for Rails 8.1 in Appraisal https://github.com/ilyakatz/data-migrate/pull/366
7
+
8
+ # 11.3.0
9
+ - Make table_name configurable https://github.com/ilyakatz/data-migrate/pull/361
10
+ - Use lease_connection over deprecated connection for rails 8 https://github.com/ilyakatz/data-migrate/pull/353
11
+ - Add Ruby 3.4 to CI matrix
12
+
13
+ # 11.2.0
14
+ - Remove committed Gemfile.lock, reduce bundled file list when running `gem install` https://github.com/ilyakatz/data-migrate/pull/351
15
+ - [Bump actionpack from 7.1.3.4 to 7.1.4.1](https://github.com/ilyakatz/data-migrate/pull/348)
16
+ - [Bump rexml from 3.3.6 to 3.3.9](https://github.com/ilyakatz/data-migrate/pull/349)
17
+ - Fix db_config_with_versions arity change and backport https://github.com/ilyakatz/data-migrate/pull/337
18
+
19
+ # 11.1.0
20
+ - Allow multiple data migration paths https://github.com/ilyakatz/data-migrate/pull/331
21
+ - Fix db:prepare:with_data task on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/339)
22
+ - Fix ConnectionPool deprecation warnings on [Rails 7.2](https://github.com/ilyakatz/data-migrate/pull/341)
23
+ - Add Rails 8.0 to testing grounds https://github.com/ilyakatz/data-migrate/pull/341
24
+ - [Bump webrick from 1.8.1 to 1.8.2](https://github.com/ilyakatz/data-migrate/pull/345)
25
+
26
+ # 11.0.0
27
+ - [Update rexml to 3.3.6](https://github.com/ilyakatz/data-migrate/pull/329)
28
+ - Fixes a bug which ignored migrations on [Rails 7.1 and higher](https://github.com/ilyakatz/data-migrate/pull/326)
29
+
30
+ # 11.0.0rc
31
+ - Remove Ruby 3.0 from build matrix
32
+ - Support Rails 7.2.0 https://github.com/ilyakatz/data-migrate/pull/312
33
+ - Update gemfile.lock builds
34
+
3
35
  ## 9.4.2
4
- - Fix db:prepare:with_data task
36
+ - Fix db:prepare:with_data task
5
37
 
6
38
  ## 9.4.1
7
- - Add db:prepare task
39
+ - Add db:prepare task
8
40
 
9
41
  ## 9.4.0
10
42
  - Reset model schema cache before each data migration https://github.com/ilyakatz/data-migrate/pull/307
data/README.md CHANGED
@@ -36,8 +36,13 @@ 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.1 through 8.0
40
40
 
41
+ For **Rails 6.0** support, please use gem version `9.1.x`:
42
+
43
+ ```ruby
44
+ gem 'data_migrate', '~> 9.1.0'
45
+ ```
41
46
 
42
47
  #### v1
43
48
 
@@ -86,6 +91,7 @@ You can generate a data migration as you would a schema migration:
86
91
  rake db:migrate:status:with_data # Display status of data and schema migrations
87
92
  rake db:migrate:up:with_data # Runs the "up" for a given migration VERSION
88
93
  rake db:migrate:with_data # Migrate the database data and schema (options: VERSION=x, VERBOSE=false)
94
+ rake db:prepare:with_data # Runs setup if database does not exist, or runs data and schema migrations if it does
89
95
  rake db:rollback:with_data # Rolls the schema back to the previous version (specify steps w/ STEP=n)
90
96
  rake db:schema:load:with_data # Load both schema.rb and data_schema.rb file into the database
91
97
  rake db:structure:load:with_data # Load both structure.sql and data_schema.rb file into the database
@@ -109,6 +115,7 @@ You can override this setting in `config/initializers/data_migrate.rb`
109
115
 
110
116
  ```ruby
111
117
  DataMigrate.configure do |config|
118
+ config.data_migrations_table_name = 'my_migrations_database_name'
112
119
  config.data_migrations_path = 'db/awesomepath/'
113
120
  config.data_template_path = Rails.root.join("lib", "awesomepath", "custom_data_migration.rb")
114
121
  config.db_configuration = {
@@ -138,19 +145,12 @@ From now on capistrano will run `rake db:migrate:with_data` in every deploy.
138
145
  ## Rails Engines support
139
146
 
140
147
  This gem also has a initial support for adding data migrations inside Rails engines.
141
- Inside the Engine's class initializer (the one that inherits from `Rails::Engine`, usually inside `engines/ENGINE_NAME/lib/engine.rb`) you need to add something like this:
142
-
148
+ Just add your engines directory pattern to data_migrations initializer, for example
149
+ in the case your engines are located in `engines` folder you can set it up like this:
143
150
 
144
151
  ```ruby
145
- module EngineName
146
- class Engine < ::Rails::Engine
147
- initializer :engine_name do |app|
148
- ::DataMigrate.configure do |data_migrate|
149
- default_path = ::DataMigrate::Config.new.data_migrations_path
150
- data_migrate.data_migrations_path = [default_path, root.join('db', 'data')]
151
- end
152
- end
153
- end
152
+ DataMigrate.configure do |config|
153
+ config.data_migrations_path = ['db/data'] + Dir['engines/**/db/data']
154
154
  end
155
155
  ```
156
156
 
@@ -163,12 +163,22 @@ Then, in the Engine's `db/data` folder, you can add data migrations and run them
163
163
  Run tests for a specific version of Rails
164
164
 
165
165
  ```
166
- bundle exec appraisal install
167
166
  bundle exec appraisal rails-6.1 rspec
168
167
  bundle exec appraisal rails-7.0 rspec
169
168
  bundle exec appraisal rails-7.1 rspec
169
+ bundle exec appraisal rails-7.2 rspec
170
+ bundle exec appraisal rails-8.0 rspec
170
171
  ```
171
172
 
173
+ ## Releasing new version
174
+
175
+ 1. Update version.rb file, run `bundle exec appraisal` to update the version in corresponding gemfile.lock
176
+ 2. Create a new tag, eg `git tag 9.4.1`
177
+ 3. Go to https://github.com/ilyakatz/data-migrate/tags
178
+ 4. Click "Create release" under 9.4.1
179
+ 5. CLick "Generate release notes"
180
+ 6. Click "Publish release"
181
+
172
182
  ## Thanks
173
183
 
174
184
  [Andrew J Vargo](http://github.com/ajvargo) Andrew was the original creator and maintainer of this project!
@@ -1,5 +1,4 @@
1
1
  module DataMigrate
2
- include ActiveSupport::Configurable
3
2
  class << self
4
3
 
5
4
  def configure
@@ -12,11 +11,12 @@ module DataMigrate
12
11
  end
13
12
 
14
13
  class Config
15
- attr_accessor :data_migrations_path, :data_template_path, :db_configuration, :spec_name
14
+ attr_accessor :data_migrations_table_name, :data_migrations_path, :data_template_path, :db_configuration, :spec_name
16
15
 
17
16
  DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"
18
17
 
19
18
  def initialize
19
+ @data_migrations_table_name = "data_migrations"
20
20
  @data_migrations_path = "db/data/"
21
21
  @data_template_path = DEFAULT_DATA_TEMPLATE_PATH
22
22
  @db_configuration = nil
@@ -12,7 +12,7 @@ module DataMigrate
12
12
 
13
13
  class << self
14
14
  def migrations_paths
15
- [DataMigrate.config.data_migrations_path]
15
+ Array.wrap(DataMigrate.config.data_migrations_path)
16
16
  end
17
17
 
18
18
  def create_data_schema_table
@@ -48,7 +48,6 @@ module DataMigrate
48
48
 
49
49
  # TODO: this was added to be backward compatible, need to re-evaluate
50
50
  def migrations(_migrations_paths)
51
- #DataMigrate::MigrationContext.new(migrations_paths).migrations
52
51
  DataMigrate::MigrationContext.new(_migrations_paths).migrations
53
52
  end
54
53
 
@@ -29,13 +29,13 @@ module DataMigrate
29
29
  end
30
30
 
31
31
  def versions
32
- @versions ||= begin
33
- versions = []
34
- Dir.foreach(DataMigrate::DataMigrator.full_migrations_path) do |file|
35
- match_data = DataMigrate::DataMigrator.match(file)
36
- versions << match_data[1].to_i if match_data
32
+ @versions ||= Set.new.tap do |versions|
33
+ DataMigrate::DataMigrator.migrations_paths.each do |path|
34
+ Dir.foreach(path) do |file|
35
+ match_data = DataMigrate::DataMigrator.match(file)
36
+ versions << match_data[1].to_i if match_data
37
+ end
37
38
  end
38
- versions
39
39
  end
40
40
  end
41
41
 
@@ -4,7 +4,7 @@ module DataMigrate
4
4
  # So we only load the appropriate methods depending on Rails version.
5
5
  if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
6
6
  def table_name
7
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
7
+ ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
8
8
  end
9
9
 
10
10
  def primary_key
@@ -13,7 +13,7 @@ module DataMigrate
13
13
  else
14
14
  class << self
15
15
  def table_name
16
- ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
16
+ ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
17
17
  end
18
18
 
19
19
  def primary_key
@@ -9,22 +9,29 @@ module DataMigrate
9
9
  extend ActiveRecord::Tasks::DatabaseTasks
10
10
  extend self
11
11
 
12
+ if respond_to?(:register_task)
13
+ register_task(/mysql/, "ActiveRecord::Tasks::MySQLDatabaseTasks")
14
+ register_task(/trilogy/, "ActiveRecord::Tasks::MySQLDatabaseTasks")
15
+ register_task(/postgresql/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
16
+ register_task(/sqlite/, "ActiveRecord::Tasks::SQLiteDatabaseTasks")
17
+ end
18
+
12
19
  # These method are only introduced in Rails 7.1
13
- unless respond_to?(:with_temporary_connection_for_each)
14
- def with_temporary_connection_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
20
+ unless respond_to?(:with_temporary_pool_for_each)
21
+ def with_temporary_pool_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
15
22
  if name
16
23
  db_config = ActiveRecord::Base.configurations.configs_for(env_name: env, name: name)
17
- with_temporary_connection(db_config, &block)
24
+ with_temporary_pool(db_config, &block)
18
25
  else
19
26
  ActiveRecord::Base.configurations.configs_for(env_name: env, name: name).each do |db_config|
20
- with_temporary_connection(db_config, &block)
27
+ with_temporary_pool(db_config, &block)
21
28
  end
22
29
  end
23
30
  end
24
31
 
25
- def with_temporary_connection(db_config) # :nodoc:
32
+ def with_temporary_connection(db_config, &block) # :nodoc:
26
33
  with_temporary_pool(db_config) do |pool|
27
- yield pool.connection
34
+ pool.with_connection(&block)
28
35
  end
29
36
  end
30
37
 
@@ -49,8 +56,8 @@ module DataMigrate
49
56
  def db_configs_with_versions
50
57
  db_configs_with_versions = Hash.new { |h, k| h[k] = [] }
51
58
 
52
- with_temporary_connection_for_each do |conn|
53
- db_config = conn.pool.db_config
59
+ with_temporary_pool_for_each do |pool|
60
+ db_config = pool.db_config
54
61
  if db_config.primary?
55
62
  versions_to_run = DataMigrate::DatabaseTasks.pending_data_migrations.map { |m| m[:version] }
56
63
  target_version = ActiveRecord::Tasks::DatabaseTasks.target_version
@@ -99,7 +106,7 @@ module DataMigrate
99
106
  end
100
107
 
101
108
  def sort_migrations(*migrations)
102
- migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
109
+ migrations.flatten.sort { |a, b| sort_string(a) <=> sort_string(b) }
103
110
  end
104
111
 
105
112
  def sort_string migration
@@ -159,7 +166,7 @@ module DataMigrate
159
166
  data_migrator = DataMigrate::RailsHelper.data_migrator(:up, data_migrations)
160
167
  sort_migrations(
161
168
  data_migrator.pending_migrations.map { |m| { version: m.version, name: m.name, kind: :data } }
162
- )
169
+ )
163
170
  end
164
171
 
165
172
  def pending_schema_migrations
@@ -179,9 +186,16 @@ module DataMigrate
179
186
 
180
187
  ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
181
188
 
182
- db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
189
+ # 7.2 removes the param for db_configs_with_versions in https://github.com/rails/rails/commit/9572fcb4a0bd5396436689a6a42613886871cd81
190
+ # 7.1 stable backported the change in https://github.com/rails/rails/commit/c53ec4b60980036b43528829d4b0b7457f759224
191
+ schema_mapped_versions = if Gem::Dependency.new("railties", ">= 7.1.4").match?("railties", Gem.loaded_specs["railties"].version, true)
192
+ ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions
193
+ else
194
+ db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)
195
+
196
+ ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions(db_configs)
197
+ end
183
198
 
184
- schema_mapped_versions = ActiveRecord::Tasks::DatabaseTasks.db_configs_with_versions(db_configs)
185
199
  data_mapped_versions = DataMigrate::DatabaseTasks.db_configs_with_versions
186
200
 
187
201
  mapped_versions = schema_mapped_versions.merge(data_mapped_versions) do |_key, schema_db_configs, data_db_configs|
@@ -209,19 +223,14 @@ module DataMigrate
209
223
  seed = false
210
224
 
211
225
  each_current_configuration(env) do |db_config|
212
- next unless db_config.primary?
226
+ next unless primary?(db_config)
213
227
 
214
- with_temporary_pool(db_config) do
215
- begin
216
- database_initialized = migration_connection.schema_migration.table_exists?
217
- rescue ActiveRecord::NoDatabaseError
228
+ with_temporary_pool(db_config) do |pool|
229
+ connection = pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
230
+ unless database_exists?(connection)
218
231
  create(db_config)
219
- retry
220
- end
221
-
222
- unless database_initialized
223
232
  if File.exist?(schema_dump_path(db_config))
224
- load_schema(db_config, ActiveRecord.schema_format, nil)
233
+ load_schema(db_config, schema_format, nil)
225
234
  load_schema_current(
226
235
  :ruby,
227
236
  ENV["DATA_SCHEMA"]
@@ -232,7 +241,7 @@ module DataMigrate
232
241
  end
233
242
 
234
243
  migrate_with_data
235
- if ActiveRecord.dump_schema_after_migration
244
+ if dump_schema_after_migration?
236
245
  dump_schema(db_config)
237
246
  DataMigrate::Tasks::DataMigrateTasks.dump
238
247
  end
@@ -241,5 +250,41 @@ module DataMigrate
241
250
 
242
251
  load_seed if seed
243
252
  end
253
+
254
+ private
255
+
256
+ def database_exists?(connection)
257
+ if connection.respond_to?(:database_exists?) # Rails 7.1+
258
+ connection.database_exists?
259
+ else
260
+ connection.table_exists?(ActiveRecord::SchemaMigration.table_name)
261
+ end
262
+ rescue ActiveRecord::NoDatabaseError
263
+ false
264
+ end
265
+
266
+ def primary?(db_config)
267
+ if db_config.respond_to?(:primary?) # Rails 7.0+
268
+ db_config.primary?
269
+ else
270
+ db_config.name == "primary"
271
+ end
272
+ end
273
+
274
+ def dump_schema_after_migration?
275
+ if ActiveRecord.respond_to?(:dump_schema_after_migration)
276
+ ActiveRecord.dump_schema_after_migration
277
+ else
278
+ ActiveRecord::Base.dump_schema_after_migration
279
+ end
280
+ end
281
+
282
+ def schema_format
283
+ if ActiveRecord.respond_to?(:schema_format)
284
+ ActiveRecord.schema_format
285
+ else
286
+ ActiveRecord::Base.schema_format
287
+ end
288
+ end
244
289
  end
245
290
  end
@@ -1,6 +1,12 @@
1
1
  module DataMigrate
2
2
  class RailsHelper
3
3
  class << self
4
+ def rails_version_equal_to_or_higher_than_7_2
5
+ return @equal_to_or_higher_than_7_2 if defined?(@equal_to_or_higher_than_7_2)
6
+
7
+ @equal_to_or_higher_than_7_2 = Gem::Dependency.new("railties", ">= 7.2.0.alpha").match?("railties", Gem.loaded_specs["railties"].version, true)
8
+ end
9
+
4
10
  def rails_version_equal_to_or_higher_than_7_1
5
11
  return @equal_to_or_higher_than_7_1 if defined?(@equal_to_or_higher_than_7_1)
6
12
 
@@ -14,7 +20,9 @@ module DataMigrate
14
20
  end
15
21
 
16
22
  def internal_metadata
17
- if rails_version_equal_to_or_higher_than_7_1
23
+ if rails_version_equal_to_or_higher_than_7_2
24
+ ActiveRecord::Base.connection_pool.internal_metadata
25
+ elsif rails_version_equal_to_or_higher_than_7_1
18
26
  ActiveRecord::Base.connection.internal_metadata
19
27
  else
20
28
  ActiveRecord::InternalMetadata
@@ -22,7 +30,9 @@ module DataMigrate
22
30
  end
23
31
 
24
32
  def schema_migration
25
- if rails_version_equal_to_or_higher_than_7_1
33
+ if rails_version_equal_to_or_higher_than_7_2
34
+ ActiveRecord::Base.connection_pool.schema_migration
35
+ elsif rails_version_equal_to_or_higher_than_7_1
26
36
  ActiveRecord::Base.connection.schema_migration
27
37
  else
28
38
  ActiveRecord::SchemaMigration
@@ -54,7 +64,9 @@ module DataMigrate
54
64
  end
55
65
 
56
66
  def data_schema_migration
57
- if rails_version_equal_to_or_higher_than_7_1
67
+ if rails_version_equal_to_or_higher_than_7_2
68
+ DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool)
69
+ elsif rails_version_equal_to_or_higher_than_7_1
58
70
  DataMigrate::DataSchemaMigration.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection)
59
71
  else
60
72
  DataMigrate::DataSchemaMigration
@@ -15,7 +15,7 @@ module DataMigrate
15
15
  end
16
16
 
17
17
  def dump(stream)
18
- define_params = @version ? "version: #{@version}" : ""
18
+ define_params = @version ? "version: #{formatted_version}" : ""
19
19
 
20
20
  stream.puts "DataMigrate::Data.define(#{define_params})"
21
21
 
@@ -34,5 +34,12 @@ module DataMigrate
34
34
  0
35
35
  end
36
36
  end
37
+
38
+ # turns 20170404131909 into "2017_04_04_131909"
39
+ def formatted_version
40
+ stringified = @version.to_s
41
+ return stringified unless stringified.length == 14
42
+ stringified.insert(4, "_").insert(7, "_").insert(10, "_")
43
+ end
37
44
  end
38
45
  end
@@ -6,7 +6,7 @@ module DataMigrate
6
6
  extend self
7
7
 
8
8
  def migrations_paths
9
- @migrations_paths ||= DataMigrate.config.data_migrations_path
9
+ @migrations_paths ||= Array.wrap(DataMigrate.config.data_migrations_path)
10
10
  end
11
11
 
12
12
  def dump
@@ -55,11 +55,13 @@ module DataMigrate
55
55
  db_list_schema = DataMigrate::RailsHelper.schema_migration_versions
56
56
  file_list = []
57
57
 
58
- Dir.foreach(File.join(Rails.root, migrations_paths)) do |file|
59
- # only files matching "20091231235959_some_name.rb" pattern
60
- if match_data = /(\d{14})_(.+)\.rb/.match(file)
61
- status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
62
- file_list << [status, match_data[1], match_data[2], 'data']
58
+ migrations_paths.each do |path|
59
+ Dir.foreach(File.join(Rails.root, path)) do |file|
60
+ # only files matching "20091231235959_some_name.rb" pattern
61
+ if match_data = /(\d{14})_(.+)\.rb/.match(file)
62
+ status = db_list_data.delete(match_data[1]) ? 'up' : 'down'
63
+ file_list << [status, match_data[1], match_data[2], 'data']
64
+ end
63
65
  end
64
66
  end
65
67
 
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "9.4.2".freeze
2
+ VERSION = "11.3.1".freeze
3
3
  end
@@ -38,8 +38,9 @@ module DataMigrate
38
38
  File.join(data_migrations_path, "#{file_name}.rb")
39
39
  end
40
40
 
41
+ # Use the first path in the data_migrations_path as the target directory
41
42
  def data_migrations_path
42
- DataMigrate.config.data_migrations_path
43
+ Array.wrap(DataMigrate.config.data_migrations_path).first
43
44
  end
44
45
  end
45
46
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.4.2
4
+ version: 11.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
8
8
  - Ilya Katz
9
9
  - Deborah Enomah
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-08-14 00:00:00.000000000 Z
13
+ date: 2025-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -189,29 +189,9 @@ executables: []
189
189
  extensions: []
190
190
  extra_rdoc_files: []
191
191
  files:
192
- - ".github/workflows/build.yml"
193
- - ".github/workflows/gempush.yml"
194
- - ".gitignore"
195
- - ".hound.yml"
196
- - ".overcommit.yml"
197
- - ".rbenv-gemsets"
198
- - ".rspec"
199
- - ".rubocop.yml"
200
- - ".ruby-style.yml"
201
- - Appraisals
202
192
  - Changelog.md
203
- - Gemfile
204
- - Gemfile.lock
205
193
  - LICENSE
206
194
  - README.md
207
- - Rakefile
208
- - data_migrate.gemspec
209
- - gemfiles/rails_6.1.gemfile
210
- - gemfiles/rails_6.1.gemfile.lock
211
- - gemfiles/rails_7.0.gemfile
212
- - gemfiles/rails_7.0.gemfile.lock
213
- - gemfiles/rails_7.1.gemfile
214
- - gemfiles/rails_7.1.gemfile.lock
215
195
  - lib/capistrano/data_migrate.rb
216
196
  - lib/capistrano/data_migrate/migrate.rb
217
197
  - lib/data_migrate.rb
@@ -228,42 +208,17 @@ files:
228
208
  - lib/data_migrate/schema_migration.rb
229
209
  - lib/data_migrate/status_service.rb
230
210
  - lib/data_migrate/tasks/data_migrate_tasks.rb
231
- - lib/data_migrate/test.rb
232
211
  - lib/data_migrate/version.rb
233
212
  - lib/generators/data_migrate.rb
234
213
  - lib/generators/data_migration/data_migration_generator.rb
235
214
  - lib/generators/data_migration/templates/data_migration.rb
236
215
  - lib/generators/data_migration/templates/migration.rb
237
- - screenshot.png
238
- - spec/data_migrate/config_spec.rb
239
- - spec/data_migrate/data_migrator_spec.rb
240
- - spec/data_migrate/data_schema_migration_spec.rb
241
- - spec/data_migrate/data_spec.rb
242
- - spec/data_migrate/database_tasks_spec.rb
243
- - spec/data_migrate/migration.rb
244
- - spec/data_migrate/migration_context_spec.rb
245
- - spec/data_migrate/schema_dumper_spec.rb
246
- - spec/data_migrate/schema_migration_spec.rb
247
- - spec/data_migrate/status_service_spec.rb
248
- - spec/data_migrate/tasks/data_migrate_tasks_spec.rb
249
- - spec/db/data/20091231235959_some_name.rb
250
- - spec/db/data/20171231235959_super_update.rb
251
- - spec/db/data/20181128000207_excluded_file.rb.other_ext
252
- - spec/db/data/partial_schema/data_schema.rb
253
- - spec/db/data/partial_schema/test_data_schema.rb
254
- - spec/db/data/schema/data_schema.rb
255
- - spec/db/data/schema/test_data_schema.rb
256
- - spec/db/migrate/20131111111111_late_migration.rb
257
- - spec/db/migrate/20202020202011_db_migration.rb
258
- - spec/generators/data_migration/data_migration_generator_spec.rb
259
- - spec/spec_helper.rb
260
- - tasks/.gitkeep
261
216
  - tasks/databases.rake
262
217
  homepage: https://github.com/ilyakatz/data-migrate
263
218
  licenses:
264
219
  - MIT
265
220
  metadata: {}
266
- post_install_message:
221
+ post_install_message:
267
222
  rdoc_options: []
268
223
  require_paths:
269
224
  - lib
@@ -279,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
234
  version: '0'
280
235
  requirements: []
281
236
  rubygems_version: 3.4.19
282
- signing_key:
237
+ signing_key:
283
238
  specification_version: 4
284
239
  summary: Rake tasks to migrate data alongside schema changes.
285
240
  test_files: []
@@ -1,35 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- - push
5
- - pull_request
6
-
7
- jobs:
8
- test:
9
- strategy:
10
- fail-fast: false
11
- matrix:
12
- os: [ "ubuntu-20.04" ]
13
- ruby:
14
- - '3.0'
15
- - '3.1'
16
- - '3.2'
17
- - '3.3'
18
- gemfile:
19
- - gemfiles/rails_6.1.gemfile
20
- - gemfiles/rails_7.0.gemfile
21
- - gemfiles/rails_7.1.gemfile
22
- runs-on: ubuntu-latest
23
- env:
24
- BUNDLE_GEMFILE: ${{ matrix.gemfile }}
25
- RAILS_ENV: test
26
- steps:
27
- - name: Checkout code
28
- uses: actions/checkout@v3
29
- - name: Set up Ruby
30
- uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: ${{ matrix.ruby }}
33
- bundler-cache: true
34
- - name: Run tests
35
- run: bundle exec rspec
@@ -1,28 +0,0 @@
1
- name: Release Gem
2
-
3
- on:
4
- release:
5
- types: [released]
6
-
7
- jobs:
8
- build:
9
- name: Build + Publish
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - uses: actions/checkout@master
14
- - name: Set up Ruby 3.2
15
- uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: '3.2'
18
-
19
- - name: Publish to RubyGems
20
- run: |
21
- mkdir -p $HOME/.gem
22
- touch $HOME/.gem/credentials
23
- chmod 0600 $HOME/.gem/credentials
24
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
- gem build *.gemspec
26
- gem push *.gem
27
- env:
28
- GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.rvmrc
2
- *.gem
3
- gemfiles/.bundle
4
- spec/db/test.db
5
- spec/db/other_test.db
6
- spec/db/data_schema.rb
7
- .vscode/
8
- .DS_Store
9
- .ruby-gemset
10
- .ruby-version
11
- .idea/
12
- vendor/