data_migrate 6.6.2 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -3
- data/Appraisals +4 -0
- data/Changelog.md +16 -0
- data/Gemfile +6 -1
- data/Gemfile.rails5 +6 -1
- data/Gemfile.rails5.1 +6 -1
- data/Gemfile.rails5.2 +6 -1
- data/Gemfile.rails6.1 +11 -0
- data/README.md +2 -1
- data/data_migrate.gemspec +7 -1
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_6.1.gemfile +8 -0
- data/lib/data_migrate/config.rb +2 -1
- data/lib/data_migrate/data_migrator_five.rb +1 -1
- data/lib/data_migrate/schema_dumper.rb +0 -4
- data/lib/data_migrate/schema_migration_six.rb +8 -1
- data/lib/data_migrate/version.rb +1 -1
- data/lib/generators/data_migration/templates/data_migration.rb +2 -0
- data/spec/data_migrate/data_migrator_spec.rb +6 -0
- data/spec/data_migrate/database_tasks_spec.rb +7 -2
- data/spec/data_migrate/schema_migration_spec.rb +29 -0
- data/spec/db/data/partial_schema/data_schema.rb +0 -1
- data/spec/db/data/partial_schema/test_data_schema.rb +1 -0
- data/spec/db/data/schema/data_schema.rb +0 -1
- data/spec/db/data/schema/test_data_schema.rb +1 -0
- data/tasks/databases.rake +18 -32
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d029ae70dba905ed85200561697e4e44b62b654ab216d6b20b809737e35f3fc1
|
4
|
+
data.tar.gz: 39f53a2d2f289d8d55730f9657bbaef454abff395593e354fa31ef11b1a38dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e7f347d47d48acab66cb3e700f72321805ee29fbed1bbb7689bfaafb0f7cff6a0add4a62ec847cb0d49dd18b46f9408b3b8d3a2bf56c0fa1c2a75dcabb3277
|
7
|
+
data.tar.gz: 63a062d5266920ecddd9d18a781f9105390f9188cc9ed6cc4930a99821ab2ed972dae7cb2687de9202c0a26fcf29040eb77aae78215e43401d234685116a7981
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.6.2
|
3
|
+
- 2.6
|
4
|
+
- 2.7
|
6
5
|
script: bundle exec rspec
|
7
6
|
gemfile:
|
8
7
|
- gemfiles/rails_5.1.gemfile
|
9
8
|
- gemfiles/rails_5.2.gemfile
|
10
9
|
- gemfiles/rails_6.0.gemfile
|
10
|
+
- gemfiles/rails_6.1.gemfile
|
11
11
|
matrix:
|
12
12
|
exclude:
|
13
13
|
- rvm: 2.4.4
|
14
14
|
gemfile: gemfiles/rails_6.0.gemfile
|
15
|
+
- rvm: 2.4.4
|
16
|
+
gemfile: gemfiles/rails_6.1.gemfile
|
data/Appraisals
CHANGED
data/Changelog.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 7.0.2
|
4
|
+
|
5
|
+
Remove magic comment in migration files [y-yagi](https://github.com/y-yagi)
|
6
|
+
User frozen string [jonnay](https://github.com/jonnay)
|
7
|
+
## 7.0.1
|
8
|
+
Use SchemaMigration.migrations_paths in main rake task [lewhit](https://github.com/lewhit)
|
9
|
+
|
10
|
+
## 6.8.0
|
11
|
+
|
12
|
+
Specify database name for migrations_paths [lewhit](https://github.com/lewhit)
|
13
|
+
## 6.7.0
|
14
|
+
|
15
|
+
Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
|
16
|
+
Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
|
17
|
+
Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
|
18
|
+
|
3
19
|
## 6.6.2
|
4
20
|
## 6.6.1
|
5
21
|
|
data/Gemfile
CHANGED
data/Gemfile.rails5
CHANGED
data/Gemfile.rails5.1
CHANGED
data/Gemfile.rails5.2
CHANGED
data/Gemfile.rails6.1
ADDED
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 =
|
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
|
-
|
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"
|
data/lib/data_migrate/config.rb
CHANGED
@@ -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
|
@@ -17,10 +17,6 @@ module DataMigrate
|
|
17
17
|
def dump(stream)
|
18
18
|
define_params = @version ? "version: #{@version}" : ""
|
19
19
|
|
20
|
-
if stream.respond_to?(:external_encoding) && stream.external_encoding
|
21
|
-
stream.puts "# encoding: #{stream.external_encoding.name}"
|
22
|
-
end
|
23
|
-
|
24
20
|
stream.puts "DataMigrate::Data.define(#{define_params})"
|
25
21
|
|
26
22
|
stream
|
@@ -21,7 +21,14 @@ module DataMigrate
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.migrations_paths
|
24
|
-
|
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)
|
data/lib/data_migrate/version.rb
CHANGED
@@ -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 @@
|
|
1
|
+
DataMigrate::Data.define(version: 20091231235959)
|
@@ -0,0 +1 @@
|
|
1
|
+
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
4
|
+
version: 7.0.2
|
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: 2021-
|
13
|
+
date: 2021-07-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
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.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.
|