mv-core 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.md +129 -0
- data/lib/migration_validators/active_record/connection_adapters/table_definition.rb +8 -1
- data/lib/migration_validators/active_record/migration.rb +9 -14
- data/lib/migration_validators/active_record/schema_dumper.rb +2 -0
- data/lib/migration_validators/adapters/validator_definitions.rb +1 -1
- data/lib/mv-core.rb +13 -13
- metadata +23 -23
- data/README.rdoc +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 992c2fce4bb3a1fe416987d75c442a9e17d9fde4
|
4
|
+
data.tar.gz: 6268526d0994ad12e25a26f4ae2ef925c19cfcea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d806091feb1046cc39ceb54ca409ae11d121226e611403c9eee94d71411105fd36c46ff3ab074b9e3136655b146f6bcf63d1cccc1f37bf845db1f7f7f2f8f5e
|
7
|
+
data.tar.gz: d8b81ccfeb2f538a5c64335d93ed8530922a6e928a1c1b3f6ecb87b18598c76ae4abb8dcf411a2fe99aebf6a0be9152186d41847b8f6aa350ae2908b6adfe583
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# Abbreviations
|
2
|
+
|
3
|
+
MV - Migration Validators Projects. All gems that belongs to that project are prefixed with mv-*
|
4
|
+
|
5
|
+
# Project goals
|
6
|
+
|
7
|
+
Main goal of the project is to allow developer to express database constraints in a rdms - agnostic syntax that is similiar to validators in Rails.
|
8
|
+
|
9
|
+
# mv-core
|
10
|
+
|
11
|
+
mv-core is a set of core classes that are used everywhere across Migration Validators project gems.
|
12
|
+
|
13
|
+
This gem is not intended to be installed directly and referenced from within the application. You should rather install appropriate driver.
|
14
|
+
|
15
|
+
# Install
|
16
|
+
|
17
|
+
PostgreSQL:
|
18
|
+
|
19
|
+
```
|
20
|
+
gem install mv-postgresql
|
21
|
+
```
|
22
|
+
|
23
|
+
MySQL:
|
24
|
+
|
25
|
+
```
|
26
|
+
gem install mv-mysql
|
27
|
+
```
|
28
|
+
|
29
|
+
SQLite:
|
30
|
+
|
31
|
+
```
|
32
|
+
gem install mv-sqlite
|
33
|
+
```
|
34
|
+
|
35
|
+
# Usage
|
36
|
+
|
37
|
+
Create new table:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
create_table do |t|
|
41
|
+
t.string :str_column, validates: { uniqueness: :true,
|
42
|
+
inclusion: { in: 1..3 }}
|
43
|
+
t.column :column_name, :integer, validates: { exclusion: { in: [1,2,3]}}
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
Modify existing table:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
change_table do |t|
|
51
|
+
t.change :str_column, :integer, validates: { exclusion: { in: [1,2,3] }}
|
52
|
+
t.change_validates :column_name, inclusion: { in: 1..3 }
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Update validator definition:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
validate_column :table_name, :str_column, :exclusion: { in: [1,2,3] }
|
60
|
+
```
|
61
|
+
|
62
|
+
Remove existing validators:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
change_table do |t|
|
66
|
+
t.change :str_column, :integer, validates: { exclusion: false }
|
67
|
+
end
|
68
|
+
validate_column table_name, :str_column, exclusion: false
|
69
|
+
```
|
70
|
+
|
71
|
+
There are many ways to define desired database constraint. And those ways might vary for each RDBMS. One could define the way how constaint should be
|
72
|
+
defined in DB:
|
73
|
+
|
74
|
+
as trigger:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
validate_column :table_name, :str_column, validates: { uniqueness: true,
|
78
|
+
as: :trigger }
|
79
|
+
```
|
80
|
+
|
81
|
+
as check constraint:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
validate_column :table_name, :str_column, validates: { uniqueness: true,
|
85
|
+
as: :check }
|
86
|
+
```
|
87
|
+
|
88
|
+
Also there is possibility to define when validations should occur:
|
89
|
+
|
90
|
+
when new record created:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
validate_column :table_name, :str_column, validates: { uniqueness: true,
|
94
|
+
on: :create }
|
95
|
+
```
|
96
|
+
|
97
|
+
or when existing record updated:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
validate_column :table_name, :str_column, validates: { uniqueness: true,
|
101
|
+
on: :update }
|
102
|
+
```
|
103
|
+
|
104
|
+
Supported validators and their properties might vary from one db driver to another. See detailed properties description in correspondent driver section.
|
105
|
+
|
106
|
+
# Drivers
|
107
|
+
|
108
|
+
Currently there are drivers for MySQL, PostgreSQL and SQLite RDBMS
|
109
|
+
|
110
|
+
So - see detailed info here:
|
111
|
+
|
112
|
+
* PostgreSQL: https://github.com/vprokopchuk256/mv-postgresql
|
113
|
+
* MySQL: https://github.com/vprokopchuk256/mv-mysql
|
114
|
+
* SQLite: https://github.com/vprokopchuk256/mv-sqlite
|
115
|
+
|
116
|
+
## Contributing to mv-core
|
117
|
+
|
118
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
119
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
120
|
+
* Fork the project
|
121
|
+
* Start a feature/bugfix branch
|
122
|
+
* Commit and push until you are happy with your contribution
|
123
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
124
|
+
* 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.
|
125
|
+
|
126
|
+
## Copyright
|
127
|
+
|
128
|
+
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
129
|
+
further details.
|
@@ -18,7 +18,14 @@ module MigrationValidators
|
|
18
18
|
|
19
19
|
column_without_validators name, type, options
|
20
20
|
|
21
|
-
|
21
|
+
#ugly patch
|
22
|
+
connection = ::ActiveRecord::Base.connection
|
23
|
+
|
24
|
+
connection.class.class_eval {
|
25
|
+
include MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter
|
26
|
+
} unless connection.class.include?(MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter)
|
27
|
+
|
28
|
+
connection.validate_column(nil, name, validates) unless validates.blank?
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -3,27 +3,22 @@ module MigrationValidators
|
|
3
3
|
module Migration
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
6
|
+
included do
|
7
7
|
class_eval do
|
8
|
-
|
9
|
-
self.alias_method_chain :migrate, :validators
|
10
|
-
end
|
8
|
+
alias_method_chain :exec_migration, :validators
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
def exec_migration_with_validators *args
|
13
|
+
connection.class.class_eval {
|
14
|
+
include MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter
|
15
|
+
} unless connection.class.include?(MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter)
|
16
16
|
|
17
|
-
|
18
|
-
include MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter
|
19
|
-
} unless connection.class.include?(MigrationValidators::ActiveRecord::ConnectionAdapters::NativeAdapter)
|
17
|
+
connection.initialize_migration_validators_table
|
20
18
|
|
21
|
-
|
19
|
+
exec_migration_without_validators *args
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
MigrationValidators::Core::DbValidator.commit MigrationValidators.validator
|
26
|
-
end
|
21
|
+
MigrationValidators::Core::DbValidator.commit MigrationValidators.validator
|
27
22
|
end
|
28
23
|
end
|
29
24
|
end
|
@@ -12,6 +12,8 @@ module MigrationValidators
|
|
12
12
|
def tables_with_validators(stream)
|
13
13
|
tables_without_validators(stream)
|
14
14
|
|
15
|
+
@connection.initialize_migration_validators_table
|
16
|
+
|
15
17
|
stream.puts ""
|
16
18
|
stream.puts " #Validators"
|
17
19
|
MigrationValidators::Core::DbValidator.order([:table_name, :column_name]).each do |validator|
|
data/lib/mv-core.rb
CHANGED
@@ -75,7 +75,7 @@ module MigrationValidators
|
|
75
75
|
def load!
|
76
76
|
::ActiveRecord::ConnectionAdapters::TableDefinition.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::TableDefinition }
|
77
77
|
::ActiveRecord::ConnectionAdapters::Table.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::Table }
|
78
|
-
|
78
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval { include MigrationValidators::ActiveRecord::ConnectionAdapters::AbstractAdapter }
|
79
79
|
::ActiveRecord::Base.instance_eval { include MigrationValidators::ActiveRecord::Base }
|
80
80
|
::ActiveRecord::Migration.instance_eval { include MigrationValidators::ActiveRecord::Migration }
|
81
81
|
::ActiveRecord::Schema.instance_eval { include MigrationValidators::ActiveRecord::Schema }
|
@@ -89,17 +89,17 @@ end
|
|
89
89
|
|
90
90
|
Dir.glob('adapters/**/*.rb').each {|file_name| require file_name}
|
91
91
|
|
92
|
-
if defined?(Rails::Railtie)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
else
|
92
|
+
# if defined?(Rails::Railtie)
|
93
|
+
# module Foreigner
|
94
|
+
# class Railtie < Rails::Railtie
|
95
|
+
# initializer 'migration-validators.load' do
|
96
|
+
# ActiveSupport.on_load :active_record do
|
97
|
+
# MigrationValidators.load!
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
# else
|
103
103
|
MigrationValidators.load!
|
104
|
-
end
|
104
|
+
# end
|
105
105
|
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-core
|
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: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1
|
19
|
+
version: '4.1'
|
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: 4.1
|
26
|
+
version: '4.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.1
|
33
|
+
version: '4.1'
|
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: 4.1
|
40
|
+
version: '4.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: i18n
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,38 +56,40 @@ dependencies:
|
|
56
56
|
name: jeweler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.0
|
61
|
+
version: '2.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.0
|
68
|
+
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
description: Migration Validators project
|
82
|
+
version: '1.3'
|
83
|
+
description: Migration Validators project. Core classes
|
84
84
|
email: vprokopchuk@gmail.com
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files:
|
88
88
|
- LICENSE.txt
|
89
|
-
- README.
|
89
|
+
- README.md
|
90
90
|
files:
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
91
93
|
- lib/migration_validators/active_record/base.rb
|
92
94
|
- lib/migration_validators/active_record/connection_adapters/abstract_adapter.rb
|
93
95
|
- lib/migration_validators/active_record/connection_adapters/native_adapter.rb
|
@@ -110,8 +112,6 @@ files:
|
|
110
112
|
- lib/migration_validators/core/validator_router.rb
|
111
113
|
- lib/mv-core.rb
|
112
114
|
- lib/options.rb
|
113
|
-
- LICENSE.txt
|
114
|
-
- README.rdoc
|
115
115
|
homepage: http://github.com/vprokopchuk256/mv-core
|
116
116
|
licenses:
|
117
117
|
- MIT
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.4.2
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Migration Validators project core classes
|
data/README.rdoc
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
= Abbreviations
|
2
|
-
|
3
|
-
MV - Migration Validators Projects. All gems that belongs to that project are prefixed with mv-*
|
4
|
-
|
5
|
-
= Project goals
|
6
|
-
|
7
|
-
Main goal of the project is to allow developer to express database constraints in a Ruby like manner.
|
8
|
-
|
9
|
-
= mv-core
|
10
|
-
|
11
|
-
mv-core is a set of core classes that are used everywhere across Migration Validators project gems.
|
12
|
-
|
13
|
-
= Install
|
14
|
-
|
15
|
-
PostgreSQL:
|
16
|
-
|
17
|
-
gem install mv-postgresql
|
18
|
-
|
19
|
-
MySQL:
|
20
|
-
|
21
|
-
gem install mv-mysql
|
22
|
-
|
23
|
-
SQLite:
|
24
|
-
|
25
|
-
gem install mv-sqlite
|
26
|
-
|
27
|
-
= Usage
|
28
|
-
|
29
|
-
Create new table:
|
30
|
-
|
31
|
-
create_table do |t|
|
32
|
-
t.string :str_column, :validates => {:uniqueness => true, :inclusion => {:in => 1..3}}
|
33
|
-
t.column :column_name, :integer, :validates => {:exclusion => {:in => [1,2,3]}}
|
34
|
-
end
|
35
|
-
|
36
|
-
Modify existing table:
|
37
|
-
|
38
|
-
change_table do |t|
|
39
|
-
t.change :str_column, :integer, :validates => {:exclusion => {:in => [1,2,3]}}
|
40
|
-
t.change_validates :column_name, :inclusion => {:in => 1..3}
|
41
|
-
end
|
42
|
-
|
43
|
-
Update existing table with new validators:
|
44
|
-
|
45
|
-
validate_column :table_name, :str_column, :exclusion => {:in => [1,2,3]}
|
46
|
-
|
47
|
-
Remove existing validators:
|
48
|
-
|
49
|
-
change_table do |t|
|
50
|
-
t.change :str_column, :integer, :validates => {:exclusion => false}
|
51
|
-
end
|
52
|
-
validate_column table_name, :str_column, :exclusion => false
|
53
|
-
|
54
|
-
Define the way how validator will be created:
|
55
|
-
|
56
|
-
as trigger:
|
57
|
-
|
58
|
-
validate_column :table_name, :str_column, :validates => {:uniqueness => true, :as => :trigger }
|
59
|
-
|
60
|
-
as check constraint:
|
61
|
-
|
62
|
-
validate_column :table_name, :str_column, :validates => {:uniqueness => true, :as => :check }
|
63
|
-
|
64
|
-
Define event that will be validates:
|
65
|
-
|
66
|
-
while new record creation:
|
67
|
-
|
68
|
-
validate_column :table_name, :str_column, :validates => {:uniqueness => true, :on => :create }
|
69
|
-
|
70
|
-
or while updating of existing record:
|
71
|
-
|
72
|
-
validate_column :table_name, :str_column, :validates => {:uniqueness => true, :on => :update }
|
73
|
-
|
74
|
-
Supported validators and their properties might vary from one db driver to another. See detailed properties description in correspondent driver section.
|
75
|
-
|
76
|
-
= Drivers
|
77
|
-
|
78
|
-
Currently there are drivers for MySQL, PostgreSQL and SQLite RDBMS
|
79
|
-
|
80
|
-
So - see detailed info here:
|
81
|
-
|
82
|
-
PostgreSQL: https://github.com/vprokopchuk256/mv-postgresql
|
83
|
-
|
84
|
-
MySQL: https://github.com/vprokopchuk256/mv-mysql
|
85
|
-
|
86
|
-
SQLite: https://github.com/vprokopchuk256/mv-sqlite
|
87
|
-
|
88
|
-
|
89
|
-
== Contributing to mv-core
|
90
|
-
|
91
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
92
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
93
|
-
* Fork the project
|
94
|
-
* Start a feature/bugfix branch
|
95
|
-
* Commit and push until you are happy with your contribution
|
96
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
97
|
-
* 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.
|
98
|
-
|
99
|
-
== Copyright
|
100
|
-
|
101
|
-
Copyright (c) 2011 Valeriy Prokopchuk. See LICENSE.txt for
|
102
|
-
further details.
|