mv-postgresql 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32dd42e8c1f366be6588c1a5917d036031938022
4
- data.tar.gz: 1e4a6cf2e617bd61469a78dff3c69cd5cc7bc702
3
+ metadata.gz: 5312214a363c7e4dd85d54c07bc72f29791d7ba7
4
+ data.tar.gz: 58a0227278138a421c75bdee96ee1bf72b616b2c
5
5
  SHA512:
6
- metadata.gz: dc152b93f0568897e1b3bb1fc87e0248632e90bc562cd7bc4e74c84f0e1d3d0e3b847cf1910954f940fcfbf5dc2a555a64c77465ac401c908ea4c3d74fdcf1c1
7
- data.tar.gz: 7bcd5d532fde13ad2c4a5654115037a6dd708c457cc2f2ba4437cb736a6bf13b88334251273360d35bfdf1358e564c2ea5bf3d70b24b2174cdd7dc33ef479b27
6
+ metadata.gz: 560d9087028db2e17a187ac876ac9fee9ec467f4cb4df27ec63a3a24c614e690c0907cda91a7445f49e17b04c14ae4173a1d1cc934c7decc7c5886bd9db09ddd
7
+ data.tar.gz: 8ac04ec6d42cf0492d3c28efbb5301b3fed8e86e02f7fee0131ce60dc0c8450898040b155bb658418fb77cc058edffbb360d462ad06a5f04037f342d3341e3c8
data/README.md CHANGED
@@ -1,11 +1,10 @@
1
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vprokopchuk256/mv-postgresql/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
2
1
  [![Build Status](https://travis-ci.org/vprokopchuk256/mv-postgresql.svg?branch=master)](https://travis-ci.org/vprokopchuk256/mv-postgresql)
3
2
  [![Coverage Status](https://coveralls.io/repos/vprokopchuk256/mv-postgresql/badge.png?branch=master)](https://coveralls.io/r/vprokopchuk256/mv-postgresql?branch=master)
4
3
  [![Gem Version](https://badge.fury.io/rb/mv-postgresql.svg)](http://badge.fury.io/rb/mv-postgresql)
5
4
 
6
5
  # Introduction
7
6
 
8
- mv-postgresql is the PostgreSQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
7
+ mv-postgresql is the PostgreSQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core). Allows RoR developer to define database constraints in a familiar ActiveRecord validations manner
9
8
 
10
9
  # Validators
11
10
 
@@ -13,7 +12,7 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
13
12
 
14
13
  Examples:
15
14
 
16
- validate uniqueness of the column 'column_name':
15
+ validate uniqueness of the column `column_name`:
17
16
 
18
17
  ```ruby
19
18
  validates :table_name, :column_name, uniqueness: true
@@ -42,7 +41,15 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
42
41
 
43
42
  ```ruby
44
43
  change :table_name do |t|
45
- t.change :column_name, :string, :validates: { uniqueness: false }
44
+ t.change :column_name, :string, validates: { uniqueness: false }
45
+ end
46
+ ```
47
+
48
+ simplifications (version >= 2.1 is required):
49
+
50
+ ```ruby
51
+ create_table :table_name do |t|
52
+ t.string :column_name, uniqueness: true
46
53
  end
47
54
  ```
48
55
 
@@ -59,27 +66,27 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
59
66
 
60
67
  ### length
61
68
 
62
- Examples:
69
+ Examples:
63
70
 
64
71
  ```ruby
65
72
  validates :table_name, :column_name,
66
- length: { in: 5..8,
67
- message: 'Wrong length message'}
73
+ length: { in: 5..8, message: 'Wrong length message'}
68
74
  ```
69
75
 
70
- allow `NULL`:
76
+ allow `NULL`:
71
77
 
72
78
  ```ruby
73
79
  validates :table_name, :column_name,
74
- length: { is: 3, allow_nil: true}
80
+ length: { is: 3, allow_nil: true}
75
81
  ```
76
82
 
77
83
  allow blank values:
78
84
 
79
85
  ```ruby
80
86
  validates :table_name, :column_name,
81
- length: { maximum: 3,
82
- too_long: 'Value is longer than 3 symbols' }
87
+ length: { maximum: 3,
88
+ allow_blank: true,
89
+ too_long: 'Value is longer than 3 symbols' }
83
90
  ```
84
91
 
85
92
  define constraint in trigger:
@@ -91,6 +98,32 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
91
98
  too_long: 'Value is longer than 3 symbols' }
92
99
  ```
93
100
 
101
+ all above are available in a create and change table blocks:
102
+
103
+ ```ruby
104
+ create_table :table_name do |t|
105
+ t.string :column_name, validates: { length: { is: 3, allow_nil: true} }
106
+ end
107
+ ```
108
+
109
+ ```ruby
110
+ change :table_name do |t|
111
+ t.change :column_name, :string, validates: { length: { is: 3 } }
112
+ end
113
+ ```
114
+
115
+ simplifications (version >= 2.1 is required):
116
+
117
+ ```ruby
118
+ create_table :table_name do |t|
119
+ t.string :string_3, length: 3
120
+ t.string :string_from_1_to_3, length: 1..3,
121
+ t.string :string_1_or_3, length: [1, 3]
122
+ t.string :string_4, validates: { length: 4 }
123
+ t.string :string_4_in_trigger: length: { is: 4, as: :trigger }
124
+ end
125
+ ```
126
+
94
127
  Options:
95
128
 
96
129
  * `in` - range or array that length of the value should be contained in.
@@ -130,18 +163,41 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
130
163
 
131
164
  ```ruby
132
165
  validates :table_name, :column_name,
133
- inclusion: { in: [1, 2, 3],
134
- on: :update,
135
- as: :check }
166
+ inclusion: { in: [1, 2, 3], as: :check }
136
167
  ```
137
168
 
138
169
  make it in trigger:
139
170
 
140
171
  ```ruby
141
172
  validates :table_name, :column_name,
142
- inclusion: { in: 1..3,
143
- on: :create,
144
- as: :trigger }
173
+ inclusion: { in: 1..3,
174
+ on: :create,
175
+ as: :trigger }
176
+ ```
177
+
178
+ all above are available in a create and change table blocks:
179
+
180
+ ```ruby
181
+ create_table :table_name do |t|
182
+ t.integer :column_name, validates: { inclusion: { in: 1..3 } }
183
+ end
184
+ ```
185
+
186
+ ```ruby
187
+ change :table_name do |t|
188
+ t.change :column_name, :integer, validates: { inclusion: { in: 1..3 } }
189
+ end
190
+ ```
191
+
192
+ simplifications (version >= 2.1 is required):
193
+
194
+ ```ruby
195
+ create_table :table_name do |t|
196
+ t.string :str_or_str_1, inclusion: ['str', 'str1']
197
+ t.string :from_str_to_str_1, inclusion: 'str'..'str1'
198
+ t.string :str_or_str_1_in_trigger, inclusion: { in: ['str', 'str1'],
199
+ as: :trigger}
200
+ end
145
201
  ```
146
202
 
147
203
  Options:
@@ -161,6 +217,16 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
161
217
  Examples:
162
218
 
163
219
  exclude 1, 2, and 3:
220
+
221
+ within `create_table` statement:
222
+
223
+ ```ruby
224
+ create_tablel :tabld_name do |t|
225
+ t.integer :column_name, validates: { exclusion: { in: [1, 2, 3] } }
226
+ end
227
+ ```
228
+
229
+ or as standalone statements:
164
230
 
165
231
  ```ruby
166
232
  validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
@@ -179,9 +245,7 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
179
245
 
180
246
  ```ruby
181
247
  validates :table_name, :column_name,
182
- exclusion: { in: [1, 2, 3],
183
- on: :update,
184
- as: :check }
248
+ exclusion: { in: [1, 2, 3], as: :check }
185
249
  ```
186
250
 
187
251
  as trigger:
@@ -193,6 +257,30 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
193
257
  as: :trigger }
194
258
  ```
195
259
 
260
+ all above are available in a create and change table blocks:
261
+
262
+ ```ruby
263
+ create_table :table_name do |t|
264
+ t.integer :column_name, validates: { exclusion: { in: 1..3 } }
265
+ end
266
+ ```
267
+
268
+ ```ruby
269
+ change :table_name do |t|
270
+ t.change :column_name, :integer, validates: { exclusion: { in: 1..3 } }
271
+ end
272
+ ```
273
+
274
+ simplifications (version >= 2.1 is required):
275
+
276
+ ```ruby
277
+ create_table :table_name do |t|
278
+ t.string :neither_str_nor_str_1, exclusion: ['str', 'str1']
279
+ t.string :from_str_to_str_1, exclusion: 'str'..'str1'
280
+ t.string :str_or_str_1_in_trigger, exclusion: { in: ['str', 'str1'],
281
+ as: :trigger}
282
+ end
283
+ ```
196
284
 
197
285
  Options:
198
286
 
@@ -237,6 +325,29 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
237
325
  on: :create }
238
326
  ```
239
327
 
328
+ all above are available in a create and change table blocks:
329
+
330
+ ```ruby
331
+ create_table :table_name do |t|
332
+ t.string :column_name, validates: { presence: true }
333
+ end
334
+ ```
335
+
336
+ ```ruby
337
+ change :table_name do |t|
338
+ t.change :column_name, :string, validates: { presence: true }
339
+ end
340
+ ```
341
+
342
+ simplifications (version >= 2.1 is required):
343
+
344
+ ```ruby
345
+ create_table :table_name do |t|
346
+ t.string :presence_in_check, presence: true
347
+ t.string :presence_in_trigger, presence: { as: :trigger, on: :create }
348
+ end
349
+ ```
350
+
240
351
  Options:
241
352
 
242
353
  * `message` - message that should be shown if validation failed
@@ -279,6 +390,29 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
279
390
  on: :create }
280
391
  ```
281
392
 
393
+ all above are available in a create and change table blocks:
394
+
395
+ ```ruby
396
+ create_table :table_name do |t|
397
+ t.string :column_name, validates: { absence: true }
398
+ end
399
+ ```
400
+
401
+ ```ruby
402
+ change :table_name do |t|
403
+ t.change :column_name, :string, validates: { absence: true }
404
+ end
405
+ ```
406
+
407
+ simplifications (version >= 2.1 is required):
408
+
409
+ ```ruby
410
+ create_table :table_name do |t|
411
+ t.string :absence_in_check, absence: true
412
+ t.string :absence_in_trigger, absence: { as: :trigger, on: :create }
413
+ end
414
+ ```
415
+
282
416
  Options:
283
417
 
284
418
  * `message` - message that should be shown if validation failed
@@ -316,6 +450,29 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
316
450
  as: :trigger }
317
451
  ```
318
452
 
453
+ all above are available in a create and change table blocks:
454
+
455
+ ```ruby
456
+ create_table :table_name do |t|
457
+ t.string :column_name, validates { format: { with: /word/ } }
458
+ end
459
+ ```
460
+
461
+ ```ruby
462
+ change :table_name do |t|
463
+ t.change :column_name, :string, validates: { format: { with: /word/ } }
464
+ end
465
+ ```
466
+
467
+ simplifications (version >= 2.1 is required):
468
+
469
+ ```ruby
470
+ create_table :table_name do |t|
471
+ t.string :contains_word, format: /word/
472
+ t.string :contains_word_in_trigger, format: { with: /word/, as: :trigger }
473
+ end
474
+ ```
475
+
319
476
  Options:
320
477
 
321
478
  * `with` - regular expression that column value should be matched to
@@ -327,6 +484,74 @@ mv-postgresql is the PostgreSQL driver for Migration Validators project (details
327
484
  * `allow_blank` - ignore validation for blank values. Default value: `false`
328
485
  * `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
329
486
 
487
+ ### custom (version >= 2.1 is required)
488
+
489
+ Examples:
490
+
491
+ allows only values that contains 'word' inside:
492
+
493
+ ```ruby
494
+ validates :table_name, :column_name,
495
+ custom: { statement: "TRIM({column_name}) ~ 'word'" }
496
+ ```
497
+
498
+ with failure message:
499
+
500
+ ```ruby
501
+ validates :table_name, :column_name,
502
+ custom: { statement: "TRIM({column_name}) ~ 'word'",
503
+ message: 'Column_name value should contain start word' }
504
+ ```
505
+
506
+ implemented as trigger:
507
+
508
+ ```ruby
509
+ validates :table_name, :column_name,
510
+ custom: { statement: "TRIM({column_name}) ~ 'word'",
511
+ message: 'Column_name value should contain start word',
512
+ as: :trigger }
513
+ ```
514
+
515
+ all above are available in a create and change table blocks:
516
+
517
+ ```ruby
518
+ create_table :table_name do |t|
519
+ t.string :column_name,
520
+ validates: { custom: { statement: "TRIM({column_name}) ~ 'word'"} }
521
+ end
522
+ ```
523
+
524
+ ```ruby
525
+ change :table_name do |t|
526
+ t.change :column_name, :string,
527
+ validates: { custom: { statement: "TRIM({column_name}) ~ 'word'"} }
528
+ end
529
+ ```
530
+
531
+ simplifications (version >= 2.1 is required):
532
+
533
+ ```ruby
534
+ create_table :table_name do |t|
535
+ t.string :contains_word, custom: "TRIM({contains_word}) ~ 'word'"
536
+ t.string :contains_word_synonym,
537
+ validates: "TRIM({contains_word_synonym}) ~ 'word'"
538
+ t.string :contains_word_in_trigger,
539
+ custom: { statement: "TRIM({contains_word_in_trigger}) ~ 'word'",
540
+ as: :trigger }
541
+ end
542
+ ```
543
+
544
+ Options:
545
+
546
+ * `statement` - db expression that column value should be matched to
547
+ * `message` - message that should be shown if validation failed
548
+ * `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
549
+ * `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
550
+ * `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
551
+ * `allow_nil` - ignore validation for `nil` values. Default value: `false`
552
+ * `allow_blank` - ignore validation for blank values. Default value: `false`
553
+ * `as` - defines the way how constraint will be implemented. Possible values: `[:trigger, :check]` Default value: `:check`
554
+
330
555
  ## Contributing to mv-postgresql
331
556
 
332
557
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -14,6 +14,7 @@ require 'mv/postgresql/validation/inclusion'
14
14
  require 'mv/postgresql/validation/length'
15
15
  require 'mv/postgresql/validation/presence'
16
16
  require 'mv/postgresql/validation/absence'
17
+ require 'mv/postgresql/validation/custom'
17
18
 
18
19
  require 'mv/postgresql/validation/builder/trigger/exclusion'
19
20
  require 'mv/postgresql/validation/builder/trigger/inclusion'
@@ -22,6 +23,7 @@ require 'mv/postgresql/validation/builder/trigger/format'
22
23
  require 'mv/postgresql/validation/builder/trigger/presence'
23
24
  require 'mv/postgresql/validation/builder/trigger/absence'
24
25
  require 'mv/postgresql/validation/builder/trigger/uniqueness'
26
+ require 'mv/postgresql/validation/builder/trigger/custom'
25
27
 
26
28
  ActiveSupport.on_load(:mv_core) do
27
29
  #router
@@ -43,7 +45,8 @@ ActiveSupport.on_load(:mv_core) do
43
45
  :inclusion => Mv::Postgresql::Validation::Inclusion,
44
46
  :length => Mv::Postgresql::Validation::Length,
45
47
  :presence => Mv::Postgresql::Validation::Presence,
46
- :absence => Mv::Postgresql::Validation::Absence
48
+ :absence => Mv::Postgresql::Validation::Absence,
49
+ :custom => Mv::Postgresql::Validation::Custom
47
50
  )
48
51
 
49
52
  #validation builders in trigger
@@ -54,7 +57,8 @@ ActiveSupport.on_load(:mv_core) do
54
57
  Mv::Postgresql::Validation::Format => Mv::Postgresql::Validation::Builder::Trigger::Format,
55
58
  Mv::Postgresql::Validation::Presence => Mv::Postgresql::Validation::Builder::Trigger::Presence,
56
59
  Mv::Postgresql::Validation::Absence => Mv::Postgresql::Validation::Builder::Trigger::Absence,
57
- Mv::Core::Validation::Uniqueness => Mv::Postgresql::Validation::Builder::Trigger::Uniqueness
60
+ Mv::Core::Validation::Uniqueness => Mv::Postgresql::Validation::Builder::Trigger::Uniqueness,
61
+ Mv::Postgresql::Validation::Custom => Mv::Postgresql::Validation::Builder::Trigger::Custom,
58
62
  )
59
63
 
60
64
  #validation builders in check
@@ -64,7 +68,8 @@ ActiveSupport.on_load(:mv_core) do
64
68
  Mv::Postgresql::Validation::Length => Mv::Core::Validation::Builder::Length,
65
69
  Mv::Postgresql::Validation::Format => Mv::Postgresql::Validation::Builder::Format,
66
70
  Mv::Postgresql::Validation::Presence => Mv::Core::Validation::Builder::Presence,
67
- Mv::Postgresql::Validation::Absence => Mv::Core::Validation::Builder::Absence
71
+ Mv::Postgresql::Validation::Absence => Mv::Core::Validation::Builder::Absence,
72
+ Mv::Postgresql::Validation::Custom => Mv::Core::Validation::Builder::Custom
68
73
  )
69
74
 
70
75
  end
@@ -0,0 +1,15 @@
1
+ require 'mv/postgresql/validation/builder/trigger/trigger_column'
2
+
3
+ module Mv
4
+ module Postgresql
5
+ module Validation
6
+ module Builder
7
+ module Trigger
8
+ class Custom < Mv::Core::Validation::Builder::Custom
9
+ include TriggerColumn
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -11,7 +11,7 @@ module Mv
11
11
  def initialize(table_name, column_name, opts)
12
12
  super
13
13
 
14
- @check_name = opts.with_indifferent_access[:check_name] || default_check_name
14
+ @check_name = options.with_indifferent_access[:check_name] || default_check_name
15
15
  end
16
16
 
17
17
  def to_a
@@ -0,0 +1,11 @@
1
+ require 'mv/postgresql/validation/check_support'
2
+
3
+ module Mv
4
+ module Postgresql
5
+ module Validation
6
+ class Custom < Mv::Core::Validation::Custom
7
+ include CheckSupport
8
+ end
9
+ end
10
+ end
11
+ end
@@ -11,6 +11,8 @@ module Mv
11
11
  validates :with, presence: true
12
12
 
13
13
  def initialize(table_name, column_name, opts)
14
+ opts = { with: opts } unless opts.is_a?(Hash)
15
+
14
16
  super(table_name, column_name, opts)
15
17
 
16
18
  @with = opts.with_indifferent_access[:with]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mv-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.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-19 00:00:00.000000000 Z
11
+ date: 2015-01-22 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.0'
47
+ version: '2.1'
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.0'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jeweler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +144,7 @@ files:
144
144
  - lib/mv/postgresql/validation/builder/format.rb
145
145
  - lib/mv/postgresql/validation/builder/inclusion.rb
146
146
  - lib/mv/postgresql/validation/builder/trigger/absence.rb
147
+ - lib/mv/postgresql/validation/builder/trigger/custom.rb
147
148
  - lib/mv/postgresql/validation/builder/trigger/exclusion.rb
148
149
  - lib/mv/postgresql/validation/builder/trigger/format.rb
149
150
  - lib/mv/postgresql/validation/builder/trigger/inclusion.rb
@@ -152,6 +153,7 @@ files:
152
153
  - lib/mv/postgresql/validation/builder/trigger/trigger_column.rb
153
154
  - lib/mv/postgresql/validation/builder/trigger/uniqueness.rb
154
155
  - lib/mv/postgresql/validation/check_support.rb
156
+ - lib/mv/postgresql/validation/custom.rb
155
157
  - lib/mv/postgresql/validation/exclusion.rb
156
158
  - lib/mv/postgresql/validation/format.rb
157
159
  - lib/mv/postgresql/validation/inclusion.rb