data_migrate 6.5.0 → 7.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9494a8b6cdea5a4f06a66f520d98e5845abfae2262c9c98c2cea1d493a89de5
4
- data.tar.gz: 28819c7dde00d8a96486e39b6555340881f65278e14fb07814805106d61b972c
3
+ metadata.gz: 7dd1c0cc04a76e4332a3af19199beab36e329ecb2af1ab8d0fd706d0457e6f93
4
+ data.tar.gz: 1431e365d30537f284039aa1dd6dd7db12b24f9ec845fc3d0d3448adbec70c1c
5
5
  SHA512:
6
- metadata.gz: ab4a15ed15d0a54253644470bb800b24cc3465922b929e7e53b67b1ad868594ba40e40a57552438a93af544b308552b635972d00f5b1c4795022f328a0cbd3ee
7
- data.tar.gz: 0f8c135679143d45d34d0e49f1b86f0ff82876ffcd7d223160aa51d4f56ea99f6ad2dc18d13b38223355669334b89ae0f50fa2c42e858e04e69212ab75fe5e74
6
+ metadata.gz: c46327a2feee44ac29106baefa254204ce4adfa914e849ae0f63c6b617369ad3c4c00b0ece39f94137b5df2547ceecf73f8d3716539b38476467cac11b9ce664
7
+ data.tar.gz: d635f7561555a22a3695f60bfcb51eeb93ed89cce158abaeba78f373dbb37746be42ff94fb9277f65d48964887cde7587e215bbda3ee565f3c3aee3e40af6d46
data/.gitignore CHANGED
@@ -3,6 +3,9 @@
3
3
  *.lock
4
4
  gemfiles/.bundle
5
5
  spec/db/test.db
6
+ spec/db/other_test.db
7
+ spec/db/data_schema.rb
6
8
  .vscode/
7
9
  .DS_Store
8
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,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.8.0
4
+
5
+ Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
6
+ # 6.7.0
7
+
8
+ Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
9
+ Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
10
+ Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
11
+
12
+ ## 6.6.2
13
+ ## 6.6.1
14
+
15
+ configs_for deprecation notice [borama](https://github.com/borama)
16
+ ## 6.6.0
17
+
18
+ Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
19
+
3
20
  ## 6.4.0
4
21
 
5
22
  Add primary key to data_migrations table [aandis](https://github.com/aandis)
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,15 @@ 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
+ config.db_configuration = {
126
+ 'host' => '127.0.0.1',
127
+ 'database' => 'awesome_database',
128
+ 'adapter' => 'mysql2',
129
+ 'username' => 'root',
130
+ 'password' => nil,
131
+ }
132
+ config.spec_name = 'primary'
125
133
  end
126
134
 
127
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,10 +12,12 @@ module DataMigrate
12
12
  end
13
13
 
14
14
  class Config
15
- attr_accessor :data_migrations_path
15
+ attr_accessor :data_migrations_path, :db_configuration, :spec_name
16
16
 
17
17
  def initialize
18
18
  @data_migrations_path = "db/data/"
19
+ @db_configuration = nil
20
+ @spec_name = nil
19
21
  end
20
22
  end
21
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)
@@ -6,6 +6,16 @@ module DataMigrate
6
6
  @migrations_paths ||= DataMigrate.config.data_migrations_path
7
7
  end
8
8
 
9
+ def dump
10
+ if ActiveRecord::Base.dump_schema_after_migration
11
+ filename = DataMigrate::DatabaseTasks.schema_file
12
+ ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
13
+ File.open(filename, "w:utf-8") do |file|
14
+ DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
15
+ end
16
+ end
17
+ end
18
+
9
19
  def migrate
10
20
  DataMigrate::DataMigrator.assure_data_schema_table
11
21
  target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
@@ -1,3 +1,3 @@
1
1
  module DataMigrate
2
- VERSION = "6.5.0".freeze
2
+ VERSION = "7.0.0".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
@@ -3,6 +3,57 @@
3
3
  require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Tasks::DataMigrateTasks do
6
+ describe :dump do
7
+ let(:db_config) do
8
+ {
9
+ adapter: "sqlite3",
10
+ database: "spec/db/other_test.db"
11
+ }
12
+ end
13
+
14
+ before do
15
+ allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
16
+ allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
17
+ end
18
+
19
+ after do
20
+ ActiveRecord::Migration.drop_table("data_migrations")
21
+ end
22
+
23
+ context 'when not given a separate db config' do
24
+ it 'does not override the default connection' do
25
+ DataMigrate::Tasks::DataMigrateTasks.migrate
26
+ expect(ActiveRecord::Base).not_to receive(:establish_connection)
27
+ expect(DataMigrate::SchemaDumper).to receive(:dump)
28
+ DataMigrate::Tasks::DataMigrateTasks.dump
29
+ end
30
+ end
31
+
32
+ context 'when given ' do
33
+ let(:override_config) do
34
+ {
35
+ 'host' => '127.0.0.1',
36
+ 'database' => 'other_test',
37
+ 'adapter' => 'sqlite3',
38
+ 'username' => 'root',
39
+ 'password' => nil,
40
+ }
41
+ end
42
+
43
+ before do
44
+ DataMigrate.configure do |config|
45
+ config.db_configuration = override_config
46
+ end
47
+ end
48
+
49
+ it 'overrides the default connection' do
50
+ DataMigrate::Tasks::DataMigrateTasks.migrate
51
+ expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
52
+ DataMigrate::Tasks::DataMigrateTasks.dump
53
+ end
54
+ end
55
+ end
56
+
6
57
  describe :migrate do
7
58
  let(:db_config) do
8
59
  {
@@ -10,12 +61,12 @@ describe DataMigrate::Tasks::DataMigrateTasks do
10
61
  database: "spec/db/test.db"
11
62
  }
12
63
  end
13
-
64
+
14
65
  before do
15
66
  allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
16
67
  ActiveRecord::Base.establish_connection(db_config)
17
68
  end
18
-
69
+
19
70
  after do
20
71
  ActiveRecord::Migration.drop_table("data_migrations")
21
72
  end
@@ -54,9 +105,9 @@ describe DataMigrate::Tasks::DataMigrateTasks do
54
105
  }, {
55
106
  name: 'B',
56
107
  version: 2
57
- }]
108
+ }]
58
109
  end
59
-
110
+
60
111
  it "should abort with given message and print names and versions of pending migrations" do
61
112
  expect { subject }
62
113
  .to raise_error(SystemExit, message)
@@ -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
@@ -343,19 +343,14 @@ namespace :data do
343
343
 
344
344
  desc "Create a db/data_schema.rb file that stores the current data version"
345
345
  task dump: :environment do
346
- if ActiveRecord::Base.dump_schema_after_migration
347
- filename = DataMigrate::DatabaseTasks.schema_file
348
- File.open(filename, "w:utf-8") do |file|
349
- DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
350
- end
351
- end
346
+ DataMigrate::Tasks::DataMigrateTasks.dump
352
347
 
353
348
  # Allow this task to be called as many times as required. An example
354
349
  # is the migrate:redo task, which calls other two internally
355
350
  # that depend on this one.
356
351
  Rake::Task["data:dump"].reenable
357
352
  end
358
-
353
+
359
354
  namespace :schema do
360
355
  desc "Load data_schema.rb file into the database"
361
356
  task load: :environment do
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.5.0
4
+ version: 7.0.0
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-10-03 00:00:00.000000000 Z
13
+ date: 2021-04-19 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.2
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.