schema_plus_foreign_keys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +21 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +200 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.base +4 -0
- data/gemfiles/activerecord-4.2.0/Gemfile.base +3 -0
- data/gemfiles/activerecord-4.2.0/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-4.2.0/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-4.2.0/Gemfile.sqlite3 +10 -0
- data/gemfiles/activerecord-4.2.1/Gemfile.base +3 -0
- data/gemfiles/activerecord-4.2.1/Gemfile.mysql2 +10 -0
- data/gemfiles/activerecord-4.2.1/Gemfile.postgresql +10 -0
- data/gemfiles/activerecord-4.2.1/Gemfile.sqlite3 +10 -0
- data/lib/schema_plus/foreign_keys.rb +78 -0
- data/lib/schema_plus/foreign_keys/active_record/base.rb +33 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb +168 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb +137 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/mysql2_adapter.rb +126 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb +89 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/sqlite3_adapter.rb +77 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/table_definition.rb +108 -0
- data/lib/schema_plus/foreign_keys/active_record/migration/command_recorder.rb +29 -0
- data/lib/schema_plus/foreign_keys/middleware/dumper.rb +88 -0
- data/lib/schema_plus/foreign_keys/middleware/migration.rb +147 -0
- data/lib/schema_plus/foreign_keys/middleware/model.rb +15 -0
- data/lib/schema_plus/foreign_keys/middleware/mysql.rb +20 -0
- data/lib/schema_plus/foreign_keys/middleware/sql.rb +27 -0
- data/lib/schema_plus/foreign_keys/version.rb +5 -0
- data/lib/schema_plus_foreign_keys.rb +1 -0
- data/schema_dev.yml +9 -0
- data/schema_plus_foreign_keys.gemspec +31 -0
- data/spec/deprecation_spec.rb +161 -0
- data/spec/foreign_key_definition_spec.rb +34 -0
- data/spec/foreign_key_spec.rb +207 -0
- data/spec/migration_spec.rb +570 -0
- data/spec/named_schemas_spec.rb +136 -0
- data/spec/schema_dumper_spec.rb +257 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/reference.rb +79 -0
- metadata +221 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
module SchemaPlus::Matchers
|
2
|
+
|
3
|
+
class Reference
|
4
|
+
def initialize(expected)
|
5
|
+
@column = @on_update = @on_delete = @deferrable = @name = @to_table = @primary_key = nil
|
6
|
+
unless expected.empty?
|
7
|
+
@to_table, @primary_key = Array(expected).map(&:to_s)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def matches?(model)
|
12
|
+
@model = model
|
13
|
+
if @to_table
|
14
|
+
@result = @model.foreign_keys.select do |fk|
|
15
|
+
fk.to_table == @to_table &&
|
16
|
+
@primary_key.blank? ? true : fk.primary_key == @primary_key
|
17
|
+
end
|
18
|
+
else
|
19
|
+
@result = @model.foreign_keys
|
20
|
+
end
|
21
|
+
@result.keep_if {|fk| Array.wrap(fk.column) == @column } if @column
|
22
|
+
@result.keep_if {|fk| fk.on_update == @on_update } if @on_update
|
23
|
+
@result.keep_if {|fk| fk.on_delete == @on_delete } if @on_delete
|
24
|
+
@result.keep_if {|fk| fk.deferrable == @deferrable } if @deferrable
|
25
|
+
@result.keep_if {|fk| fk.name == @name } if @name
|
26
|
+
!@result.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def failure_message(should_not = false)
|
30
|
+
target_column = @column.present? ? "(#{Array.wrap(@column).join(', ')})" : ""
|
31
|
+
destinantion_column = @to_table ? "#{@to_table}(#{Array.wrap(@primary_key).join(', ')})" : "anything"
|
32
|
+
invert = should_not ? 'not' : ''
|
33
|
+
msg = "Expected #{@model.table_name}#{target_column} to #{invert} reference #{destinantion_column}"
|
34
|
+
with = []
|
35
|
+
with << "on_update=#{@on_update.inspect}" if @on_update
|
36
|
+
with << "on_delete=#{@on_delete.inspect}" if @on_delete
|
37
|
+
with << "deferrable=#{@deferrable.inspect}" if @deferrable
|
38
|
+
with << "name=#{@name.inspect}" if @name
|
39
|
+
msg += " with #{with.join(" and ")}" if with.any?
|
40
|
+
msg
|
41
|
+
end
|
42
|
+
|
43
|
+
def failure_message_when_negated
|
44
|
+
failure_message(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
def on(*column)
|
48
|
+
@column = column.collect(&:to_s)
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def on_update(action)
|
53
|
+
@on_update = action
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def deferrable(action)
|
58
|
+
@deferrable = action
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_delete(action)
|
63
|
+
@on_delete = action
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def with_name(action)
|
68
|
+
@name = action
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def reference(*expect)
|
75
|
+
Reference.new(expect)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
metadata
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schema_plus_foreign_keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ronen barzel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: schema_plus_core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: valuable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: schema_dev
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov-gem-profile
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: 'Extended support for foreign key constraints in ActiveRecord, including:
|
140
|
+
definition as column attribute; deferrable; and SQLite3 support; cleaner dumps;
|
141
|
+
and more!'
|
142
|
+
email:
|
143
|
+
- ronen@barzel.org
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".travis.yml"
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- gemfiles/Gemfile.base
|
155
|
+
- gemfiles/activerecord-4.2.0/Gemfile.base
|
156
|
+
- gemfiles/activerecord-4.2.0/Gemfile.mysql2
|
157
|
+
- gemfiles/activerecord-4.2.0/Gemfile.postgresql
|
158
|
+
- gemfiles/activerecord-4.2.0/Gemfile.sqlite3
|
159
|
+
- gemfiles/activerecord-4.2.1/Gemfile.base
|
160
|
+
- gemfiles/activerecord-4.2.1/Gemfile.mysql2
|
161
|
+
- gemfiles/activerecord-4.2.1/Gemfile.postgresql
|
162
|
+
- gemfiles/activerecord-4.2.1/Gemfile.sqlite3
|
163
|
+
- lib/schema_plus/foreign_keys.rb
|
164
|
+
- lib/schema_plus/foreign_keys/active_record/base.rb
|
165
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb
|
166
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
|
167
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/mysql2_adapter.rb
|
168
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb
|
169
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/sqlite3_adapter.rb
|
170
|
+
- lib/schema_plus/foreign_keys/active_record/connection_adapters/table_definition.rb
|
171
|
+
- lib/schema_plus/foreign_keys/active_record/migration/command_recorder.rb
|
172
|
+
- lib/schema_plus/foreign_keys/middleware/dumper.rb
|
173
|
+
- lib/schema_plus/foreign_keys/middleware/migration.rb
|
174
|
+
- lib/schema_plus/foreign_keys/middleware/model.rb
|
175
|
+
- lib/schema_plus/foreign_keys/middleware/mysql.rb
|
176
|
+
- lib/schema_plus/foreign_keys/middleware/sql.rb
|
177
|
+
- lib/schema_plus/foreign_keys/version.rb
|
178
|
+
- lib/schema_plus_foreign_keys.rb
|
179
|
+
- schema_dev.yml
|
180
|
+
- schema_plus_foreign_keys.gemspec
|
181
|
+
- spec/deprecation_spec.rb
|
182
|
+
- spec/foreign_key_definition_spec.rb
|
183
|
+
- spec/foreign_key_spec.rb
|
184
|
+
- spec/migration_spec.rb
|
185
|
+
- spec/named_schemas_spec.rb
|
186
|
+
- spec/schema_dumper_spec.rb
|
187
|
+
- spec/spec_helper.rb
|
188
|
+
- spec/support/reference.rb
|
189
|
+
homepage: https://github.com/SchemaPlus/schema_plus_foreign_keys
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.2.2
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Extended support for foreign key constraints in ActiveRecord
|
213
|
+
test_files:
|
214
|
+
- spec/deprecation_spec.rb
|
215
|
+
- spec/foreign_key_definition_spec.rb
|
216
|
+
- spec/foreign_key_spec.rb
|
217
|
+
- spec/migration_spec.rb
|
218
|
+
- spec/named_schemas_spec.rb
|
219
|
+
- spec/schema_dumper_spec.rb
|
220
|
+
- spec/spec_helper.rb
|
221
|
+
- spec/support/reference.rb
|