data_migrate 6.6.0 → 7.0.1

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: b5b08f7465fcf3fba0054816fa8b07b07216ba3831114b0a8d477e24caa7ba98
4
- data.tar.gz: 556f3785c1b198cc36daac457809b95fe79754276b2ad4f1056ab1f7dfbd748d
3
+ metadata.gz: eb3b56bd9d4670d332c63569b1744e1bb98af5f2f492ba3df0d4b80a5bdb7f7d
4
+ data.tar.gz: '08fe1b1769bf9c021aa2896e733d98100034d934e6a27492f6e455ad3f7475dd'
5
5
  SHA512:
6
- metadata.gz: 3df442c3c71eb087476c1c66a0ad1b0d74672b98a6ada2fb9349874f28a3bb3321ba3bc856278f63756d778e9ea7568771788d6e94a255f6f92a0d673f9782a8
7
- data.tar.gz: f56faf7e4dd10ef8a1c9e0698190ee5a6cdf2217e1bbdc1a153bc64b3b43e32d3d0065b81fe2e15f9811fe6a5ba3ee40f722d0009da1e00586f7be97349210cc
6
+ metadata.gz: 1d84302907054176f07464c0c4ec0f2340d43e90305477fb0da6dac29a597287628f26882590168c4bd8e2d376deacbde53d27e8e5458a6dbe0970f275462886
7
+ data.tar.gz: 055f2fe4fea33cc47d64976bd5c5f630099e0be193a7b01f01f76f4e272de20bdc43b5e6ba2de2888a1a60643ad4947af03dfa71190cb5b1812550eab9a95e1b
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ spec/db/data_schema.rb
8
8
  .vscode/
9
9
  .DS_Store
10
10
  .idea/
11
+ vendor/
data/.travis.yml CHANGED
@@ -8,7 +8,10 @@ gemfile:
8
8
  - gemfiles/rails_5.1.gemfile
9
9
  - gemfiles/rails_5.2.gemfile
10
10
  - gemfiles/rails_6.0.gemfile
11
+ - gemfiles/rails_6.1.gemfile
11
12
  matrix:
12
13
  exclude:
13
14
  - rvm: 2.4.4
14
15
  gemfile: gemfiles/rails_6.0.gemfile
16
+ - rvm: 2.4.4
17
+ gemfile: gemfiles/rails_6.1.gemfile
data/Appraisals CHANGED
@@ -13,3 +13,7 @@ end
13
13
  appraise 'rails-6.0' do
14
14
  gem 'rails', '~> 6.0.0'
15
15
  end
