schema_plus_foreign_keys 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 161f26b7a83ca42ce9fa30a6132447bbf1ca000e
4
- data.tar.gz: 1393641fbdd4843d42558e12cf97d4792a9b3d18
3
+ metadata.gz: 414ce7516432fbe61314220f49b00d144a9f5af1
4
+ data.tar.gz: b8fdcfd8a82bc78627fb4c75229b38d25dd3d50e
5
5
  SHA512:
6
- metadata.gz: 9b0d962d24372f0fa68a9dd6775cb930d929a3dea94a438fc689a52628b1e0d5c24eefe1aefab160137d0355ac230cf15742e27cbce8186658a96e352ad59d35
7
- data.tar.gz: 2db8b15e9be4c76bdef4b356882d00abce638585fc613c258ab8d77706ddf9d41dfdf4b455b23b5e738607687e25f13498e44a606a215a807d5a9bf3abd593d6
6
+ metadata.gz: 96831479e0e83ff566c945c38c6639412e6250a16a4dd02ec37505d2ba53d30025fde92330fb1af9f848ff97423aa448c552158902d36e9ab37f45d2606e854e
7
+ data.tar.gz: 8cf9d39ac9a408c0e319cdc9b56a6f8506c842161074ff6477671523badb6341645d3adfc7040f6f02ff57d35c27fea4e319a0dbfdf32addd68fc6f01f3ab710
data/README.md CHANGED
@@ -150,6 +150,7 @@ SchemaPlus::ForeignKeys is tested on:
150
150
 
151
151
  ## History
152
152
 
153
+ * 0.1.4 - Upgrade schema_plus_core dependency
153
154
  * 0.1.3 - Support aciverecord 4.2.6. Thanks to [@btsuhako](https://github.com/SchemaPlus/schema_plus_foreign_keys/issues?q=is%3Apr+is%3Aopen+author%3Abtsuhako) and [@dholdren](https://github.com/SchemaPlus/schema_plus_foreign_keys/issues?q=is%3Apr+is%3Aopen+author%3Adholdren)
154
155
  * 0.1.2 - Handle very long names
155
156
  * 0.1.1 - Cleanup; use (new) core Migration::RenameTable stack rather than monkey patching.
@@ -72,23 +72,19 @@ module SchemaPlus::ForeignKeys
72
72
  end
73
73
 
74
74
  # Dumps a definition of foreign key.
75
- def to_dump(column: nil)
76
- dump = case
77
- when column then "foreign_key: {references:"
78
- else "add_foreign_key #{from_table.inspect},"
79
- end
80
- dump << " #{to_table.inspect}"
81
-
82
- val_or_array = -> val { val.is_a?(Array) ? "[#{val.map(&:inspect).join(', ')}]" : val.inspect }
83
-
84
- dump << ", column: #{val_or_array.call self.column}" unless column
85
- dump << ", primary_key: #{val_or_array.call self.primary_key}" if custom_primary_key?
86
- dump << ", name: #{name.inspect}" if name
87
- dump << ", on_update: #{on_update.inspect}" if on_update
88
- dump << ", on_delete: #{on_delete.inspect}" if on_delete
89
- dump << ", deferrable: #{deferrable.inspect}" if deferrable
90
- dump << "}" if column
91
- dump
75
+ def to_dump
76
+ opts = {column: self.column}.merge options_for_dump
77
+ dump = "add_foreign_key #{from_table.inspect}, #{to_table.inspect}, #{opts.to_s.sub(/^{(.*)}$/, '\1')}"
78
+ end
79
+
80
+ def options_for_dump
81
+ opts = {}
82
+ opts[:primary_key] = self.primary_key if custom_primary_key?
83
+ opts[:name] = name if name
84
+ opts[:on_update] = on_update if on_update
85
+ opts[:on_delete] = on_delete if on_delete
86
+ opts[:deferrable] = deferrable if deferrable
87
+ opts
92
88
  end
93
89
 
94
90
  def to_sql
@@ -67,11 +67,11 @@ module SchemaPlus::ForeignKeys
67
67
  dumped = {}
68
68
  env.table.columns.each do |column|
69
69
  if (foreign_key = env.dump.data.inline_fks[env.table.name].find(&its.column.to_s == column.name))
70
- column.add_option foreign_key.to_dump(column: true)
70
+ column.options[:foreign_key] = {references: foreign_key.to_table}.merge foreign_key.options_for_dump
71
71
  dumped[foreign_key] = true
72
72
  end
73
73
  if (foreign_key = env.dump.data.backref_fks.values.flatten.find{|fk| fk.from_table.to_s == env.table.name && fk.column.to_s == column.name})
74
- column.add_comment "foreign key references #{foreign_key.to_table.inspect} (below)"
74
+ column.comments << "foreign key references #{foreign_key.to_table.inspect} (below)"
75
75
  end
76
76
  end
77
77
  env.table.trailer += env.dump.data.inline_fks[env.table.name].map { |foreign_key|
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module ForeignKeys
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency "activerecord", "~> 4.2"
22
- gem.add_dependency "schema_plus_core", "~> 0.5"
22
+ gem.add_dependency "schema_plus_core", "~> 1.0"
23
23
  gem.add_dependency "valuable"
24
24
 
25
25
  gem.add_development_dependency "bundler", "~> 1.7"
@@ -59,13 +59,13 @@ describe "Schema dump" do
59
59
 
60
60
  it "should include foreign_key name" do
61
61
  with_foreign_key Post, :user_id, :users, :id, :name => "yippee" do
62
- expect(dump_posts).to match(/user_id.*foreign_key.*users.*name: "yippee"/)
62
+ expect(dump_posts).to match(/user_id.*foreign_key.*users.*:name=>"yippee"/)
63
63
  end
64
64
  end
65
65
 
66
66
  it "should respect foreign key's primary key" do
67
67
  with_foreign_key Post, :user_id, :users, :first_post_id do
68
- expect(dump_posts).to match(%r{t.integer\s+"user_id".*foreign_key.*primary_key: "first_post_id"})
68
+ expect(dump_posts).to match(%r{t.integer\s+"user_id".*foreign_key.*:primary_key=>"first_post_id"})
69
69
  end
70
70
  end
71
71
 
@@ -107,7 +107,7 @@ describe "Schema dump" do
107
107
 
108
108
  it "should include foreign_key options" do
109
109
  with_foreign_key Post, :user_id, :users, :id, :on_update => :cascade, :on_delete => :nullify do
110
- expect(dump_posts).to match(%q[t.integer\s*"user_id",.*foreign_key: {references: "users", name: "fk_posts_user_id", on_update: :cascade, on_delete: :nullify}])
110
+ expect(dump_posts).to match(%q[t.integer\s*"user_id",.*:foreign_key=>{:references=>"users", :name=>"fk_posts_user_id", :on_update=>:cascade, :on_delete=>:nullify}])
111
111
  end
112
112
  end
113
113
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus_foreign_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.5'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.5'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: valuable
43
43
  requirement: !ruby/object:Gem::Requirement