moargration 0.0.4 → 0.0.5

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.
data/Gemfile CHANGED
@@ -4,4 +4,6 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem "activerecord", "2.3.14"
7
+ gem "minitest", "~> 4.2"
8
+ gem "pg"
7
9
  end
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # Moargration
2
2
 
3
- Helping you migrate, MOAR.
3
+ Helping you migrate MOAR.
4
4
 
5
5
  This is Ruby gem that takes environment variables to assist the execution of database migrations that would otherwise require two-step deploys.
6
6
 
7
7
  For more information refer to [Rails migrations with no downtime](http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/).
8
8
 
9
+ Currently works only with ActiveRecord 2.x.
9
10
 
10
11
  ## Setup
11
12
 
@@ -41,15 +42,21 @@ After the migration finishes you can unset that variable and enjoy your new data
41
42
 
42
43
  ## The example above is not completely obvious, I need a [BNF grammar](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form)
43
44
 
44
- Sure thing, bro:
45
+ Sure thing:
45
46
 
46
47
  <ignore> ::= <definition> { " " <definition> }
47
48
  <definition> ::= <table> ":" <fields>
48
49
  <fields> ::= <field> { "," <field> }
49
50
 
50
51
 
52
+ ## Todo
53
+
54
+ * Sequel::Model support
55
+ * ActiveRecord 3 support
56
+
57
+
51
58
  ## Notes
52
59
 
53
60
  Created by Pedro Belo.
54
61
  Licensed as MIT.
55
- Use at your own risk.
62
+ Use at your own risk.
@@ -4,8 +4,9 @@ module Moargration
4
4
  extend self
5
5
 
6
6
  def init
7
+ @@columns_to_ignore = {}
7
8
  return unless ignore = ENV["MOARGRATION_IGNORE"]
8
- columns_to_ignore = parse(ignore)
9
+ self.columns_to_ignore = parse(ignore)
9
10
  hack_active_record!
10
11
  end
11
12
 
@@ -17,8 +18,13 @@ module Moargration
17
18
  @@columns_to_ignore
18
19
  end
19
20
 
21
+ def ignoring?(table, column)
22
+ ignored_columns = columns_to_ignore[table.to_s] || []
23
+ ignored_columns.include?(column.to_s)
24
+ end
25
+
20
26
  def parse(text)
21
- @@columns_to_ignore = text.strip.split(" ").inject({}) do |parsed, definition|
27
+ text.strip.split(" ").inject({}) do |parsed, definition|
22
28
  table, fields = definition.split(":", 2)
23
29
  parsed[table] = fields.split(",") if fields
24
30
  parsed
@@ -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.4"
7
+ gem.version = "0.0.5"
8
8
  gem.authors = ["Pedro Belo"]
9
9
  gem.email = ["pedro@heroku.com"]
10
10
  gem.description = %q{Helping you migrate, MOAR.}
@@ -19,6 +19,27 @@ describe Moargration do
19
19
  end
20
20
  end
21
21
 
22
+ describe "ignoring?" do
23
+ it "helper to indicate if Moargration is set to ignore a column" do
24
+ Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
25
+ assert Moargration.ignoring?(:samples, :f1)
26
+ assert !Moargration.ignoring?(:samples, :f2)
27
+ assert !Moargration.ignoring?(:other, :f1)
28
+ end
29
+
30
+ it "reads a table with multiple fields" do
31
+ Moargration.parse("table:f1,f2").must_equal("table" => %w( f1 f2 ))
32
+ end
33
+
34
+ it "reads multiple tables" do
35
+ Moargration.parse("t1:f1,f2 t2:f1").must_equal("t1" => %w( f1 f2 ), "t2" => %w( f1 ))
36
+ end
37
+
38
+ it "ignores tables without fields" do
39
+ Moargration.parse("t1:f1 t2 t3:f1").must_equal("t1" => %w( f1 ), "t3" => %w( f1 ))
40
+ end
41
+ end
42
+
22
43
  describe "hack_active_record" do
23
44
  it "hacks the model to ignore the specified columns" do
24
45
  Moargration.columns_to_ignore = { "samples" => %w( f1 ) }
@@ -1,3 +1,6 @@
1
+ require "bundler"
2
+ Bundler.require(:default, :test)
3
+
1
4
  require "minitest/spec"
2
5
  require "minitest/autorun"
3
6
  require "active_record"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moargration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helping you migrate, MOAR.
15
15
  email:
@@ -46,10 +46,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  version: '0'
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 1.8.22
49
+ rubygems_version: 1.8.25
50
50
  signing_key:
51
51
  specification_version: 3
52
52
  summary: To assist app developers with tricky database migrations
53
53
  test_files:
54
54
  - test/moargration_test.rb
55
55
  - test/test_helper.rb
56
+ has_rdoc: