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 +4 -4
- data/README.md +1 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb +13 -17
- data/lib/schema_plus/foreign_keys/middleware/dumper.rb +2 -2
- data/lib/schema_plus/foreign_keys/version.rb +1 -1
- data/schema_plus_foreign_keys.gemspec +1 -1
- data/spec/schema_dumper_spec.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 414ce7516432fbe61314220f49b00d144a9f5af1
|
4
|
+
data.tar.gz: b8fdcfd8a82bc78627fb4c75229b38d25dd3d50e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
CHANGED
@@ -72,23 +72,19 @@ module SchemaPlus::ForeignKeys
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Dumps a definition of foreign key.
|
75
|
-
def to_dump
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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.
|
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.
|
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|
|
@@ -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
|
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"
|
data/spec/schema_dumper_spec.rb
CHANGED
@@ -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
|
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
|
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"
|
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.
|
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-
|
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
|
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
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: valuable
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|