rein 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rein/constraint/foreign_key.rb +5 -3
- data/lib/rein/constraint/numericality.rb +2 -3
- data/lib/rein/version.rb +1 -1
- metadata +3 -109
@@ -1,14 +1,16 @@
|
|
1
1
|
module RC
|
2
2
|
module ForeignKey
|
3
3
|
def add_foreign_key_constraint(referencing_table, referenced_table, options = {})
|
4
|
-
referencing_attribute = options[:referencing] || "#{referenced_table.to_s.singularize}_id"
|
5
|
-
referenced_attribute = "id"
|
6
|
-
constraint_name = options[:name] || "#{referencing_attribute}_fk"
|
4
|
+
referencing_attribute = options[:referencing] || "#{referenced_table.to_s.singularize}_id".to_sym
|
5
|
+
referenced_attribute = "id".to_sym
|
6
|
+
constraint_name = options[:name] || "#{referencing_attribute}_fk".to_sym
|
7
7
|
|
8
8
|
sql = "ALTER TABLE #{referencing_table} ADD CONSTRAINT #{constraint_name} FOREIGN KEY (#{referencing_attribute}) REFERENCES #{referenced_table} (#{referenced_attribute})"
|
9
9
|
sql << " ON DELETE #{referential_action(options[:on_delete])}" if options[:on_delete]
|
10
10
|
sql << " ON UPDATE #{referential_action(options[:on_update])}" if options[:on_update]
|
11
11
|
|
12
|
+
add_index(referencing_table, referencing_attribute) if options[:index] == true
|
13
|
+
|
12
14
|
execute(sql)
|
13
15
|
end
|
14
16
|
|
@@ -14,10 +14,9 @@ module RC
|
|
14
14
|
[attribute, operator, value].join(" ")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
conditions_sql = "(#{conditions_sql})" if conditions.length > 1
|
17
|
+
conditions = conditions.join(" AND ")
|
19
18
|
|
20
|
-
execute "ALTER TABLE #{table} ADD CONSTRAINT #{attribute} CHECK #{
|
19
|
+
execute "ALTER TABLE #{table} ADD CONSTRAINT #{attribute} CHECK (#{conditions})"
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
data/lib/rein/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Josh Bassett
|
@@ -19,6 +19,7 @@ default_executable:
|
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activesupport
|
22
|
+
prerelease: false
|
22
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
24
|
none: false
|
24
25
|
requirements:
|
@@ -31,113 +32,7 @@ dependencies:
|
|
31
32
|
- rc
|
32
33
|
version: 3.0.0.rc
|
33
34
|
type: :runtime
|
34
|
-
prerelease: false
|
35
35
|
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: bundler
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 0
|
46
|
-
- 0
|
47
|
-
version: 1.0.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: hirb
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
56
|
-
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
- 3
|
61
|
-
- 2
|
62
|
-
version: 0.3.2
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: rake
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - ~>
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
- 8
|
76
|
-
- 7
|
77
|
-
version: 0.8.7
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: *id004
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rcov
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
|
-
requirements:
|
86
|
-
- - ~>
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
- 9
|
91
|
-
- 8
|
92
|
-
version: 0.9.8
|
93
|
-
type: :development
|
94
|
-
prerelease: false
|
95
|
-
version_requirements: *id005
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: rspec
|
98
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
101
|
-
- - ~>
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
segments:
|
104
|
-
- 1
|
105
|
-
- 3
|
106
|
-
- 0
|
107
|
-
version: 1.3.0
|
108
|
-
type: :development
|
109
|
-
prerelease: false
|
110
|
-
version_requirements: *id006
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rr
|
113
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
|
-
requirements:
|
116
|
-
- - ~>
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
segments:
|
119
|
-
- 1
|
120
|
-
- 0
|
121
|
-
- 0
|
122
|
-
version: 1.0.0
|
123
|
-
type: :development
|
124
|
-
prerelease: false
|
125
|
-
version_requirements: *id007
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: wirble
|
128
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
|
-
requirements:
|
131
|
-
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
- 1
|
136
|
-
- 3
|
137
|
-
version: 0.1.3
|
138
|
-
type: :development
|
139
|
-
prerelease: false
|
140
|
-
version_requirements: *id008
|
141
36
|
description: Rein adds bunch of methods to your ActiveRecord migrations so you can easily tame your database.
|
142
37
|
email: josh.bassett@gmail.com
|
143
38
|
executables: []
|
@@ -168,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
63
|
requirements:
|
169
64
|
- - ">="
|
170
65
|
- !ruby/object:Gem::Version
|
171
|
-
hash: 1844054734367271197
|
172
66
|
segments:
|
173
67
|
- 0
|
174
68
|
version: "0"
|