mv-postgresql 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +235 -100
- data/lib/migration_validators/adapters/postgresql.rb +2 -2
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13c089d60aae49617aa26da0fe977a1908b03e3c
|
4
|
+
data.tar.gz: 08cc2f9ed8b940c4075f78db5af52459b81800bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b14170815495b1c873fde107ad3a441e967b78c815e46c9ec49848152373da3f0c56b994ca96d7bce6494c13088888eac6a1566f52eb2c5c3fe31e1f2d51fcfe
|
7
|
+
data.tar.gz: c08a261687f1d624d7d690737dfee64175a960e5abc693261c593ac39f4acceec48b87e8501d6acade946bffcd91b45065c4d554402fa3a1ea35b5fc885320ca
|
data/README.rdoc
CHANGED
@@ -1,151 +1,286 @@
|
|
1
|
-
|
1
|
+
# Introduction
|
2
2
|
|
3
3
|
mv-postgresql is the PostgreSQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
|
4
4
|
|
5
|
-
|
5
|
+
# Validators
|
6
6
|
|
7
|
-
|
7
|
+
### uniqueness
|
8
8
|
|
9
|
-
|
9
|
+
Examples:
|
10
10
|
|
11
|
-
|
11
|
+
validate uniqueness of the column 'column_name':
|
12
12
|
|
13
|
-
|
14
|
-
validate_column :table_name, :column_name,
|
15
|
-
|
13
|
+
```ruby
|
14
|
+
validate_column :table_name, :column_name, uniqueness: true
|
15
|
+
```
|
16
16
|
|
17
|
+
define validation as trigger with specified failure message:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
validate_column :table_name, :column_name,
|
21
|
+
uniqueness: { message: 'Error message', as: :trigger }
|
22
|
+
```
|
23
|
+
|
24
|
+
define validation as unique index:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
validate_column :table_name, :column_name, uniqueness: { as: :index }
|
28
|
+
```
|
29
|
+
|
30
|
+
all above are available in a create and change table blocks:
|
31
|
+
|
32
|
+
```ruby
|
17
33
|
create_table :table_name do |t|
|
18
|
-
t.string :column_name, :
|
34
|
+
t.string :column_name, validates: { uniqueness: true }
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
change :table_name do |t|
|
40
|
+
t.change :column_name, :string, :validates: { uniqueness: false }
|
19
41
|
end
|
42
|
+
```
|
20
43
|
|
21
44
|
Options:
|
22
45
|
|
23
|
-
message
|
24
|
-
index_name
|
25
|
-
on
|
26
|
-
create_tigger_name
|
27
|
-
update_tigger_name
|
28
|
-
allow_nil
|
29
|
-
allow_blank
|
30
|
-
as
|
46
|
+
* `:message` - text of the error message that will be shown if constraint violated. Ignored unless `:as == :trigger`
|
47
|
+
* `:index_name` - name of the index that will be created for validator. Ignored unless `:as == :index`
|
48
|
+
* `:on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value `:save`
|
49
|
+
* `:create_tigger_name` - name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
50
|
+
* `:update_tigger_name` - name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
51
|
+
* `:allow_nil` - ignore validation for nil values. Ignored unless `:as == :trigger`. Default value: `false`
|
52
|
+
* `:allow_blank` - ignore validation for blank values. Ignored unless `:as == :trigger`. Default value: `false`
|
53
|
+
* `:as` - defines the way how constraint will be implemented. Possible values: `[:index, :trigger]`. Default value: `:index`
|
31
54
|
|
32
|
-
|
55
|
+
### length
|
33
56
|
|
34
|
-
|
57
|
+
Examples:
|
35
58
|
|
36
|
-
|
59
|
+
```ruby
|
60
|
+
validate_column :table_name, :column_name,
|
61
|
+
length: { in: 5..8,
|
62
|
+
message: 'Wrong length message'}
|
63
|
+
```
|
37
64
|
|
38
|
-
|
39
|
-
validate_column :table_name, :column_name, :length => {:is => 3, :allow_nil => true}
|
40
|
-
validate_column :table_name, :column_name, :length => {:maximum => 3, :too_long => "Value is longer than 3 symbols"}
|
65
|
+
allow `NULL`:
|
41
66
|
|
42
|
-
|
67
|
+
```ruby
|
68
|
+
validate_column :table_name, :column_name,
|
69
|
+
length: { is: 3, allow_nil: true}
|
70
|
+
```
|
71
|
+
|
72
|
+
allow blank values:
|
43
73
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
message: message that should be shown if validation failed and specific message is not defined
|
50
|
-
too_long: message that will be shown if value longer than allowed. Ignored unless maximum value is defined
|
51
|
-
too_short: message that will be shown if value shorter than allowed. Ignored unless minimum value is defined
|
52
|
-
on: validation event. Possible values [:save, :update, :create]. Ignored unless :as == :trigger. Default value: :save
|
53
|
-
create_tigger_name: Name of the 'before insert' trigger that will be created if :as == :trigger && :on in [:save, :create]
|
54
|
-
update_tigger_name: Name of the 'before update' trigger that will be created if :as == :trigger && :on in [:save, :update]
|
55
|
-
allow_nil: ignore validation for nil values. Default value: false
|
56
|
-
allow_blank: ignore validation for blank values. Default value: false
|
57
|
-
as: defines the way how constraint will be implemented. Possible values: [:trigger, :check] Default value: :check
|
74
|
+
```ruby
|
75
|
+
validate_column :table_name, :column_name,
|
76
|
+
length: { maximum: 3,
|
77
|
+
too_long: 'Value is longer than 3 symbols' }
|
78
|
+
```
|
58
79
|
|
59
|
-
|
80
|
+
define constraint in trigger:
|
60
81
|
|
61
|
-
|
82
|
+
```ruby
|
83
|
+
validate_column :table_name, :column_name,
|
84
|
+
length: { maximum: 3,
|
85
|
+
as: :trigger,
|
86
|
+
too_long: 'Value is longer than 3 symbols' }
|
87
|
+
```
|
62
88
|
|
63
|
-
|
89
|
+
Options:
|
64
90
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
91
|
+
* `in` - range or array that length of the value should be contained in.
|
92
|
+
* `within` - synonym of `:in`
|
93
|
+
* `is` - exact length of the value
|
94
|
+
* `maximum` - maximum allowed length
|
95
|
+
* `minimum` - minimum allowed length
|
96
|
+
* `message` - message that should be shown if validation failed and specific message is not defined
|
97
|
+
* `too_long` - message that will be shown if value longer than allowed. Ignored unless maximum value is defined
|
98
|
+
* `too_short` - message that will be shown if value shorter than allowed. Ignored unless minimum value is defined
|
99
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
100
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
101
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
102
|
+
* `allow_nil` - ignore validation for nil values. Default value: `false`
|
103
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
104
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
|
105
|
+
|
106
|
+
### inclusion
|
107
|
+
|
108
|
+
Examples:
|
109
|
+
|
110
|
+
valid values array:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
validate_column :table_name, :column_name, inclusion: { in: [1, 2, 3] }
|
114
|
+
```
|
115
|
+
|
116
|
+
with failure message specified:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
validate_column :table_name, :column_name,
|
120
|
+
inclusion: { in: [1, 2, 3],
|
121
|
+
message: "Column 'column_name' should be equal to 1 or 2 or 3" }
|
122
|
+
```
|
123
|
+
|
124
|
+
make it as check constraint:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
validate_column :table_name, :column_name,
|
128
|
+
inclusion: { in: [1, 2, 3],
|
129
|
+
on: :update,
|
130
|
+
as: :check }
|
131
|
+
```
|
132
|
+
|
133
|
+
make it in trigger:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
validate_column :table_name, :column_name,
|
137
|
+
inclusion: { in: 1..3,
|
138
|
+
on: :create,
|
139
|
+
as: :trigger }
|
140
|
+
```
|
69
141
|
|
70
142
|
Options:
|
71
143
|
|
72
|
-
in
|
73
|
-
message
|
74
|
-
on
|
75
|
-
create_tigger_name
|
76
|
-
update_tigger_name
|
77
|
-
allow_nil
|
78
|
-
allow_blank
|
79
|
-
as
|
144
|
+
* `in` - range or array that column value should be contained in.
|
145
|
+
* `message` - message that should be shown if validation failed
|
146
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
147
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
148
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
149
|
+
* `allow_nil` - ignore validation for nil values. Default value: `false`
|
150
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
151
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
|
80
152
|
|
81
153
|
|
82
|
-
|
154
|
+
### exclusion
|
155
|
+
|
156
|
+
Examples:
|
157
|
+
|
158
|
+
exclude 1, 2, and 3:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
validate_column :table_name, :column_name, exclusion: { in: [1, 2, 3] }
|
162
|
+
```
|
163
|
+
|
164
|
+
the same with failure message:
|
83
165
|
|
84
|
-
|
166
|
+
```ruby
|
167
|
+
validate_column :table_name, :column_name,
|
168
|
+
exclusion: {
|
169
|
+
in: [1, 2, 3],
|
170
|
+
message: "Column 'column_name' should not be equal to 1 or 2 or 3" }
|
171
|
+
```
|
85
172
|
|
86
|
-
|
173
|
+
as check constraint:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
validate_column :table_name, :column_name,
|
177
|
+
exclusion: { in: [1, 2, 3],
|
178
|
+
on: :update,
|
179
|
+
as: :check }
|
180
|
+
```
|
181
|
+
|
182
|
+
as trigger:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
validate_column :table_name, :column_name,
|
186
|
+
exclusion: { in: 1..3,
|
187
|
+
on: :create,
|
188
|
+
as: :trigger }
|
189
|
+
```
|
87
190
|
|
88
|
-
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3]}
|
89
|
-
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3], :message => "Column 'column_name' should not be equal to 1 or 2 or 3"}
|
90
|
-
validate_column :table_name, :column_name, :exclusion => {:in => [1, 2, 3], :on => :update, :as => :check}
|
91
|
-
validate_column :table_name, :column_name, :exclusion => {:in => 1..3, :on => :create, :as => :trigger}
|
92
191
|
|
93
192
|
Options:
|
94
193
|
|
95
|
-
in
|
96
|
-
message
|
97
|
-
on
|
98
|
-
create_tigger_name
|
99
|
-
update_tigger_name
|
100
|
-
allow_nil
|
101
|
-
allow_blank
|
102
|
-
as
|
194
|
+
* `:in` - range or array that column value should NOT be contained in.
|
195
|
+
* `:message` - message that should be shown if validation failed
|
196
|
+
* `:on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
197
|
+
* `:create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
198
|
+
* `:update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
199
|
+
* `:allow_nil` - ignore validation for `nil` values. Default value: `false`
|
200
|
+
* `:allow_blank` - ignore validation for blank values. Default value: `false`
|
201
|
+
* `:as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
|
103
202
|
|
104
|
-
|
203
|
+
### presence
|
105
204
|
|
106
|
-
|
205
|
+
Examples:
|
107
206
|
|
108
|
-
|
207
|
+
```ruby
|
208
|
+
validate_column :table_name, :column_name, presence: true
|
209
|
+
```
|
109
210
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
validate_column :table_name, :column_name,
|
114
|
-
|
211
|
+
with failure message:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
validate_column :table_name, :column_name,
|
215
|
+
presence: { message: 'value should not be empty' }
|
216
|
+
```
|
217
|
+
|
218
|
+
implemented as trigger:
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
validate_column :table_name, :column_name,
|
222
|
+
presence: { message: 'value should not be empty',
|
223
|
+
as: :trigger }
|
224
|
+
```
|
225
|
+
|
226
|
+
check when record is inserted only:
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
validate_column :table_name, :column_name,
|
230
|
+
presence: { message: 'value should not be empty',
|
231
|
+
as: :trigger,
|
232
|
+
on: :create }
|
233
|
+
```
|
115
234
|
|
116
235
|
Options:
|
117
236
|
|
118
|
-
message
|
119
|
-
on
|
120
|
-
create_tigger_name
|
121
|
-
update_tigger_name
|
122
|
-
allow_nil
|
123
|
-
allow_blank
|
124
|
-
as
|
237
|
+
* `message` - message that should be shown if validation failed
|
238
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
239
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
240
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
241
|
+
* `allow_nil` - ignore validation for `nil` values. Default value: `false`
|
242
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
243
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
|
125
244
|
|
126
|
-
|
245
|
+
### format
|
127
246
|
|
128
|
-
|
247
|
+
Examples:
|
129
248
|
|
130
|
-
|
249
|
+
allows only values that contains 'word' inside:
|
131
250
|
|
132
|
-
|
133
|
-
validate_column :table_name, :column_name, :
|
134
|
-
|
135
|
-
|
251
|
+
```ruby
|
252
|
+
validate_column :table_name, :column_name, format: { with: /word/ }
|
253
|
+
```
|
254
|
+
|
255
|
+
with failure message:
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
validate_column :table_name, :column_name,
|
259
|
+
format: { with: /word/,
|
260
|
+
message: 'Column_name value should contain start word' }
|
261
|
+
```
|
262
|
+
|
263
|
+
implemented as trigger:
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
validate_column :table_name, :column_name,
|
267
|
+
format: { with: /word/,
|
268
|
+
message: 'Column_name value should contain start word',
|
269
|
+
as: :trigger }
|
270
|
+
```
|
136
271
|
|
137
272
|
Options:
|
138
273
|
|
139
|
-
with
|
140
|
-
message
|
141
|
-
on
|
142
|
-
create_tigger_name
|
143
|
-
update_tigger_name
|
144
|
-
allow_nil
|
145
|
-
allow_blank
|
146
|
-
as
|
274
|
+
* `with` - regular expression that column value should be matched to
|
275
|
+
* `message` - message that should be shown if validation failed
|
276
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
277
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
278
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
279
|
+
* `allow_nil` - ignore validation for `nil` values. Default value: `false`
|
280
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
281
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
|
147
282
|
|
148
|
-
|
283
|
+
## Contributing to mv-postgresql
|
149
284
|
|
150
285
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
151
286
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -155,7 +290,7 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
|
|
155
290
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
156
291
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
157
292
|
|
158
|
-
|
293
|
+
## Copyright
|
159
294
|
|
160
295
|
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
161
296
|
further details.
|
@@ -105,11 +105,11 @@ module MigrationValidators
|
|
105
105
|
end
|
106
106
|
|
107
107
|
|
108
|
-
route :
|
108
|
+
route :presence, :trigger do
|
109
109
|
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
110
110
|
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
111
111
|
end
|
112
|
-
route :
|
112
|
+
route :presence, :check, :to => :check, :default => true
|
113
113
|
|
114
114
|
route :inclusion, :trigger do
|
115
115
|
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valeriy Prokopchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.17'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mv-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
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: jeweler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '2.0'
|
55
55
|
description: Migration Validators project postgresql driver
|
56
56
|
email: vprokopchuk@gmail.com
|
57
57
|
executables: []
|
@@ -60,10 +60,10 @@ extra_rdoc_files:
|
|
60
60
|
- LICENSE.txt
|
61
61
|
- README.rdoc
|
62
62
|
files:
|
63
|
-
- lib/migration_validators/adapters/postgresql.rb
|
64
|
-
- lib/mv-postgresql.rb
|
65
63
|
- LICENSE.txt
|
66
64
|
- README.rdoc
|
65
|
+
- lib/migration_validators/adapters/postgresql.rb
|
66
|
+
- lib/mv-postgresql.rb
|
67
67
|
homepage: http://github.com/vprokopchuk256/mv-postgresql
|
68
68
|
licenses:
|
69
69
|
- MIT
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.4.2
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Migration Validators project postgresql driver
|