migration_data 0.4.0 → 0.5.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/README.md +15 -1
- data/lib/migration_data.rb +1 -3
- data/lib/migration_data/active_record/migration.rb +2 -0
- data/lib/migration_data/config.rb +6 -0
- data/lib/migration_data/testing.rb +2 -0
- data/lib/migration_data/version.rb +1 -1
- data/test/migration_test.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcfa827b7ff6fe4bf4509b6c4a5d148a52ad5328312de09c482b6532d3bdf893
|
4
|
+
data.tar.gz: 7ce0546a76606344b3b17c0e26bfae78724c66556e3c928cefc8a2919910489c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1ed960aadd4db399fd6a9d0b1881484bfa494cbe654cc995114b6c23e0031d78ae77d9b1e2f888c72df885f77c33d69e9d8bb3e4f8a9df67f34b084fee6146
|
7
|
+
data.tar.gz: 6ed2163de0401cf380e786a823358d714f948eb968a3132c33a1672dfaac5a2e83e7c04b6b74cb0a14c767ab36ab1254a227cee71c7b3ce0ea9eef7c0380ea37
|
data/README.md
CHANGED
@@ -81,7 +81,21 @@ describe CreateUsers do
|
|
81
81
|
end
|
82
82
|
```
|
83
83
|
|
84
|
-
The helper to load migrations `require_migration` is defined in the `migration_data/testing`. So you should to require it to have access to this
|
84
|
+
The helper to load migrations `require_migration` is defined in the `migration_data/testing`. So you should to require it to have access to this convenient require extension.
|
85
|
+
|
86
|
+
## Skipping data migrations execution
|
87
|
+
|
88
|
+
At some point, one might realize that data migrations should not run on particular environments, e.g. `test`.
|
89
|
+
|
90
|
+
On performing migrations in `test` environment, a data migration might try to add the same data that has already been added by seeds. In that case, migrations might fail with a duplication error.
|
91
|
+
|
92
|
+
Use `MigrationData.config.skip = true` to skip data migrations execution. One might put this code in an initializer, e.g. `config/initializers/migration_data.rb`:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
if Rails.env.test?
|
96
|
+
MigrationData.config.skip = true
|
97
|
+
end
|
98
|
+
```
|
85
99
|
|
86
100
|
## Contributing
|
87
101
|
|
data/lib/migration_data.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'migration_data/version'
|
3
3
|
require 'migration_data/active_record/migration'
|
4
|
-
|
5
|
-
require 'rake'
|
6
|
-
import File.join(File.dirname(__FILE__), 'tasks', 'db.rake')
|
4
|
+
require 'migration_data/config'
|
7
5
|
|
8
6
|
ActiveRecord::Migration.send(:include, MigrationData::ActiveRecord::Migration)
|
@@ -15,6 +15,8 @@ module MigrationData
|
|
15
15
|
base.class_eval do
|
16
16
|
def exec_migration_with_data(conn, direction)
|
17
17
|
origin_exec_migration(conn, direction)
|
18
|
+
::ActiveRecord::Base.connection.schema_cache.clear!
|
19
|
+
return if MigrationData.config.skip_data_on_test
|
18
20
|
data if direction == :up && respond_to?(:data)
|
19
21
|
rollback if direction == :down && respond_to?(:rollback)
|
20
22
|
end
|
@@ -17,6 +17,8 @@ end
|
|
17
17
|
def all_migrations(path)
|
18
18
|
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
|
19
19
|
ActiveRecord::MigrationContext.new(path).migrations
|
20
|
+
elsif Rails::VERSION::MAJOR > 5
|
21
|
+
ActiveRecord::MigrationContext.new(path, nil).migrations
|
20
22
|
else
|
21
23
|
ActiveRecord::Migrator.migrations(path)
|
22
24
|
end
|
data/test/migration_test.rb
CHANGED
@@ -38,4 +38,24 @@ describe MyMigration do
|
|
38
38
|
assert_nil @migration.rolled_back_data
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "#migrate with Rails.env = test and skip_data_on_test = true" do
|
43
|
+
before do
|
44
|
+
@old_skip, MigrationData.config.skip_data_on_test = MigrationData.config.skip_data_on_test, true
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
MigrationData.config.skip_data_on_test = @old_skip
|
49
|
+
end
|
50
|
+
|
51
|
+
it "doesn't runs #data" do
|
52
|
+
@migration.migrate(:up)
|
53
|
+
refute @migration.migrated_data
|
54
|
+
end
|
55
|
+
|
56
|
+
it "doesn't runs #rollback" do
|
57
|
+
@migration.migrate(:down)
|
58
|
+
refute @migration.rolled_back_data
|
59
|
+
end
|
60
|
+
end
|
41
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migration_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Koleshko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- Rakefile
|
73
73
|
- lib/migration_data.rb
|
74
74
|
- lib/migration_data/active_record/migration.rb
|
75
|
+
- lib/migration_data/config.rb
|
75
76
|
- lib/migration_data/testing.rb
|
76
77
|
- lib/migration_data/version.rb
|
77
78
|
- migration_data.gemspec
|