migration_data 0.0.3 → 0.0.4
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/.travis.yml +5 -0
- data/README.md +6 -2
- data/lib/migration_data/active_record/migration.rb +17 -0
- data/lib/migration_data/testing.rb +2 -0
- data/lib/migration_data/version.rb +1 -1
- data/lib/migration_data.rb +3 -10
- data/migration_data.gemspec +1 -1
- data/test/require_migration_test.rb +5 -3
- data/test/test_helper.rb +0 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd17cf47cfa0baf42b5c1d2352959ec3157a975b
|
4
|
+
data.tar.gz: de896217509a426ff6c4e937d84f761783807623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95485cd38bf813737a1b8d2608b2fd98086b79c60f220be527228e4417580a41bc627a27a87ef07355198722ccfee9fb9876bb3be66fb1b88bc64234aff429f
|
7
|
+
data.tar.gz: ee4b11882e2439e0ba09baccb514ca95bad1400a7200f6865655e64788bdbc9386f1719a4091330a38648db1655722d930f1bb4478d3549ff061c5db9ee6f92e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# MigrationData
|
2
2
|
|
3
|
+
[](https://travis-ci.org/ka8725/migration_data)
|
4
|
+
|
3
5
|
This gem provides functionality to write any code in migrations safely without regression.
|
4
6
|
|
5
7
|
Sometimes we have to write some Rails code in the migrations and it's hard to
|
@@ -8,7 +10,9 @@ some techniques which help to avoid these pitfalls. For example, define model
|
|
8
10
|
classes in the migrations or write raw SQL. But they don't help in 100% cases anyway.
|
9
11
|
This gem promises to solve the problem in a simple way.
|
10
12
|
|
11
|
-
Currently the gem supports Rails 4
|
13
|
+
Currently the gem supports Rails 4.
|
14
|
+
|
15
|
+
If you still don't understand what for this gem please check out [this blob post](http://railsguides.net/2014/01/30/change-data-in-migrations-like-a-boss/).
|
12
16
|
|
13
17
|
## Installation
|
14
18
|
|
@@ -46,7 +50,7 @@ NOTE: it's not run on `down`. If you have any reason to do it please fell free t
|
|
46
50
|
|
47
51
|
## Testing migrations
|
48
52
|
|
49
|
-
To keep your migrations working don't forget to write
|
53
|
+
To keep your migrations working don't forget to write tests for them.
|
50
54
|
Possible `RSpec` test for the migration looks like this:
|
51
55
|
|
52
56
|
```ruby
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MigrationData
|
2
|
+
module ActiveRecord
|
3
|
+
module Migration
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def exec_migration_with_data(conn, direction)
|
7
|
+
origin_exec_migration(conn, direction)
|
8
|
+
data if direction == :up && respond_to?(:data)
|
9
|
+
end
|
10
|
+
|
11
|
+
alias origin_exec_migration exec_migration
|
12
|
+
alias exec_migration exec_migration_with_data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/migration_data.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
+
require 'active_record'
|
1
2
|
require 'migration_data/version'
|
3
|
+
require 'migration_data/active_record/migration'
|
2
4
|
|
3
|
-
|
4
|
-
def exec_migration(conn, direction)
|
5
|
-
super
|
6
|
-
if direction == :up && respond_to?(:data)
|
7
|
-
data
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
ActiveRecord::Migration.prepend(MigrationData)
|
5
|
+
ActiveRecord::Migration.send(:include, MigrationData::ActiveRecord::Migration)
|
data/migration_data.gemspec
CHANGED
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
26
26
|
spec.add_development_dependency 'rake'
|
27
27
|
spec.add_development_dependency 'sqlite3'
|
28
|
-
spec.add_dependency '
|
28
|
+
spec.add_dependency 'rails', '>= 4.0.0.rc1'
|
29
29
|
end
|
@@ -4,12 +4,14 @@ require 'migration_data/testing'
|
|
4
4
|
describe '#require_migration' do
|
5
5
|
let(:db_path) do
|
6
6
|
test_dir = File.expand_path(File.dirname(__FILE__))
|
7
|
-
File.join(test_dir, 'db')
|
7
|
+
Pathname(File.join(test_dir, 'db'))
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'loads existed migation' do
|
11
|
-
|
12
|
-
|
11
|
+
Rails.stub(:root, db_path) do
|
12
|
+
ActiveRecord::Migrator.stub(:migrations_path, db_path) do
|
13
|
+
require_migration 'test_migration'
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
data/test/test_helper.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Koleshko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -79,11 +79,13 @@ extensions: []
|
|
79
79
|
extra_rdoc_files: []
|
80
80
|
files:
|
81
81
|
- ".gitignore"
|
82
|
+
- ".travis.yml"
|
82
83
|
- Gemfile
|
83
84
|
- LICENSE.txt
|
84
85
|
- README.md
|
85
86
|
- Rakefile
|
86
87
|
- lib/migration_data.rb
|
88
|
+
- lib/migration_data/active_record/migration.rb
|
87
89
|
- lib/migration_data/testing.rb
|
88
90
|
- lib/migration_data/version.rb
|
89
91
|
- migration_data.gemspec
|