16
+
17
+ appraise 'rails-6.1' do
18
+ gem 'rails', '~> 6.1.0'
19
+ end
data/Changelog.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
+ ## 7.0.1
3
+ Use SchemaMigrations.migration_paths in main rake task [lewhit](https://github.com/lewhit)
2
4
 
5
+ ## 6.8.0
6
+
7
+ Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
8
+ ## 6.7.0
9
+
10
+ Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
11
+ Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
12
+ Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
13
+
14
+ ## 6.6.2
15
+ ## 6.6.1
16
+
17
+ configs_for deprecation notice [borama](https://github.com/borama)
3
18
  ## 6.6.0
4
19
 
5
20
  Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
- gem 'rails', '~> 6.0.0'
4
+ %w[
5
+ activerecord
6
+ railties
7
+ ].each do |rails_gem|
8
+ gem rails_gem, '~> 6.0.0'
9
+ end
5
10
  gem 'sqlite3', "~> 1.4"
6
11
  gemspec
data/Gemfile.rails5 CHANGED
@@ -2,4 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
4
  gemspec
5
- gem 'rails', '~> 5.0.0'
5
+ %w[
6
+ activerecord
7
+ railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, '~> 5.0.0'
10
+ end
data/Gemfile.rails5.1 CHANGED
@@ -2,4 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
4
  gemspec
5
- gem 'rails', '~> 5.1.7'
5
+ %w[
6
+ activerecord
7
+ railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, '~> 5.1.7'
10
+ end
data/Gemfile.rails5.2 CHANGED
@@ -2,4 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in data_migrate.gemspec
4
4
  gemspec
5
- gem 'rails', '~> 5.2'
5
+ %w[
6
+ activerecord
7
+ railties
8
+ ].each do |rails_gem|
9
+ gem rails_gem, '~> 5.2'
10
+ end
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
@@ -121,7 +121,7 @@ You can override this setting in `config/initializers/data_migrate.rb`
121
121
 
122
122
  ```ruby
123
123
  DataMigrate.configure do |config|
124
- config.data_migrations_path = "db/awesomepath/"
124
+ config.data_migrations_path = 'db/awesomepath/'
125
125
  config.db_configuration = {
126
126
  'host' => '127.0.0.1',
127
127
  'database' => 'awesome_database',
@@ -129,6 +129,7 @@ DataMigrate.configure do |config|
129
129
  'username' => 'root',
130
130
  'password' => nil,
131
131
  }
132
+ config.spec_name = 'primary'
132
133
  end
133
134
 
134
135
  ```
data/data_migrate.gemspec CHANGED
@@ -15,7 +15,13 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "data_migrate"
17
17
 
18
- s.add_dependency('rails', '>= 5.0')
18
+ %w[
19
+ activerecord
20
+ railties
21
+ ].each do |rails_gem|
22
+ s.add_dependency(rails_gem, '>= 5.0')
23
+ end
24
+
19
25
  s.add_development_dependency "appraisal"
20
26
  s.add_development_dependency "rake"
21
27
  s.add_development_dependency "rspec"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "5.0.7.2"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"
@@ -12,11 +12,12 @@ module DataMigrate
12
12
  end
13
13
 
14
14
  class Config
15
- attr_accessor :data_migrations_path, :db_configuration
15
+ attr_accessor :data_migrations_path, :db_configuration, :spec_name
16
16
 
17
17
  def initialize
18
18
  @data_migrations_path = "db/data/"
19
19
  @db_configuration = nil
20
+ @spec_name = nil
20
21
  end
21
22
  end
22
23
  end
@@ -42,7 +42,7 @@ module DataMigrate
42
42
  # @param (String) filename
43
43
  # @return (MatchData)
44
44
  def match(filename)
45
- /(\d{14})_(.+)\.rb/.match(filename)
45
+ /(\d{14})_(.+)\.rb$/.match(filename)
46
46
  end
47
47
 
48
48
  def needs_migration?
@@ -75,8 +75,13 @@ module DataMigrate
75
75
  end
76
76
 
77
77
  def db_config
78
- ActiveRecord::Base.configurations[Rails.env || "development"] ||
79
- ENV["DATABASE_URL"]
78
+ env = Rails.env || "development"
79
+ ar_config = if (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 6
80
+ ActiveRecord::Base.configurations.configs_for(env_name: env).first
81
+ else
82
+ ActiveRecord::Base.configurations[env]
83
+ end
84
+ ar_config || ENV["DATABASE_URL"]
80
85
  end
81
86
  end
82
87
 
@@ -21,7 +21,14 @@ module DataMigrate
21
21
  end
22
22
 
23
23
  def self.migrations_paths
24
- Rails.application.config.paths["db/migrate"].to_a
24
+ spec_name = DataMigrate.config.spec_name
25
+ if spec_name && Rails.version > '6.1'
26
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: spec_name).migrations_paths
27
+ elsif spec_name
28
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: spec_name).migrations_paths
29
+ else
30
+ Rails.application.config.paths["db/migrate"].to_a
31
+ end
25
32
  end
26
33
 
27
34
  def self.sort_string(migration)
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "6.6.0".freeze
2
+ VERSION = "7.0.1".freeze
3
3
  end
@@ -82,6 +82,12 @@ describe DataMigrate::DataMigrator do
82
82
  end
83
83
  end
84
84
 
85
+ context "when the file doesn't end in .rb" do
86
+ it "returns nil" do
87
+ expect(subject.match("20091231235959_some_name.rb.un~")).to be_nil
88
+ end
89
+ end
90
+
85
91
  context "when the file matches" do
86
92
  it "returns a valid MatchData object" do
87
93
  match_data = subject.match("20091231235959_some_name.rb")
@@ -39,8 +39,14 @@ describe DataMigrate::DatabaseTasks do
39
39
  data_migrations_path
40
40
  }
41
41
  allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
42
- ActiveRecord::Base.configurations[:test] =db_config
43
42
  ActiveRecord::Base.establish_connection(db_config)
43
+ if Rails.version >= '6.1'
44
+ hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
45
+ config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
46
+ allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
47
+ else
48
+ ActiveRecord::Base.configurations[:test] = db_config
49
+ end
44
50
  end
45
51
 
46
52
  describe :schema_file do
@@ -59,7 +65,6 @@ describe DataMigrate::DatabaseTasks do
59
65
  end
60
66
 
61
67
  before do
62
- # ActiveRecord::Base.establish_connection(db_config)
63
68
  ActiveRecord::SchemaMigration.create_table
64
69
 
65
70
  allow(DataMigrate::SchemaMigration).to receive(:migrations_paths) {
@@ -68,4 +68,33 @@ describe DataMigrate::SchemaMigration do
68
68
  expect(versions.count).to eq(0)
69
69
  end
70
70
  end
71
+
72
+ if Rails.version > '6'
73
+ describe :migrations_paths do
74
+ context 'when a db_name is configured' do
75
+ let(:paths) { ['spec/db/migrate/6.0', 'spec/db/components/migrate/6.0'] }
76
+
77
+ if Rails.version > '6.1'
78
+ before do
79
+ allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', name: 'primary')).to receive(:migrations_paths).and_return(paths)
80
+ DataMigrate.configure do |config|
81
+ config.spec_name = 'primary'
82
+ end
83
+ end
84
+ else
85
+ before do
86
+ allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', spec_name: 'primary')).to receive(:migrations_paths).and_return(paths)
87
+ DataMigrate.configure do |config|
88
+ config.spec_name = 'primary'
89
+ end
90
+ end
91
+ end
92
+
93
+ it 'lists schema migration paths' do
94
+ expect(subject.migrations_paths.size).to eq(2)
95
+ expect(subject.migrations_paths).to eq(paths)
96
+ end
97
+ end
98
+ end
99
+ end
71
100
  end
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ DataMigrate::Data.define(version: 20091231235959)
@@ -0,0 +1,2 @@
1
+ # encoding: UTF-8
2
+ DataMigrate::Data.define(version: 20171231235959)
data/tasks/databases.rake CHANGED
@@ -46,17 +46,7 @@ namespace :db do
46
46
  end
47
47
 
48
48
  migrations.each do |migration|
49
- if migration[:kind] == :data
50
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
51
- DataMigrate::DataMigrator.run(migration[:direction], data_migrations_path, migration[:version])
52
- else
53
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
54
- DataMigrate::SchemaMigration.run(
55
- migration[:direction],
56
- Rails.application.config.paths["db/migrate"],
57
- migration[:version]
58
- )
59
- end
49
+ run_migration(migration, migration[:direction])
60
50
  end
61
51
 
62
52
  Rake::Task["db:_dump"].invoke
@@ -91,13 +81,7 @@ namespace :db do
91
81
  end
92
82
 
93
83
  migrations.each do |migration|
94
- if migration[:kind] == :data
95
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
96
- DataMigrate::DataMigrator.run(:up, data_migrations_path, migration[:version])
97
- else
98
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
99
- DataMigrate::SchemaMigration.run(:up, "db/migrate/", migration[:version])
100
- end
84
+ run_migration(migration, :up)
101
85
  end
102
86
 
103
87
  Rake::Task["db:_dump"].invoke
@@ -119,13 +103,7 @@ namespace :db do
119
103
  end
120
104
 
121
105
  migrations.each do |migration|
122
- if migration[:kind] == :data
123
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
124
- DataMigrate::DataMigrator.run(:down, data_migrations_path, migration[:version])
125
- else
126
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
127
- DataMigrate::SchemaMigration.run(:down, "db/migrate/", migration[:version])
128
- end
106
+ run_migration(migration, :down)
129
107
  end
130
108
 
131
109
  Rake::Task["db:_dump"].invoke
@@ -189,13 +167,7 @@ namespace :db do
189
167
  step = ENV['STEP'] ? ENV['STEP'].to_i : 1
190
168
  assure_data_schema_table
191
169
  past_migrations[0..(step - 1)].each do | past_migration |
192
- if past_migration[:kind] == :data
193
- ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
194
- DataMigrate::DataMigrator.run(:down, data_migrations_path, past_migration[:version])
195
- elsif past_migration[:kind] == :schema
196
- ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
197
- DataMigrate::SchemaMigration.run(:down, "db/migrate/", past_migration[:version])
198
- end
170
+ run_migration(past_migration, :down)
199
171
  end
200
172
 
201
173
  Rake::Task["db:_dump"].invoke
@@ -412,3 +384,17 @@ end
412
384
  def data_migrations_path
413
385
  DataMigrate.config.data_migrations_path
414
386
  end
387
+
388
+ def run_migration(migration, direction)
389
+ if migration[:kind] == :data
390
+ ActiveRecord::Migration.write("== %s %s" % ['Data', "=" * 71])
391
+ DataMigrate::DataMigrator.run(direction, data_migrations_path, migration[:version])
392
+ else
393
+ ActiveRecord::Migration.write("== %s %s" % ['Schema', "=" * 69])
394
+ DataMigrate::SchemaMigration.run(
395
+ direction,
396
+ DataMigrate::SchemaMigration.migrations_paths,
397
+ migration[:version]
398
+ )
399
+ end
400
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.6.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew J Vargo
@@ -10,10 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-12-15 00:00:00.000000000 Z
13
+ date: 2021-05-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rails
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '5.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '5.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: railties
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
33
  - - ">="
@@ -191,15 +205,18 @@ files:
191
205
  - Gemfile.rails5
192
206
  - Gemfile.rails5.1
193
207
  - Gemfile.rails5.2
208
+ - Gemfile.rails6.1
194
209
  - LICENSE
195
210
  - README.md
196
211
  - Rakefile
197
212
  - data_migrate.gemspec
198
213
  - gemfiles/rails_4.1.gemfile
199
214
  - gemfiles/rails_4.2.gemfile
215
+ - gemfiles/rails_5.0.gemfile
200
216
  - gemfiles/rails_5.1.gemfile
201
217
  - gemfiles/rails_5.2.gemfile
202
218
  - gemfiles/rails_6.0.gemfile
219
+ - gemfiles/rails_6.1.gemfile
203
220
  - lib/capistrano/data_migrate.rb
204
221
  - lib/capistrano/data_migrate/migrate.rb
205
222
  - lib/data_migrate.rb
@@ -250,7 +267,9 @@ files:
250
267
  - spec/db/data/20171231235959_super_update.rb
251
268
  - spec/db/data/20181128000207_excluded_file.rb.other_ext
252
269
  - spec/db/data/partial_schema/data_schema.rb
270
+ - spec/db/data/partial_schema/test_data_schema.rb
253
271
  - spec/db/data/schema/data_schema.rb
272
+ - spec/db/data/schema/test_data_schema.rb
254
273
  - spec/db/migrate/4.2/20131111111111_late_migration.rb
255
274
  - spec/db/migrate/4.2/20202020202011_db_migration.rb
256
275
  - spec/db/migrate/5.0/20131111111111_late_migration.rb
@@ -288,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
307
  - !ruby/object:Gem::Version
289
308
  version: '0'
290
309
  requirements: []
291
- rubygems_version: 3.1.4
310
+ rubygems_version: 3.2.15
292
311
  signing_key:
293
312
  specification_version: 4
294
313
  summary: Rake tasks to migrate data alongside schema changes.