moargration 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/moargration.rb +14 -9
- data/moargration.gemspec +1 -1
- data/test/moargration_test.rb +2 -2
- data/test/test_helper.rb +5 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Worry not, Moargration won't impact your boot time until you actually need it.
|
|
28
28
|
|
29
29
|
So it's time to drop some columns.
|
30
30
|
|
31
|
-
Knowing that this can bring your app down, and that you normally need to do two deploys to safely
|
31
|
+
Knowing that this can bring your app down, and that you normally need to do two deploys to safely drop columns, you can use Moargration to setup the first step for you.
|
32
32
|
|
33
33
|
Just set an `ENV` var like:
|
34
34
|
|
data/lib/moargration.rb
CHANGED
@@ -5,8 +5,12 @@ module Moargration
|
|
5
5
|
|
6
6
|
def init
|
7
7
|
return unless ignore = ENV["MOARGRATION_IGNORE"]
|
8
|
-
|
9
|
-
hack_active_record
|
8
|
+
columns_to_ignore = parse(ignore)
|
9
|
+
hack_active_record!
|
10
|
+
end
|
11
|
+
|
12
|
+
def columns_to_ignore=(columns)
|
13
|
+
@@columns_to_ignore = columns
|
10
14
|
end
|
11
15
|
|
12
16
|
def columns_to_ignore
|
@@ -14,20 +18,21 @@ module Moargration
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def parse(text)
|
17
|
-
text.strip.split(" ").inject({}) do |parsed, definition|
|
21
|
+
@@columns_to_ignore = text.strip.split(" ").inject({}) do |parsed, definition|
|
18
22
|
table, fields = definition.split(":", 2)
|
19
23
|
parsed[table] = fields.split(",") if fields
|
20
24
|
parsed
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
def hack_active_record
|
25
|
-
@@columns_to_ignore = spec
|
26
|
-
|
28
|
+
def hack_active_record!
|
27
29
|
ActiveRecord::Base.class_eval do
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
class << self
|
31
|
+
alias :columns_without_moargration :columns
|
32
|
+
def columns
|
33
|
+
columns_without_moargration.reject do |column|
|
34
|
+
(Moargration.columns_to_ignore[table_name] || []).include?(column.name)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
data/moargration.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "moargration"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.3"
|
8
8
|
gem.authors = ["Pedro Belo"]
|
9
9
|
gem.email = ["pedro@heroku.com"]
|
10
10
|
gem.description = %q{Helping you migrate, MOAR.}
|
data/test/moargration_test.rb
CHANGED
@@ -21,12 +21,12 @@ describe Moargration do
|
|
21
21
|
|
22
22
|
describe "hack_active_record" do
|
23
23
|
it "hacks the model to ignore the specified columns" do
|
24
|
-
Moargration.
|
24
|
+
Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
|
25
25
|
Sample.columns.map(&:name).wont_include("f1")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "doesn't affect other models" do
|
29
|
-
Moargration.
|
29
|
+
Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
|
30
30
|
User.columns.map(&:name).must_include("f1")
|
31
31
|
end
|
32
32
|
end
|
data/test/test_helper.rb
CHANGED