mv-mysql 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +44 -45
- data/lib/mv-mysql.rb +54 -1
- data/lib/mv/mysql/active_record/connection_adapters/mysql_adapter_decorator.rb +11 -0
- data/lib/mv/mysql/constraint/builder/trigger.rb +51 -0
- data/lib/mv/mysql/railtie.rb +11 -0
- data/lib/mv/mysql/validation/absence.rb +11 -0
- data/lib/mv/mysql/validation/builder/trigger/absence.rb +15 -0
- data/lib/mv/mysql/validation/builder/trigger/exclusion.rb +17 -0
- data/lib/mv/mysql/validation/builder/trigger/inclusion.rb +17 -0
- data/lib/mv/mysql/validation/builder/trigger/length.rb +15 -0
- data/lib/mv/mysql/validation/builder/trigger/mysql_datetime_values.rb +20 -0
- data/lib/mv/mysql/validation/builder/trigger/presence.rb +15 -0
- data/lib/mv/mysql/validation/builder/trigger/trigger_column.rb +17 -0
- data/lib/mv/mysql/validation/builder/trigger/uniqueness.rb +15 -0
- data/lib/mv/mysql/validation/exclusion.rb +11 -0
- data/lib/mv/mysql/validation/inclusion.rb +11 -0
- data/lib/mv/mysql/validation/length.rb +11 -0
- data/lib/mv/mysql/validation/mysql_error_message_restrictions.rb +13 -0
- data/lib/mv/mysql/validation/presence.rb +11 -0
- data/lib/mv/mysql/validation/uniqueness.rb +11 -0
- metadata +93 -6
- data/lib/migration_validators/adapters/mysql.rb +0 -103
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2e34b3bf792fc0af5fe6f7a8eba9fff0e45d72a8
|
|
4
|
+
data.tar.gz: 16d472ac7b1df90e0b572d09d51c9e1e58829581
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d101f8c2604d4ead2d404f46818b7322d8960a7de257a3d5693cf0eca28be55c69e84dc7f76afd2ffa18c2c197d7412c811cf8f7caf71f362a5582a69c5bdf0
|
|
7
|
+
data.tar.gz: 60a0f244a35b978908d16706228329a24134717aff78d5fec0d2974fd03091ab898dbfb70b959752a09e4d0867aafc9b957be3aead20918af6a30dc15e7cc97f
|
data/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
|
2
|
+
[](https://travis-ci.org/vprokopchuk256/mv-mysql)
|
|
3
|
+
[](https://coveralls.io/r/vprokopchuk256/mv-mysql?branch=master)
|
|
4
|
+
[](http://badge.fury.io/rb/mv-mysql)
|
|
5
|
+
|
|
1
6
|
# Introduction
|
|
2
7
|
|
|
3
8
|
mv-mysql is the MySQL driver for Migration Validators project (details here: https://github.com/vprokopchuk256/mv-core)
|
|
4
9
|
|
|
5
|
-
# Validators
|
|
6
|
-
|
|
7
10
|
### uniqueness
|
|
8
11
|
|
|
9
12
|
Examples:
|
|
@@ -11,20 +14,20 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
11
14
|
validate uniqueness of the column 'column_name':
|
|
12
15
|
|
|
13
16
|
```ruby
|
|
14
|
-
|
|
17
|
+
validates :table_name, :column_name, uniqueness: true
|
|
15
18
|
```
|
|
16
19
|
|
|
17
20
|
define validation as trigger with specified failure message:
|
|
18
21
|
|
|
19
22
|
```ruby
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
validates :table_name, :column_name,
|
|
24
|
+
uniqueness: { message: 'Error message', as: :trigger }
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
define validation as unique index:
|
|
25
28
|
|
|
26
29
|
```ruby
|
|
27
|
-
|
|
30
|
+
validates :table_name, :column_name, uniqueness: { as: :index }
|
|
28
31
|
```
|
|
29
32
|
|
|
30
33
|
all above are available in a create and change table blocks:
|
|
@@ -59,22 +62,22 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
59
62
|
column value length should be more than 4 symbols and less than 9. Otherwise 'Wrong length message' error will be raised:
|
|
60
63
|
|
|
61
64
|
```ruby
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
validates :table_name, :column_name,
|
|
66
|
+
length: { in: 5..8,
|
|
67
|
+
message: 'Wrong length message' }
|
|
65
68
|
```
|
|
66
69
|
|
|
67
70
|
allow `NULL`:
|
|
68
71
|
|
|
69
72
|
```ruby
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
validates :table_name, :column_name,
|
|
74
|
+
length: { is: 3, allow_nil: true}
|
|
72
75
|
```
|
|
73
76
|
|
|
74
77
|
allow blank values:
|
|
75
78
|
|
|
76
79
|
```ruby
|
|
77
|
-
|
|
80
|
+
validates :table_name, :column_name,
|
|
78
81
|
length: { maximum: 3,
|
|
79
82
|
too_long: 'Value is longer than 3 symbols' }
|
|
80
83
|
```
|
|
@@ -103,13 +106,13 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
103
106
|
valid values array:
|
|
104
107
|
|
|
105
108
|
```ruby
|
|
106
|
-
|
|
109
|
+
validates :table_name, :column_name, inclusion: { in: [1, 2, 3]}
|
|
107
110
|
```
|
|
108
111
|
|
|
109
112
|
with failure message specified:
|
|
110
113
|
|
|
111
114
|
```ruby
|
|
112
|
-
|
|
115
|
+
validates :table_name, :column_name,
|
|
113
116
|
inclusion: { in: [1, 2, 3],
|
|
114
117
|
message: "Column 'column_name' should be equal to 1 or 2 or 3" }
|
|
115
118
|
```
|
|
@@ -133,13 +136,13 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
133
136
|
exclude 1, 2, and 3:
|
|
134
137
|
|
|
135
138
|
```ruby
|
|
136
|
-
|
|
139
|
+
validates :table_name, :column_name, exclusion: { in: [1, 2, 3] }
|
|
137
140
|
```
|
|
138
141
|
|
|
139
142
|
exclude values with specified failure message:
|
|
140
143
|
|
|
141
144
|
```ruby
|
|
142
|
-
|
|
145
|
+
validates :table_name, :column_name,
|
|
143
146
|
exclusion: {
|
|
144
147
|
in: [1, 2, 3],
|
|
145
148
|
message: "Column 'column_name' should not be equal to 1 or 2 or 3"
|
|
@@ -149,7 +152,7 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
149
152
|
performs verification on update only:
|
|
150
153
|
|
|
151
154
|
```ruby
|
|
152
|
-
|
|
155
|
+
validates :table_name, :column_name,
|
|
153
156
|
exclusion: { in: [1, 2, 3],
|
|
154
157
|
on: :update }
|
|
155
158
|
```
|
|
@@ -172,64 +175,61 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
172
175
|
simple presence validator:
|
|
173
176
|
|
|
174
177
|
```ruby
|
|
175
|
-
|
|
178
|
+
validates :table_name, :column_name, presence: true
|
|
176
179
|
```
|
|
177
180
|
|
|
178
181
|
with failure message:
|
|
179
182
|
|
|
180
183
|
```ruby
|
|
181
|
-
|
|
184
|
+
validates :table_name, :column_name,
|
|
182
185
|
:presence: { message: 'value should not be empty' }
|
|
183
186
|
```
|
|
184
187
|
|
|
185
188
|
performs verification only when new record is inserted:
|
|
186
189
|
|
|
187
190
|
```ruby
|
|
188
|
-
|
|
191
|
+
validates :table_name, :column_name,
|
|
189
192
|
presence: { message: 'value should not be empty',
|
|
190
193
|
on: :create }
|
|
191
194
|
```
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
* `:message` - message that should be shown if validation failed
|
|
196
|
-
`:on` validation event. Possible values `[:save, :update, :create]`. Default value: `:save`
|
|
197
|
-
* `:create_tigger_name` - name of the 'before insert' trigger
|
|
198
|
-
* `:update_tigger_name` - name of the 'before update' trigger
|
|
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]`
|
|
202
|
-
|
|
203
|
-
### format
|
|
204
|
-
|
|
205
|
-
Allows to define regular expression that column value will be mathed with
|
|
196
|
+
### absence
|
|
206
197
|
|
|
207
|
-
|
|
198
|
+
Examples:
|
|
208
199
|
|
|
209
|
-
simple
|
|
200
|
+
simple absence validator:
|
|
210
201
|
|
|
211
202
|
```ruby
|
|
212
|
-
|
|
203
|
+
validates :table_name, :column_name, absence: true
|
|
213
204
|
```
|
|
214
205
|
|
|
215
|
-
with
|
|
206
|
+
with failure message:
|
|
216
207
|
|
|
217
208
|
```ruby
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
messsage: 'Column_name value should contain start word' }
|
|
209
|
+
validates :table_name, :column_name,
|
|
210
|
+
:absence: { message: 'value should not empty' }
|
|
221
211
|
```
|
|
222
212
|
|
|
223
|
-
|
|
213
|
+
performs verification only when new record is inserted:
|
|
224
214
|
|
|
225
215
|
```ruby
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
validates :table_name, :column_name,
|
|
217
|
+
absence: { message: 'value should not empty',
|
|
218
|
+
on: :create }
|
|
229
219
|
```
|
|
230
220
|
|
|
231
221
|
Options:
|
|
232
222
|
|
|
223
|
+
* `:message` - message that should be shown if validation failed
|
|
224
|
+
`:on` validation event. Possible values `[:save, :update, :create]`. Default value: `:save`
|
|
225
|
+
* `:create_tigger_name` - name of the 'before insert' trigger
|
|
226
|
+
* `:update_tigger_name` - name of the 'before update' trigger
|
|
227
|
+
* `:allow_nil` - ignore validation for nil values. Default value: false
|
|
228
|
+
* `:allow_blank` - ignore validation for blank values. Default value: `false`
|
|
229
|
+
* `:as` - defines the way how constraint will be implemented. Possible values: `[:trigger]`
|
|
230
|
+
|
|
231
|
+
Options:
|
|
232
|
+
|
|
233
233
|
* `:with` - regular expression that column value should be matched to
|
|
234
234
|
* `:message` - message that should be shown if validation failed
|
|
235
235
|
* `:on` - validation event. Possible values `[:save, :update, :create]`. Default value: `:save`
|
|
@@ -253,4 +253,3 @@ mv-mysql is the MySQL driver for Migration Validators project (details here: htt
|
|
|
253
253
|
|
|
254
254
|
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
|
255
255
|
further details.
|
|
256
|
-
|
data/lib/mv-mysql.rb
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
require 'mv-core'
|
|
2
|
+
require 'mv/mysql/railtie'
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
+
require 'mv/mysql/constraint/builder/trigger'
|
|
5
|
+
|
|
6
|
+
require 'mv/mysql/validation/exclusion'
|
|
7
|
+
require 'mv/mysql/validation/inclusion'
|
|
8
|
+
require 'mv/mysql/validation/length'
|
|
9
|
+
require 'mv/mysql/validation/presence'
|
|
10
|
+
require 'mv/mysql/validation/absence'
|
|
11
|
+
require 'mv/mysql/validation/uniqueness'
|
|
12
|
+
|
|
13
|
+
require 'mv/mysql/validation/builder/trigger/exclusion'
|
|
14
|
+
require 'mv/mysql/validation/builder/trigger/inclusion'
|
|
15
|
+
require 'mv/mysql/validation/builder/trigger/length'
|
|
16
|
+
require 'mv/mysql/validation/builder/trigger/presence'
|
|
17
|
+
require 'mv/mysql/validation/builder/trigger/absence'
|
|
18
|
+
require 'mv/mysql/validation/builder/trigger/uniqueness'
|
|
19
|
+
|
|
20
|
+
ActiveSupport.on_load(:mv_core) do
|
|
21
|
+
|
|
22
|
+
#constraint builders
|
|
23
|
+
Mv::Core::Constraint::Builder::Factory.register_builders(
|
|
24
|
+
Mv::Core::Constraint::Trigger => Mv::Mysql::Constraint::Builder::Trigger,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
#validations
|
|
28
|
+
Mv::Core::Validation::Factory.register_validations(
|
|
29
|
+
:exclusion => Mv::Mysql::Validation::Exclusion,
|
|
30
|
+
:inclusion => Mv::Mysql::Validation::Inclusion,
|
|
31
|
+
:length => Mv::Mysql::Validation::Length,
|
|
32
|
+
:presence => Mv::Mysql::Validation::Presence,
|
|
33
|
+
:absence => Mv::Mysql::Validation::Absence,
|
|
34
|
+
:uniqueness => Mv::Mysql::Validation::Uniqueness
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
#validation builders in trigger
|
|
38
|
+
Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
|
|
39
|
+
Mv::Mysql::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion ,
|
|
40
|
+
Mv::Mysql::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
|
|
41
|
+
Mv::Mysql::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
|
|
42
|
+
Mv::Mysql::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
|
|
43
|
+
Mv::Mysql::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
|
|
44
|
+
Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
#validation builders in trigger
|
|
48
|
+
Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
|
|
49
|
+
Mv::Core::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion,
|
|
50
|
+
Mv::Core::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
|
|
51
|
+
Mv::Core::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
|
|
52
|
+
Mv::Core::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
|
|
53
|
+
Mv::Core::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
|
|
54
|
+
Mv::Core::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness
|
|
55
|
+
)
|
|
56
|
+
end
|
|
4
57
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Mv
|
|
2
|
+
module Mysql
|
|
3
|
+
module Constraint
|
|
4
|
+
module Builder
|
|
5
|
+
class Trigger < Mv::Core::Constraint::Builder::Trigger
|
|
6
|
+
def create
|
|
7
|
+
validation_builders.group_by(&:table_name).each do |table_name, validations|
|
|
8
|
+
db.execute(drop_trigger_statement(table_name))
|
|
9
|
+
db.execute(create_trigger_statement(table_name))
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def delete
|
|
14
|
+
validation_builders.group_by(&:table_name).each do |table_name, validations|
|
|
15
|
+
db.execute(drop_trigger_statement(table_name))
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def update new_constraint_builder
|
|
20
|
+
delete
|
|
21
|
+
new_constraint_builder.create
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def drop_trigger_statement table_name
|
|
28
|
+
"DROP TRIGGER IF EXISTS #{name};"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_trigger_statement table_name
|
|
32
|
+
"CREATE TRIGGER #{name} BEFORE #{update? ? 'UPDATE' : 'INSERT'} ON #{table_name} FOR EACH ROW
|
|
33
|
+
BEGIN
|
|
34
|
+
DECLARE var INT;
|
|
35
|
+
|
|
36
|
+
#{trigger_body(table_name)};
|
|
37
|
+
END;"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def trigger_body(table_name)
|
|
41
|
+
validation_builders.select{|b| b.table_name == table_name }.collect(&:conditions).flatten.collect do |condition|
|
|
42
|
+
"IF NOT(#{condition[:statement]}) THEN
|
|
43
|
+
SET var = (SELECT MAX(1) FROM `#{condition[:message]}`);
|
|
44
|
+
END IF".squish
|
|
45
|
+
end.join("; \n")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'mv/mysql/active_record/connection_adapters/mysql_adapter_decorator'
|
|
2
|
+
|
|
3
|
+
module Mv
|
|
4
|
+
module Mysql
|
|
5
|
+
class Railtie < ::Rails::Railtie
|
|
6
|
+
initializer 'mv-mysql.initialization', after: 'active_record.initialize_database' do
|
|
7
|
+
::ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:prepend, Mv::Mysql::ActiveRecord::ConnectionAdapters::MysqlAdapterDecorator)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
2
|
+
|
|
3
|
+
module Mv
|
|
4
|
+
module Mysql
|
|
5
|
+
module Validation
|
|
6
|
+
module Builder
|
|
7
|
+
module Trigger
|
|
8
|
+
class Absence < Mv::Core::Validation::Builder::Absence
|
|
9
|
+
include TriggerColumn
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/mysql_datetime_values'
|
|
2
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
3
|
+
|
|
4
|
+
module Mv
|
|
5
|
+
module Mysql
|
|
6
|
+
module Validation
|
|
7
|
+
module Builder
|
|
8
|
+
module Trigger
|
|
9
|
+
class Exclusion < Mv::Core::Validation::Builder::Exclusion
|
|
10
|
+
include MysqlDatetimeValues
|
|
11
|
+
include TriggerColumn
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/mysql_datetime_values'
|
|
2
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
3
|
+
|
|
4
|
+
module Mv
|
|
5
|
+
module Mysql
|
|
6
|
+
module Validation
|
|
7
|
+
module Builder
|
|
8
|
+
module Trigger
|
|
9
|
+
class Inclusion < Mv::Core::Validation::Builder::Inclusion
|
|
10
|
+
include MysqlDatetimeValues
|
|
11
|
+
include TriggerColumn
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
2
|
+
|
|
3
|
+
module Mv
|
|
4
|
+
module Mysql
|
|
5
|
+
module Validation
|
|
6
|
+
module Builder
|
|
7
|
+
module Trigger
|
|
8
|
+
class Length < Mv::Core::Validation::Builder::Length
|
|
9
|
+
include TriggerColumn
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Mv
|
|
2
|
+
module Mysql
|
|
3
|
+
module Validation
|
|
4
|
+
module Builder
|
|
5
|
+
module Trigger
|
|
6
|
+
module MysqlDatetimeValues
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
def db_value value
|
|
10
|
+
return "TIMESTAMP('#{value.strftime('%Y-%m-%d %H:%M:%S')}')" if value.is_a?(DateTime)
|
|
11
|
+
return "TIME('#{value.strftime('%Y-%m-%d %H:%M:%S')}')" if value.is_a?(Time)
|
|
12
|
+
return "DATE('#{value.strftime('%Y-%m-%d')}')" if value.is_a?(Date)
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
2
|
+
|
|
3
|
+
module Mv
|
|
4
|
+
module Mysql
|
|
5
|
+
module Validation
|
|
6
|
+
module Builder
|
|
7
|
+
module Trigger
|
|
8
|
+
class Presence < Mv::Core::Validation::Builder::Presence
|
|
9
|
+
include TriggerColumn
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'mv/mysql/validation/builder/trigger/trigger_column'
|
|
2
|
+
|
|
3
|
+
module Mv
|
|
4
|
+
module Mysql
|
|
5
|
+
module Validation
|
|
6
|
+
module Builder
|
|
7
|
+
module Trigger
|
|
8
|
+
class Uniqueness < Mv::Core::Validation::Builder::Uniqueness
|
|
9
|
+
include TriggerColumn
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mv-mysql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.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:
|
|
11
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: railties
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.1'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: mysql2
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -30,14 +44,14 @@ dependencies:
|
|
|
30
44
|
requirements:
|
|
31
45
|
- - ~>
|
|
32
46
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
47
|
+
version: '2.0'
|
|
34
48
|
type: :runtime
|
|
35
49
|
prerelease: false
|
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
51
|
requirements:
|
|
38
52
|
- - ~>
|
|
39
53
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
54
|
+
version: '2.0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: jeweler
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +66,62 @@ dependencies:
|
|
|
52
66
|
- - ~>
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
68
|
version: '2.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ~>
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.1'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ~>
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.1'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec-its
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ~>
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '1.1'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ~>
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '1.1'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: guard-rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ~>
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '4.5'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ~>
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '4.5'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: mv-test
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ~>
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '1.0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ~>
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '1.0'
|
|
55
125
|
description: Migration Validators project mysql driver
|
|
56
126
|
email: vprokopchuk@gmail.com
|
|
57
127
|
executables: []
|
|
@@ -62,8 +132,25 @@ extra_rdoc_files:
|
|
|
62
132
|
files:
|
|
63
133
|
- LICENSE.txt
|
|
64
134
|
- README.md
|
|
65
|
-
- lib/migration_validators/adapters/mysql.rb
|
|
66
135
|
- lib/mv-mysql.rb
|
|
136
|
+
- lib/mv/mysql/active_record/connection_adapters/mysql_adapter_decorator.rb
|
|
137
|
+
- lib/mv/mysql/constraint/builder/trigger.rb
|
|
138
|
+
- lib/mv/mysql/railtie.rb
|
|
139
|
+
- lib/mv/mysql/validation/absence.rb
|
|
140
|
+
- lib/mv/mysql/validation/builder/trigger/absence.rb
|
|
141
|
+
- lib/mv/mysql/validation/builder/trigger/exclusion.rb
|
|
142
|
+
- lib/mv/mysql/validation/builder/trigger/inclusion.rb
|
|
143
|
+
- lib/mv/mysql/validation/builder/trigger/length.rb
|
|
144
|
+
- lib/mv/mysql/validation/builder/trigger/mysql_datetime_values.rb
|
|
145
|
+
- lib/mv/mysql/validation/builder/trigger/presence.rb
|
|
146
|
+
- lib/mv/mysql/validation/builder/trigger/trigger_column.rb
|
|
147
|
+
- lib/mv/mysql/validation/builder/trigger/uniqueness.rb
|
|
148
|
+
- lib/mv/mysql/validation/exclusion.rb
|
|
149
|
+
- lib/mv/mysql/validation/inclusion.rb
|
|
150
|
+
- lib/mv/mysql/validation/length.rb
|
|
151
|
+
- lib/mv/mysql/validation/mysql_error_message_restrictions.rb
|
|
152
|
+
- lib/mv/mysql/validation/presence.rb
|
|
153
|
+
- lib/mv/mysql/validation/uniqueness.rb
|
|
67
154
|
homepage: http://github.com/vprokopchuk256/mv-mysql
|
|
68
155
|
licenses:
|
|
69
156
|
- MIT
|
|
@@ -84,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
171
|
version: '0'
|
|
85
172
|
requirements: []
|
|
86
173
|
rubyforge_project:
|
|
87
|
-
rubygems_version: 2.4.
|
|
174
|
+
rubygems_version: 2.4.4
|
|
88
175
|
signing_key:
|
|
89
176
|
specification_version: 4
|
|
90
177
|
summary: Migration Validators project. MySQL driver
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
module MigrationValidators
|
|
2
|
-
module Adapters
|
|
3
|
-
class Mysql < MigrationValidators::Adapters::Base
|
|
4
|
-
def name
|
|
5
|
-
"Mysql Migration Validators Adapter"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
define_base_syntax
|
|
9
|
-
define_base_validators
|
|
10
|
-
define_base_containers
|
|
11
|
-
|
|
12
|
-
container :insert_trigger do
|
|
13
|
-
operation :create do |stmt, trigger_name, group_name|
|
|
14
|
-
"CREATE TRIGGER #{trigger_name} BEFORE INSERT ON #{group_name.first} FOR EACH ROW
|
|
15
|
-
BEGIN
|
|
16
|
-
DECLARE var INT;
|
|
17
|
-
|
|
18
|
-
#{stmt};
|
|
19
|
-
END;"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
operation :db_value do |value|
|
|
23
|
-
case value.class.name
|
|
24
|
-
when "String" then "'#{value}'"
|
|
25
|
-
when "Date" then "DATE('#{value.strftime('%Y-%m-%d')}')"
|
|
26
|
-
when "DateTime" then "TIMESTAMP('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
27
|
-
when "Time" then "TIME('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
28
|
-
when "Regexp" then "'#{value.source}'"
|
|
29
|
-
else value.to_s
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
operation :bind_to_error do |stmt, error_message|
|
|
34
|
-
"IF NOT(#{stmt}) THEN
|
|
35
|
-
SET var = (SELECT MAX(1) FROM `#{error_message}`);
|
|
36
|
-
END IF"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
container :update_trigger do
|
|
41
|
-
operation :create do |stmt, trigger_name, group_name|
|
|
42
|
-
"CREATE TRIGGER #{trigger_name} BEFORE UPDATE ON #{group_name.first} FOR EACH ROW
|
|
43
|
-
BEGIN
|
|
44
|
-
DECLARE var INT;
|
|
45
|
-
|
|
46
|
-
#{stmt};
|
|
47
|
-
END;"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
operation :db_value do |value|
|
|
51
|
-
case value.class.name
|
|
52
|
-
when "String" then "'#{value}'"
|
|
53
|
-
when "Date" then "DATE('#{value.strftime('%Y-%m-%d')}')"
|
|
54
|
-
when "DateTime" then "TIMESTAMP('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
55
|
-
when "Time" then "TIME('#{value.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
56
|
-
when "Regexp" then "'#{value.source}'"
|
|
57
|
-
else value.to_s
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
operation :bind_to_error do |stmt, error_message|
|
|
62
|
-
"IF NOT(#{stmt}) THEN
|
|
63
|
-
SET var = (SELECT MAX(1) FROM `#{error_message}`);
|
|
64
|
-
END IF"
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
route :presence, :trigger, :default => true do
|
|
70
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
71
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
route :inclusion, :trigger, :default => true do
|
|
75
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
76
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
route :exclusion, :trigger, :default => true do
|
|
80
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
81
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
route :length, :trigger, :default => true do
|
|
85
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
86
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
route :format, :trigger, :default => true do
|
|
90
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
91
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
route :uniqueness, :trigger do
|
|
95
|
-
to :insert_trigger, :if => {:on => [:save, :create, nil]}
|
|
96
|
-
to :update_trigger, :if => {:on => [:save, :update, nil]}
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
MigrationValidators.register_adapter! "mysql", Mysql
|
|
101
|
-
MigrationValidators.register_adapter! "mysql2", Mysql
|
|
102
|
-
end
|
|
103
|
-
end
|