data_migrate 6.3.0 → 6.7.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 +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +3 -0
- data/Appraisals +4 -0
- data/Changelog.md +18 -0
- data/Gemfile.rails6.1 +6 -0
- data/README.md +9 -1
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_6.1.gemfile +8 -0
- data/lib/data_migrate/config.rb +3 -1
- data/lib/data_migrate/data_migrator.rb +1 -10
- data/lib/data_migrate/data_migrator_five.rb +8 -3
- data/lib/data_migrate/data_schema_migration.rb +2 -2
- data/lib/data_migrate/migration.rb +2 -2
- data/lib/data_migrate/migration_five.rb +2 -2
- data/lib/data_migrate/schema_migration_six.rb +8 -1
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +10 -0
- data/lib/data_migrate/version.rb +1 -1
- data/spec/data_migrate/data_migrator_spec.rb +6 -0
- data/spec/data_migrate/data_schema_migration_spec.rb +2 -2
- data/spec/data_migrate/database_tasks_spec.rb +7 -2
- data/spec/data_migrate/migration.rb +1 -1
- data/spec/data_migrate/schema_migration_spec.rb +29 -0
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +55 -4
- data/spec/db/data/partial_schema/test_data_schema.rb +2 -0
- data/spec/db/data/schema/test_data_schema.rb +2 -0
- data/tasks/databases.rake +2 -7
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d433e96cf05b528252be16a5e05c6143bf278ed36557099ace0747bf80b5653
|
4
|
+
data.tar.gz: 17a0001c0f9bb93507f3147d7ed13e947661d012fe67186e7b768d82635cba2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230f8dd3c66d6def374b32af7776f86360ee18df38c36ebb126ab2dd06832009ed95d52cd752d43415a0358a588f3e1ca972275ab01be38e0f6fa0f29e947655
|
7
|
+
data.tar.gz: 9f8d5ce9e098ab46d4eec6330630a577b1c5941d35762d5304a2e390a3b4815df50da374f23ad289865cfa2f02e77db02df4a0a9f5d45aed6314851924cd2d0d
|
data/.gitignore
CHANGED
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
data/Changelog.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 6.7.0
|
4
|
+
|
5
|
+
Add configuration for which database name is to be used for database migrations [lewhit](https://github.com/lewhit)
|
6
|
+
Add tests for Rails 6.1 [lewhit](https://github.com/lewhit)
|
7
|
+
Migrations files should end only in .rb [kroehre](https://github.com/kroehre)
|
8
|
+
|
9
|
+
## 6.6.2
|
10
|
+
## 6.6.1
|
11
|
+
|
12
|
+
configs_for deprecation notice [borama](https://github.com/borama)
|
13
|
+
## 6.6.0
|
14
|
+
|
15
|
+
Allow data dump connection to be configured [lewhit](https://github.com/lewhit)
|
16
|
+
|
17
|
+
## 6.4.0
|
18
|
+
|
19
|
+
Add primary key to data_migrations table [aandis](https://github.com/aandis)
|
20
|
+
|
3
21
|
## 6.3.0
|
4
22
|
|
5
23
|
Add `abort_if_pending_migrations` rake tasks [tomgia](https://github.com/tomgia)
|
data/Gemfile.rails6.1
ADDED
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 =
|
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/lib/data_migrate/config.rb
CHANGED
@@ -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
|
@@ -76,17 +76,8 @@ module DataMigrate
|
|
76
76
|
|
77
77
|
def create_table(sm_table)
|
78
78
|
ActiveRecord::Base.connection.create_table(sm_table, id: false) do |schema_migrations_table|
|
79
|
-
schema_migrations_table.
|
79
|
+
schema_migrations_table.string :version, primary_key: true
|
80
80
|
end
|
81
|
-
|
82
|
-
suffix = ActiveRecord::Base.table_name_suffix
|
83
|
-
prefix = ActiveRecord::Base.table_name_prefix
|
84
|
-
index_name = "#{prefix}unique_data_migrations#{suffix}"
|
85
|
-
|
86
|
-
options = {unique: true, name: index_name}
|
87
|
-
options[:length] = 191 if ActiveRecord::Base.connection_config[:adapter] == "mysql2"
|
88
|
-
|
89
|
-
ActiveRecord::Base.connection.add_index sm_table, :version, options
|
90
81
|
end
|
91
82
|
|
92
83
|
def table_exists?(connection, table_name)
|
@@ -42,7 +42,7 @@ module DataMigrate
|
|
42
42
|
# @param (String) filename
|
43
43
|
# @return (MatchData)
|
44
44
|
def match(filename)
|
45
|
-
/(\d{14})_(.+)\.rb
|
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
|
-
|
79
|
-
|
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
|
|
@@ -6,8 +6,8 @@ module DataMigrate
|
|
6
6
|
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
"
|
9
|
+
def primary_key
|
10
|
+
"version"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -14,8 +14,8 @@ module DataMigrate
|
|
14
14
|
ActiveRecord::Base.table_name_prefix + "data_migrations" + ActiveRecord::Base.table_name_suffix
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
"
|
17
|
+
def primary_key
|
18
|
+
"version"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -14,8 +14,8 @@ module DataMigrate
|
|
14
14
|
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
"
|
17
|
+
def primary_key
|
18
|
+
"version"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -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)
|
@@ -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
|
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")
|
@@ -9,8 +9,8 @@ describe DataMigrate::DataSchemaMigration do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe :index_name do
|
12
|
-
it "returns correct
|
13
|
-
expect(subject.
|
12
|
+
it "returns correct primary key name" do
|
13
|
+
expect(subject.primary_key).to eq("version")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -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) {
|
@@ -14,6 +14,6 @@ describe subject do
|
|
14
14
|
it "uses correct index name" do
|
15
15
|
expect(subject).to receive(:table_name_prefix) { "" }
|
16
16
|
expect(subject).to receive(:table_name_suffix) { "" }
|
17
|
-
expect(subject.
|
17
|
+
expect(subject.primary_key).to eq("version")
|
18
18
|
end
|
19
19
|
end
|
@@ -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)
|
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
|
-
|
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.
|
4
|
+
version: 6.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J Vargo
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -191,15 +191,18 @@ files:
|
|
191
191
|
- Gemfile.rails5
|
192
192
|
- Gemfile.rails5.1
|
193
193
|
- Gemfile.rails5.2
|
194
|
+
- Gemfile.rails6.1
|
194
195
|
- LICENSE
|
195
196
|
- README.md
|
196
197
|
- Rakefile
|
197
198
|
- data_migrate.gemspec
|
198
199
|
- gemfiles/rails_4.1.gemfile
|
199
200
|
- gemfiles/rails_4.2.gemfile
|
201
|
+
- gemfiles/rails_5.0.gemfile
|
200
202
|
- gemfiles/rails_5.1.gemfile
|
201
203
|
- gemfiles/rails_5.2.gemfile
|
202
204
|
- gemfiles/rails_6.0.gemfile
|
205
|
+
- gemfiles/rails_6.1.gemfile
|
203
206
|
- lib/capistrano/data_migrate.rb
|
204
207
|
- lib/capistrano/data_migrate/migrate.rb
|
205
208
|
- lib/data_migrate.rb
|
@@ -250,7 +253,9 @@ files:
|
|
250
253
|
- spec/db/data/20171231235959_super_update.rb
|
251
254
|
- spec/db/data/20181128000207_excluded_file.rb.other_ext
|
252
255
|
- spec/db/data/partial_schema/data_schema.rb
|
256
|
+
- spec/db/data/partial_schema/test_data_schema.rb
|
253
257
|
- spec/db/data/schema/data_schema.rb
|
258
|
+
- spec/db/data/schema/test_data_schema.rb
|
254
259
|
- spec/db/migrate/4.2/20131111111111_late_migration.rb
|
255
260
|
- spec/db/migrate/4.2/20202020202011_db_migration.rb
|
256
261
|
- spec/db/migrate/5.0/20131111111111_late_migration.rb
|
@@ -288,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
293
|
- !ruby/object:Gem::Version
|
289
294
|
version: '0'
|
290
295
|
requirements: []
|
291
|
-
rubygems_version: 3.
|
296
|
+
rubygems_version: 3.2.3
|
292
297
|
signing_key:
|
293
298
|
specification_version: 4
|
294
299
|
summary: Rake tasks to migrate data alongside schema changes.
|