mv-mysql 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +347 -176
- data/lib/mv-mysql.rb +10 -0
- data/lib/mv/mysql/validation/mysql_error_message_restrictions.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad87072c466331a2cc04a715c63f6fe32449162a
|
4
|
+
data.tar.gz: 3c0e3915a9e967b58ce49425444b985f4aef2cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd8f63199d84fe2fda8881f660cce276fc22cadd93eba4ac555dd1e7425b2c790fcc1bb6883ef48eaa2a03a3fd35eba6c955b4404a0a36cc88ae25e98b802637
|
7
|
+
data.tar.gz: d156d70cede830cfd14342e912b396e2a986d99d078582067f49a906ae6513e563e5fb9d058097f0f6a17926d8cbd1fe1b5eb4eee903a23d6e8c042d7bf078ee
|
data/README.md
CHANGED
@@ -2,11 +2,23 @@
|
|
2
2
|
[![Coverage Status](https://coveralls.io/repos/vprokopchuk256/mv-mysql/badge.png?branch=master)](https://coveralls.io/r/vprokopchuk256/mv-mysql?branch=master)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mv-mysql.svg)](http://badge.fury.io/rb/mv-mysql)
|
4
4
|
|
5
|
-
#
|
5
|
+
# `Migration Validators` project. MySQL driver.
|
6
6
|
|
7
|
-
|
7
|
+
Define validations directly in DB as MySQL constraints and integrate them into your model transparently. See [mv-core](https://github.com/vprokopchuk256/mv-core) for details. There you will be able to review high level project information. Below you can see details of the migration validations that are supported by MySQL driver.
|
8
8
|
|
9
|
-
#
|
9
|
+
#Table Of Contents
|
10
|
+
* [Validations](#validations)
|
11
|
+
* [uniqueness](#uniqueness)
|
12
|
+
* [length](#length)
|
13
|
+
* [inclusion](#inclusion)
|
14
|
+
* [exclusion](#exclusion)
|
15
|
+
* [presence](#presence)
|
16
|
+
* [absence](#absence)
|
17
|
+
* [custom](#custom)
|
18
|
+
* [Version History](#version history)
|
19
|
+
* [Contributing](#contributing)
|
20
|
+
|
21
|
+
# Validations
|
10
22
|
|
11
23
|
### uniqueness
|
12
24
|
|
@@ -15,41 +27,71 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
15
27
|
validate uniqueness of the column 'column_name':
|
16
28
|
|
17
29
|
```ruby
|
18
|
-
|
30
|
+
def up
|
31
|
+
validates :table_name, :column_name, uniqueness: true
|
32
|
+
end
|
33
|
+
|
34
|
+
def down
|
35
|
+
validates :table_name, :column_name, uniqueness: false
|
36
|
+
end
|
19
37
|
```
|
20
38
|
|
21
39
|
define validation as trigger with specified failure message:
|
22
40
|
|
23
41
|
```ruby
|
24
|
-
|
25
|
-
|
42
|
+
def up
|
43
|
+
validates :table_name, :column_name,
|
44
|
+
uniqueness: { message: 'Error message', as: :trigger }
|
45
|
+
end
|
46
|
+
|
47
|
+
def down
|
48
|
+
validates :table_name, :column_name, uniqueness: false
|
49
|
+
end
|
26
50
|
```
|
27
51
|
|
28
52
|
define validation as unique index:
|
29
53
|
|
30
54
|
```ruby
|
31
|
-
|
55
|
+
def up
|
56
|
+
validates :table_name, :column_name, uniqueness: { as: :index }
|
57
|
+
end
|
58
|
+
|
59
|
+
def down
|
60
|
+
validates :table_name, :column_name, uniqueness: false
|
61
|
+
end
|
32
62
|
```
|
33
63
|
|
34
64
|
all above are available in a create and change table blocks:
|
35
65
|
|
36
66
|
```ruby
|
37
|
-
|
38
|
-
|
67
|
+
def change
|
68
|
+
create_table :table_name do |t|
|
69
|
+
t.string :column_name, validates: { uniqueness: true }
|
70
|
+
end
|
39
71
|
end
|
40
72
|
```
|
41
73
|
|
42
74
|
```ruby
|
43
|
-
|
44
|
-
|
75
|
+
def up
|
76
|
+
change :table_name do |t|
|
77
|
+
t.change :column_name, :string, :validates: { uniqueness: true }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def down
|
82
|
+
change :table_name do |t|
|
83
|
+
t.change :column_name, :string, :validates: { uniqueness: false }
|
84
|
+
end
|
45
85
|
end
|
46
86
|
```
|
47
87
|
|
48
88
|
simplifications (version >= 2.1 is required):
|
49
89
|
|
50
90
|
```ruby
|
51
|
-
|
52
|
-
|
91
|
+
def change
|
92
|
+
create_table :table_name do |t|
|
93
|
+
t.string :column_name, uniqueness: true
|
94
|
+
end
|
53
95
|
end
|
54
96
|
```
|
55
97
|
|
@@ -71,49 +113,79 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
71
113
|
column value length should be more than 4 symbols and less than 9. Otherwise 'Wrong length message' error will be raised:
|
72
114
|
|
73
115
|
```ruby
|
74
|
-
|
75
|
-
|
76
|
-
|
116
|
+
def up
|
117
|
+
validates :table_name, :column_name,
|
118
|
+
length: { in: 5..8,
|
119
|
+
message: 'Wrong length message' }
|
120
|
+
end
|
121
|
+
|
122
|
+
def down
|
123
|
+
validates :table_name, :column_name, length: false
|
124
|
+
end
|
77
125
|
```
|
78
126
|
|
79
127
|
allow `NULL`:
|
80
128
|
|
81
129
|
```ruby
|
82
|
-
|
83
|
-
|
130
|
+
def up
|
131
|
+
validates :table_name, :column_name,
|
132
|
+
length: { is: 3, allow_nil: true}
|
133
|
+
end
|
134
|
+
|
135
|
+
def down
|
136
|
+
validates :table_name, :column_name, length: false
|
137
|
+
end
|
84
138
|
```
|
85
139
|
|
86
140
|
allow blank values:
|
87
141
|
|
88
142
|
```ruby
|
89
|
-
|
90
|
-
|
91
|
-
|
143
|
+
def up
|
144
|
+
validates :table_name, :column_name,
|
145
|
+
length: { maximum: 3,
|
146
|
+
too_long: 'Value is longer than 3 symbols' }
|
147
|
+
end
|
148
|
+
|
149
|
+
def down
|
150
|
+
validates :table_name, :column_name, length: false
|
151
|
+
end
|
92
152
|
```
|
93
153
|
|
94
154
|
all above are available in a create and change table blocks:
|
95
155
|
|
96
156
|
```ruby
|
97
|
-
|
98
|
-
|
157
|
+
def change
|
158
|
+
create_table :table_name do |t|
|
159
|
+
t.string :column_name, validates: { length: { is: 3, allow_nil: true} }
|
160
|
+
end
|
99
161
|
end
|
100
162
|
```
|
101
163
|
|
102
164
|
```ruby
|
103
|
-
|
104
|
-
|
165
|
+
def up
|
166
|
+
change :table_name do |t|
|
167
|
+
t.change :column_name, :string, validates: { length: { is: 3 } }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def down
|
172
|
+
change :table_name do |t|
|
173
|
+
t.change :column_name, :string, validates: { length: false }
|
174
|
+
end
|
105
175
|
end
|
106
176
|
```
|
107
177
|
|
108
178
|
simplifications (version >= 2.1 is required):
|
109
179
|
|
110
180
|
```ruby
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
181
|
+
def change
|
182
|
+
create_table :table_name do |t|
|
183
|
+
t.string :string_3, length: 3
|
184
|
+
t.string :string_from_1_to_3, length: 1..3,
|
185
|
+
t.string :string_1_or_3, length: [1, 3]
|
186
|
+
t.string :string_4, validates: { length: 4 }
|
187
|
+
t.string :string_4_in_trigger: length: { is: 4, as: :trigger }
|
188
|
+
end
|
117
189
|
end
|
118
190
|
```
|
119
191
|
|
@@ -138,44 +210,66 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
138
210
|
|
139
211
|
Examples:
|
140
212
|
|
141
|
-
Examples:
|
142
|
-
|
143
213
|
valid values array:
|
144
214
|
|
145
215
|
```ruby
|
146
|
-
|
216
|
+
def up
|
217
|
+
validates :table_name, :column_name, inclusion: { in: [1, 2, 3] }
|
218
|
+
end
|
219
|
+
|
220
|
+
def up
|
221
|
+
validates :table_name, :column_name, inclusion: false
|
222
|
+
end
|
147
223
|
```
|
148
224
|
|
149
225
|
with failure message specified:
|
150
226
|
|
151
227
|
```ruby
|
228
|
+
def up
|
152
229
|
validates :table_name, :column_name,
|
153
|
-
|
154
|
-
|
230
|
+
inclusion: { in: [1, 2, 3],
|
231
|
+
message: "Column value should be equal to 1 or 2 or 3" }
|
232
|
+
end
|
233
|
+
|
234
|
+
def down
|
235
|
+
validates :table_name, :column_name, inclusion: false
|
236
|
+
end
|
155
237
|
```
|
156
238
|
|
157
239
|
all above are available in a create and change table blocks:
|
158
240
|
|
159
241
|
```ruby
|
160
|
-
|
161
|
-
|
242
|
+
def change
|
243
|
+
create_table :table_name do |t|
|
244
|
+
t.integer :column_name, validates: { inclusion: { in: 1..3 } }
|
245
|
+
end
|
162
246
|
end
|
163
247
|
```
|
164
248
|
|
165
249
|
```ruby
|
166
|
-
|
167
|
-
|
250
|
+
def up
|
251
|
+
change :table_name do |t|
|
252
|
+
t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def down
|
257
|
+
change :table_name do |t|
|
258
|
+
t.change :column_name, :integer, validates: { inclusion: false }
|
259
|
+
end
|
168
260
|
end
|
169
261
|
```
|
170
262
|
|
171
263
|
simplifications (version >= 2.1 is required):
|
172
264
|
|
173
265
|
```ruby
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
266
|
+
def change
|
267
|
+
create_table :table_name do |t|
|
268
|
+
t.string :str_or_str_1, inclusion: ['str', 'str1']
|
269
|
+
t.string :from_str_to_str_1, inclusion: 'str'..'str1'
|
270
|
+
t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
|
271
|
+
as: :trigger}
|
272
|
+
end
|
179
273
|
end
|
180
274
|
```
|
181
275
|
|
@@ -198,40 +292,64 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
198
292
|
exclude 1, 2, and 3:
|
199
293
|
|
200
294
|
```ruby
|
201
|
-
|
295
|
+
def up
|
296
|
+
validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
|
297
|
+
end
|
298
|
+
|
299
|
+
def down
|
300
|
+
validates :table_name, :column_name, exclusion: false
|
301
|
+
end
|
202
302
|
```
|
203
303
|
|
204
304
|
the same with failure message:
|
205
305
|
|
206
306
|
```ruby
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
307
|
+
def up
|
308
|
+
validates :table_name, :column_name,
|
309
|
+
exclusion: {
|
310
|
+
in: [1, 2, 3],
|
311
|
+
message: "Column value should not be equal to 1 or 2 or 3" }
|
312
|
+
end
|
313
|
+
|
314
|
+
def down
|
315
|
+
validates :table_name, :column_name, exclusion: false
|
316
|
+
end
|
211
317
|
```
|
212
318
|
|
213
319
|
all above are available in a create and change table blocks:
|
214
320
|
|
215
321
|
```ruby
|
216
|
-
|
217
|
-
|
322
|
+
def change
|
323
|
+
create_table :table_name do |t|
|
324
|
+
t.integer :column_name, validates: { exclusion: { in: 1..3 } }
|
325
|
+
end
|
218
326
|
end
|
219
327
|
```
|
220
328
|
|
221
329
|
```ruby
|
222
|
-
|
223
|
-
|
330
|
+
def up
|
331
|
+
change :table_name do |t|
|
332
|
+
t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
def down
|
337
|
+
change :table_name do |t|
|
338
|
+
t.change :column_name, :integer, validates: { exclusion: false }
|
339
|
+
end
|
224
340
|
end
|
225
341
|
```
|
226
342
|
|
227
343
|
simplifications (version >= 2.1 is required):
|
228
344
|
|
229
345
|
```ruby
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
346
|
+
def change
|
347
|
+
create_table :table_name do |t|
|
348
|
+
t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
|
349
|
+
t.string :from_str_to_str_1, exclusion: 'str'..'str1'
|
350
|
+
t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
|
351
|
+
as: :trigger}
|
352
|
+
end
|
235
353
|
end
|
236
354
|
```
|
237
355
|
|
@@ -251,149 +369,261 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
251
369
|
Examples:
|
252
370
|
|
253
371
|
```ruby
|
254
|
-
|
372
|
+
def up
|
373
|
+
validates :table_name, :column_name, presence: true
|
374
|
+
end
|
375
|
+
|
376
|
+
def down
|
377
|
+
validates :table_name, :column_name, presence: false
|
378
|
+
end
|
255
379
|
```
|
256
380
|
|
257
381
|
with failure message:
|
258
382
|
|
259
383
|
```ruby
|
260
|
-
|
261
|
-
|
384
|
+
def up
|
385
|
+
validates :table_name, :column_name,
|
386
|
+
presence: { message: 'value should not be empty' }
|
387
|
+
end
|
388
|
+
|
389
|
+
def down
|
390
|
+
validates :table_name, :column_name, presence: false
|
391
|
+
end
|
262
392
|
```
|
263
393
|
|
264
394
|
check when record is inserted only:
|
265
395
|
|
266
396
|
```ruby
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
397
|
+
def up
|
398
|
+
validates :table_name, :column_name,
|
399
|
+
presence: { message: 'value should not be empty',
|
400
|
+
as: :trigger,
|
401
|
+
on: :create }
|
402
|
+
end
|
403
|
+
|
404
|
+
def down
|
405
|
+
validates :table_name, :column_name, presence: false
|
406
|
+
end
|
271
407
|
```
|
272
408
|
|
273
409
|
all above are available in a create and change table blocks:
|
274
410
|
|
275
411
|
```ruby
|
276
|
-
|
277
|
-
|
412
|
+
def change
|
413
|
+
create_table :table_name do |t|
|
414
|
+
t.string :column_name, validates: { presence: true }
|
415
|
+
end
|
278
416
|
end
|
279
417
|
```
|
280
418
|
|
281
419
|
```ruby
|
282
|
-
|
283
|
-
|
420
|
+
def up
|
421
|
+
change :table_name do |t|
|
422
|
+
t.change :column_name, :string, validates: { presence: true }
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
def down
|
427
|
+
change :table_name do |t|
|
428
|
+
t.change :column_name, :string, validates: false
|
429
|
+
end
|
284
430
|
end
|
285
431
|
```
|
286
432
|
|
287
433
|
simplifications (version >= 2.1 is required):
|
288
434
|
|
289
435
|
```ruby
|
290
|
-
|
291
|
-
|
292
|
-
|
436
|
+
def change
|
437
|
+
create_table :table_name do |t|
|
438
|
+
t.string :presence_in_check, presence: true
|
439
|
+
t.string :presence_in_trigger, presence: { as: :trigger, on: :create }
|
440
|
+
end
|
293
441
|
end
|
294
442
|
```
|
295
443
|
|
444
|
+
Options:
|
445
|
+
|
446
|
+
* `message` - message that should be shown if validation failed
|
447
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
448
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
449
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
450
|
+
* `allow_nil` - ignore validation for `nil` values. Default value: `false`
|
451
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
452
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
|
453
|
+
|
296
454
|
### absence
|
297
455
|
|
298
456
|
Examples:
|
299
457
|
|
300
458
|
```ruby
|
301
|
-
|
459
|
+
def up
|
460
|
+
validates :table_name, :column_name, absence: true
|
461
|
+
end
|
462
|
+
|
463
|
+
def down
|
464
|
+
validates :table_name, :column_name, absence: false
|
465
|
+
end
|
302
466
|
```
|
303
467
|
|
304
468
|
with failure message:
|
305
469
|
|
306
470
|
```ruby
|
307
|
-
|
308
|
-
|
471
|
+
def up
|
472
|
+
validates :table_name, :column_name,
|
473
|
+
absence: { message: 'value should be empty' }
|
474
|
+
end
|
475
|
+
|
476
|
+
def down
|
477
|
+
validates :table_name, :column_name, absence: false
|
478
|
+
end
|
309
479
|
```
|
310
480
|
|
311
481
|
check when record is inserted only:
|
312
482
|
|
313
483
|
```ruby
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
484
|
+
def up
|
485
|
+
validates :table_name, :column_name,
|
486
|
+
absence: { message: 'value should be empty',
|
487
|
+
as: :trigger,
|
488
|
+
on: :create }
|
489
|
+
end
|
490
|
+
|
491
|
+
def down
|
492
|
+
validates :table_name, :column_name, absence: false
|
493
|
+
end
|
318
494
|
```
|
319
495
|
|
320
496
|
all above are available in a create and change table blocks:
|
321
497
|
|
322
498
|
```ruby
|
323
|
-
|
324
|
-
|
499
|
+
def change
|
500
|
+
create_table :table_name do |t|
|
501
|
+
t.string :column_name, validates: { absence: true }
|
502
|
+
end
|
325
503
|
end
|
326
504
|
```
|
327
505
|
|
328
506
|
```ruby
|
329
|
-
|
330
|
-
|
507
|
+
def up
|
508
|
+
change :table_name do |t|
|
509
|
+
t.change :column_name, :string, validates: { absence: true }
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
def down
|
514
|
+
change :table_name do |t|
|
515
|
+
t.change :column_name, :string, validates: { absence: false }
|
516
|
+
end
|
331
517
|
end
|
332
518
|
```
|
333
519
|
|
334
520
|
simplifications (version >= 2.1 is required):
|
335
521
|
|
336
522
|
```ruby
|
337
|
-
|
338
|
-
|
339
|
-
|
523
|
+
def change
|
524
|
+
create_table :table_name do |t|
|
525
|
+
t.string :absence_in_check, absence: true
|
526
|
+
t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
|
527
|
+
end
|
340
528
|
end
|
341
529
|
```
|
342
530
|
|
343
|
-
|
531
|
+
Options:
|
532
|
+
|
533
|
+
* `message` - message that should be shown if validation failed
|
534
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
535
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
536
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
537
|
+
* `allow_nil` - ignore validation for `nil` values. Default value: `true`
|
538
|
+
* `allow_blank` - ignore validation for blank values. Default value: `true`
|
539
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
|
540
|
+
|
541
|
+
### custom
|
542
|
+
|
543
|
+
(version >= 2.1 is required)
|
344
544
|
|
345
545
|
Examples:
|
346
546
|
|
347
547
|
allows only values that equals 'word' when trimmed:
|
348
548
|
|
349
549
|
```ruby
|
350
|
-
|
351
|
-
|
550
|
+
def up
|
551
|
+
validates :table_name, :column_name,
|
552
|
+
custom: { statement: "TRIM({column_name}) = 'word'" }
|
553
|
+
end
|
554
|
+
|
555
|
+
def down
|
556
|
+
validates :table_name, :column_name, custom: false
|
557
|
+
end
|
352
558
|
```
|
353
559
|
|
354
560
|
with failure message:
|
355
561
|
|
356
562
|
```ruby
|
357
|
-
|
358
|
-
|
359
|
-
|
563
|
+
def up
|
564
|
+
validates :table_name, :column_name,
|
565
|
+
custom: { statement: "TRIM({column_name}) = 'word'",
|
566
|
+
message: 'Column_name value should contain start word' }
|
567
|
+
end
|
568
|
+
|
569
|
+
def down
|
570
|
+
validates :table_name, :column_name, custom: false
|
571
|
+
end
|
360
572
|
```
|
361
573
|
|
362
574
|
implemented as trigger on insert event:
|
363
575
|
|
364
576
|
```ruby
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
577
|
+
def up
|
578
|
+
validates :table_name, :column_name,
|
579
|
+
custom: { statement: "TRIM({column_name}) = 'word'",
|
580
|
+
message: 'Column_name value should contain start word',
|
581
|
+
as: :trigger,
|
582
|
+
on: :create }
|
583
|
+
end
|
584
|
+
|
585
|
+
def down
|
586
|
+
validates :table_name, :column_name, custom: false
|
587
|
+
end
|
370
588
|
```
|
371
589
|
|
372
590
|
all above are available in a create and change table blocks:
|
373
591
|
|
374
592
|
```ruby
|
375
|
-
|
376
|
-
|
593
|
+
def change
|
594
|
+
create_table :table_name do |t|
|
595
|
+
t.string :column_name,
|
377
596
|
validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
|
597
|
+
end
|
378
598
|
end
|
379
599
|
```
|
380
600
|
|
381
601
|
```ruby
|
382
|
-
|
383
|
-
|
602
|
+
def up
|
603
|
+
change :table_name do |t|
|
604
|
+
t.change :column_name, :string,
|
384
605
|
validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
def down
|
610
|
+
change :table_name do |t|
|
611
|
+
t.change :column_name, :string, validates: { custom: false }
|
612
|
+
end
|
385
613
|
end
|
386
614
|
```
|
387
615
|
|
388
616
|
simplifications (version >= 2.1 is required):
|
389
617
|
|
390
618
|
```ruby
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
619
|
+
def change
|
620
|
+
create_table :table_name do |t|
|
621
|
+
t.string :contains_word, custom: "TRIM({contains_word}) = 'word'"
|
622
|
+
t.string :contains_word_synonym,
|
623
|
+
validates: "TRIM({contains_word_synonym}) = 'word'"
|
624
|
+
t.string :contains_word_in_trigger,
|
625
|
+
custom: { statement: "TRIM({contains_word_in_trigger}) = 'word'", as: :trigger }
|
626
|
+
end
|
397
627
|
end
|
398
628
|
```
|
399
629
|
|
@@ -406,77 +636,23 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
406
636
|
* `:allow_nil` - ignore validation for nil values. Default value: false
|
407
637
|
* `:allow_blank` - ignore validation for blank values. Default value: `false`
|
408
638
|
* `:as` - defines the way how constraint will be implemented. Possible values: `[:trigger]`
|
639
|
+
|
640
|
+
## Version History
|
409
641
|
|
410
|
-
|
411
|
-
|
412
|
-
Examples:
|
413
|
-
|
414
|
-
allows only values that equals 'word' when trimmed:
|
415
|
-
|
416
|
-
```ruby
|
417
|
-
validates :table_name, :column_name,
|
418
|
-
custom: { statement: "TRIM({column_name}) = 'word'" }
|
419
|
-
```
|
420
|
-
|
421
|
-
with failure message:
|
642
|
+
**(2.0.0)** (17 Jan, 2015)
|
422
643
|
|
423
|
-
|
424
|
-
validates :table_name, :column_name,
|
425
|
-
custom: { statement: "TRIM({column_name}) = 'word'",
|
426
|
-
message: 'Column_name value should contain start word' }
|
427
|
-
```
|
644
|
+
* Completely rewritten. Migrated to Ruby 2.0 and RoR 4
|
428
645
|
|
429
|
-
|
646
|
+
**(2.1.0)** (22 Jan, 2015)
|
430
647
|
|
431
|
-
|
432
|
-
validates :table_name, :column_name,
|
433
|
-
custom: { statement: "TRIM({column_name}) = 'word'",
|
434
|
-
message: 'Column_name value should contain start word',
|
435
|
-
as: :trigger,
|
436
|
-
on: :create }
|
437
|
-
```
|
648
|
+
* Custom validation
|
438
649
|
|
439
|
-
|
650
|
+
**(2.2.0)** (28 Jan, 2015)
|
440
651
|
|
441
|
-
|
442
|
-
create_table :table_name do |t|
|
443
|
-
t.string :column_name,
|
444
|
-
validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
|
445
|
-
end
|
446
|
-
```
|
652
|
+
* Integration with ActiveRecord
|
447
653
|
|
448
|
-
|
449
|
-
change :table_name do |t|
|
450
|
-
t.change :column_name, :string,
|
451
|
-
validates: { custom: { statement: "TRIM({column_name}) = 'word'"} }
|
452
|
-
end
|
453
|
-
```
|
654
|
+
## Contributing
|
454
655
|
|
455
|
-
simplifications (version >= 2.1 is required):
|
456
|
-
|
457
|
-
```ruby
|
458
|
-
create_table :table_name do |t|
|
459
|
-
t.string :contains_word, custom: "TRIM({contains_word}) = 'word'"
|
460
|
-
t.string :contains_word_synonym,
|
461
|
-
validates: "TRIM({contains_word_synonym}) = 'word'"
|
462
|
-
t.string :contains_word_in_trigger,
|
463
|
-
custom: { statement: "TRIM({contains_word_in_trigger}) = 'word'", as: :trigger }
|
464
|
-
end
|
465
|
-
```
|
466
|
-
|
467
|
-
Options:
|
468
|
-
|
469
|
-
* `statement` - db expression that column value should be matched to
|
470
|
-
* `message` - message that should be shown if validation failed
|
471
|
-
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
472
|
-
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
473
|
-
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
474
|
-
* `allow_nil` - ignore validation for `nil` values. Default value: `false`
|
475
|
-
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
476
|
-
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
|
477
|
-
|
478
|
-
## Contributing to mv-mysql
|
479
|
-
|
480
656
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
481
657
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
482
658
|
* Fork the project
|
@@ -484,8 +660,3 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
484
660
|
* Commit and push until you are happy with your contribution
|
485
661
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
486
662
|
* 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.
|
487
|
-
|
488
|
-
## Copyright
|
489
|
-
|
490
|
-
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
491
|
-
further details.
|
data/lib/mv-mysql.rb
CHANGED
@@ -47,5 +47,15 @@ ActiveSupport.on_load(:mv_core) do
|
|
47
47
|
Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness,
|
48
48
|
Mv::Mysql::Validation::Custom => Mv::Mysql::Validation::Builder::Trigger::Custom
|
49
49
|
)
|
50
|
+
|
51
|
+
#validation active model presenters
|
52
|
+
Mv::Core::Validation::ActiveModelPresenter::Factory.register_presenters(
|
53
|
+
Mv::Mysql::Validation::Exclusion => Mv::Core::Validation::ActiveModelPresenter::Exclusion,
|
54
|
+
Mv::Mysql::Validation::Inclusion => Mv::Core::Validation::ActiveModelPresenter::Inclusion,
|
55
|
+
Mv::Mysql::Validation::Length => Mv::Core::Validation::ActiveModelPresenter::Length,
|
56
|
+
Mv::Mysql::Validation::Presence => Mv::Core::Validation::ActiveModelPresenter::Presence,
|
57
|
+
Mv::Mysql::Validation::Absence => Mv::Core::Validation::ActiveModelPresenter::Absence,
|
58
|
+
Mv::Mysql::Validation::Uniqueness => Mv::Core::Validation::ActiveModelPresenter::Uniqueness
|
59
|
+
)
|
50
60
|
end
|
51
61
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valeriy Prokopchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.2'
|
48
48
|
type: :runtime
|
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: '2.
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: jeweler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
165
|
requirements:
|
166
166
|
- - '>='
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version: '0'
|
168
|
+
version: '2.0'
|
169
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - '>='
|