mv-core 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 +67 -12
- data/lib/mv-core.rb +18 -100
- data/lib/mv/core/active_record/connection_adapters/abstract_adapter_decorator.rb +51 -0
- data/lib/mv/core/active_record/connection_adapters/table_decorator.rb +13 -0
- data/lib/mv/core/active_record/connection_adapters/table_definition_decorator.rb +21 -0
- data/lib/mv/core/active_record/migration/command_recorder_decorator.rb +13 -0
- data/lib/mv/core/active_record/migration_decorator.rb +14 -0
- data/lib/mv/core/active_record/schema_decorator.rb +16 -0
- data/lib/mv/core/active_record/schema_dumper_decorator.rb +29 -0
- data/lib/mv/core/constraint/base.rb +33 -0
- data/lib/mv/core/constraint/builder/base.rb +45 -0
- data/lib/mv/core/constraint/builder/factory.rb +42 -0
- data/lib/mv/core/constraint/builder/index.rb +50 -0
- data/lib/mv/core/constraint/builder/trigger.rb +13 -0
- data/lib/mv/core/constraint/description.rb +24 -0
- data/lib/mv/core/constraint/factory.rb +33 -0
- data/lib/mv/core/constraint/index.rb +13 -0
- data/lib/mv/core/constraint/trigger.rb +20 -0
- data/lib/mv/core/db/helpers/column_validators.rb +57 -0
- data/lib/mv/core/db/helpers/table_validators.rb +38 -0
- data/lib/mv/core/db/migration_validator.rb +26 -0
- data/lib/mv/core/error.rb +25 -0
- data/lib/mv/core/migration/base.rb +94 -0
- data/lib/mv/core/migration/operations/add_column.rb +27 -0
- data/lib/mv/core/migration/operations/change_column.rb +31 -0
- data/lib/mv/core/migration/operations/drop_table.rb +21 -0
- data/lib/mv/core/migration/operations/factory.rb +20 -0
- data/lib/mv/core/migration/operations/list.rb +28 -0
- data/lib/mv/core/migration/operations/remove_column.rb +22 -0
- data/lib/mv/core/migration/operations/rename_column.rb +26 -0
- data/lib/mv/core/migration/operations/rename_table.rb +25 -0
- data/lib/mv/core/presenter/constraint/description.rb +26 -0
- data/lib/mv/core/presenter/validation/base.rb +73 -0
- data/lib/mv/core/railtie.rb +40 -0
- data/lib/mv/core/route/base.rb +25 -0
- data/lib/mv/core/route/index.rb +17 -0
- data/lib/mv/core/route/trigger.rb +22 -0
- data/lib/mv/core/router.rb +33 -0
- data/lib/mv/core/services/compare_constraint_arrays.rb +50 -0
- data/lib/mv/core/services/compare_constraints.rb +31 -0
- data/lib/mv/core/services/create_constraints.rb +30 -0
- data/lib/mv/core/services/create_migration_validators_table.rb +31 -0
- data/lib/mv/core/services/delete_constraints.rb +30 -0
- data/lib/mv/core/services/load_constraints.rb +45 -0
- data/lib/mv/core/services/say_constraints_diff.rb +66 -0
- data/lib/mv/core/services/show_constraints.rb +41 -0
- data/lib/mv/core/services/synchronize_constraints.rb +54 -0
- data/lib/mv/core/services/uninstall.rb +25 -0
- data/lib/mv/core/validation/absence.rb +35 -0
- data/lib/mv/core/validation/base.rb +98 -0
- data/lib/mv/core/validation/builder/absence.rb +19 -0
- data/lib/mv/core/validation/builder/base.rb +58 -0
- data/lib/mv/core/validation/builder/exclusion.rb +42 -0
- data/lib/mv/core/validation/builder/factory.rb +43 -0
- data/lib/mv/core/validation/builder/inclusion.rb +42 -0
- data/lib/mv/core/validation/builder/length.rb +68 -0
- data/lib/mv/core/validation/builder/presence.rb +19 -0
- data/lib/mv/core/validation/builder/uniqueness.rb +19 -0
- data/lib/mv/core/validation/exclusion.rb +27 -0
- data/lib/mv/core/validation/factory.rb +56 -0
- data/lib/mv/core/validation/inclusion.rb +27 -0
- data/lib/mv/core/validation/length.rb +59 -0
- data/lib/mv/core/validation/presence.rb +25 -0
- data/lib/mv/core/validation/uniqueness.rb +45 -0
- data/lib/mv/core/validators/array_validator.rb +5 -0
- data/lib/mv/core/validators/integers_array_validator.rb +12 -0
- data/lib/mv/core/validators/valid_validator.rb +9 -0
- metadata +158 -30
- data/lib/migration_validators/active_record/base.rb +0 -29
- data/lib/migration_validators/active_record/connection_adapters/abstract_adapter.rb +0 -38
- data/lib/migration_validators/active_record/connection_adapters/native_adapter.rb +0 -129
- data/lib/migration_validators/active_record/connection_adapters/table.rb +0 -17
- data/lib/migration_validators/active_record/connection_adapters/table_definition.rb +0 -33
- data/lib/migration_validators/active_record/migration.rb +0 -25
- data/lib/migration_validators/active_record/schema.rb +0 -32
- data/lib/migration_validators/active_record/schema_dumper.rb +0 -25
- data/lib/migration_validators/adapters/base.rb +0 -15
- data/lib/migration_validators/adapters/containers.rb +0 -100
- data/lib/migration_validators/adapters/routing.rb +0 -102
- data/lib/migration_validators/adapters/syntax.rb +0 -51
- data/lib/migration_validators/adapters/validator_definitions.rb +0 -132
- data/lib/migration_validators/core/adapter_wrapper.rb +0 -88
- data/lib/migration_validators/core/db_validator.rb +0 -131
- data/lib/migration_validators/core/statement_builder.rb +0 -61
- data/lib/migration_validators/core/validator_constraints_list.rb +0 -32
- data/lib/migration_validators/core/validator_container.rb +0 -110
- data/lib/migration_validators/core/validator_definition.rb +0 -91
- data/lib/migration_validators/core/validator_router.rb +0 -45
- data/lib/options.rb +0 -7
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mv/core/db/helpers/column_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class AddColumn
|
8
|
+
include Mv::Core::Db::Helpers::ColumnValidators
|
9
|
+
|
10
|
+
attr_reader :opts
|
11
|
+
|
12
|
+
def initialize(table_name, column_name, opts = nil)
|
13
|
+
self.table_name = table_name
|
14
|
+
self.column_name = column_name
|
15
|
+
@opts = opts || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
opts.each do |validation_type, validator_opts|
|
20
|
+
create_column_validator(validation_type, validator_opts)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'mv/core/db/helpers/column_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class ChangeColumn
|
8
|
+
include Mv::Core::Db::Helpers::ColumnValidators
|
9
|
+
|
10
|
+
attr_reader :opts
|
11
|
+
|
12
|
+
def initialize(table_name, column_name, opts = nil)
|
13
|
+
self.table_name = table_name
|
14
|
+
self.column_name = column_name
|
15
|
+
@opts = opts || {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
if opts.present?
|
20
|
+
opts.each do |validation_type, validator_opts|
|
21
|
+
update_column_validator(validation_type, validator_opts)
|
22
|
+
end
|
23
|
+
elsif column_validators.exists?
|
24
|
+
delete_column_validator
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mv/core/db/helpers/table_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class DropTable
|
8
|
+
include Mv::Core::Db::Helpers::TableValidators
|
9
|
+
|
10
|
+
def initialize(table_name)
|
11
|
+
self.table_name = table_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
delete_table_validators
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mv/core/migration/operations/add_column'
|
2
|
+
require 'mv/core/migration/operations/change_column'
|
3
|
+
require 'mv/core/migration/operations/drop_table'
|
4
|
+
require 'mv/core/migration/operations/remove_column'
|
5
|
+
require 'mv/core/migration/operations/rename_column'
|
6
|
+
require 'mv/core/migration/operations/rename_table'
|
7
|
+
|
8
|
+
module Mv
|
9
|
+
module Core
|
10
|
+
module Migration
|
11
|
+
module Operations
|
12
|
+
class Factory
|
13
|
+
def create_operation operation_name, *args
|
14
|
+
"Mv::Core::Migration::Operations::#{operation_name.to_s.camelize}".constantize.new(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
module Migration
|
4
|
+
module Operations
|
5
|
+
class List
|
6
|
+
attr_reader :operations
|
7
|
+
|
8
|
+
def initialize()
|
9
|
+
@operations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_operation(operation)
|
13
|
+
operations << operation
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
operations.each(&:execute)
|
18
|
+
operations.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
def tables
|
22
|
+
operations.collect(&:table_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mv/core/db/helpers/column_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class RemoveColumn
|
8
|
+
include Mv::Core::Db::Helpers::ColumnValidators
|
9
|
+
|
10
|
+
def initialize(table_name, column_name)
|
11
|
+
self.table_name = table_name
|
12
|
+
self.column_name = column_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
delete_column_validator
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'mv/core/db/helpers/column_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class RenameColumn
|
8
|
+
include Mv::Core::Db::Helpers::ColumnValidators
|
9
|
+
|
10
|
+
attr_reader :new_column_name
|
11
|
+
|
12
|
+
def initialize(table_name, column_name, new_column_name)
|
13
|
+
self.table_name = table_name
|
14
|
+
self.column_name = column_name
|
15
|
+
|
16
|
+
@new_column_name = new_column_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute
|
20
|
+
rename_column(new_column_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mv/core/db/helpers/table_validators'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Migration
|
6
|
+
module Operations
|
7
|
+
class RenameTable
|
8
|
+
include Mv::Core::Db::Helpers::TableValidators
|
9
|
+
|
10
|
+
attr_reader :new_table_name
|
11
|
+
|
12
|
+
def initialize(table_name, new_table_name)
|
13
|
+
self.table_name = table_name
|
14
|
+
|
15
|
+
@new_table_name = new_table_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
update_table_validators(new_table_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
module Presenter
|
4
|
+
module Constraint
|
5
|
+
class Description
|
6
|
+
attr_reader :description
|
7
|
+
|
8
|
+
delegate :name, :type, :options, to: :description
|
9
|
+
|
10
|
+
def initialize(description)
|
11
|
+
@description = description
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
params = [
|
16
|
+
"\"#{name}\"",
|
17
|
+
options.collect{|key, value| "#{key}: :#{value}"}
|
18
|
+
].flatten.join(', ')
|
19
|
+
|
20
|
+
"#{type}(#{params})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
module Presenter
|
4
|
+
module Validation
|
5
|
+
class Base
|
6
|
+
attr_reader :validation
|
7
|
+
|
8
|
+
delegate :table_name, :column_name, :options, to: :validation
|
9
|
+
|
10
|
+
def initialize(validation)
|
11
|
+
@validation = validation
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
options_as_str = options.blank? ? 'true' : "{ #{options_str} }"
|
16
|
+
"validates(\"#{table_name}\", \"#{column_name}\", #{validation_type}: #{options_as_str})".squish
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def validation_type
|
22
|
+
validation.class.name.demodulize.underscore
|
23
|
+
end
|
24
|
+
|
25
|
+
def options_str
|
26
|
+
options.collect do |key, value|
|
27
|
+
"#{key}: #{value_to_str(value)}"
|
28
|
+
end.join(', ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def value_to_str value
|
32
|
+
return ":#{value}" if value.is_a?(Symbol)
|
33
|
+
return time_to_str(value) if value.is_a?(Time)
|
34
|
+
return datetime_to_str(value) if value.is_a?(DateTime)
|
35
|
+
return date_to_str(value) if value.is_a?(Date)
|
36
|
+
return range_to_str(value) if value.is_a?(Range)
|
37
|
+
return array_to_str(value) if value.is_a?(Array)
|
38
|
+
return "'#{value}'" if value.is_a?(String)
|
39
|
+
return "/#{value.source}/" if value.is_a?(Regexp)
|
40
|
+
value.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def array_to_str value
|
44
|
+
"[#{value.collect{ |value| value_to_str(value) }.join(', ')}]"
|
45
|
+
end
|
46
|
+
|
47
|
+
def range_to_str value
|
48
|
+
[
|
49
|
+
value_to_str(value.first),
|
50
|
+
value.exclude_end? ? '...' : '..',
|
51
|
+
value_to_str(value.last)
|
52
|
+
].join
|
53
|
+
end
|
54
|
+
|
55
|
+
def regexp_to_str value
|
56
|
+
end
|
57
|
+
|
58
|
+
def time_to_str value
|
59
|
+
"Time.new(#{value.strftime("%Y, %-m, %-d, %-H, %-M, %-S")})"
|
60
|
+
end
|
61
|
+
|
62
|
+
def datetime_to_str value
|
63
|
+
"DateTime.new(#{value.utc.strftime("%Y, %-m, %-d, %-H, %-M, %-S")})"
|
64
|
+
end
|
65
|
+
|
66
|
+
def date_to_str value
|
67
|
+
"Date.new(#{value.strftime("%Y, %-m, %-d")})"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'mv/core/services/uninstall'
|
2
|
+
require 'mv/core/services/delete_constraints'
|
3
|
+
require 'mv/core/services/create_constraints'
|
4
|
+
require 'mv/core/services/show_constraints'
|
5
|
+
require 'mv/core/services/create_migration_validators_table'
|
6
|
+
|
7
|
+
module Mv
|
8
|
+
module Core
|
9
|
+
class Railtie < ::Rails::Railtie
|
10
|
+
rake_tasks do
|
11
|
+
namespace :mv do
|
12
|
+
task :uninstall => :environment do
|
13
|
+
STDOUT.puts "Uninstall is irreversible operation. All constraints descriptions and declarations will be removed.
|
14
|
+
You will have to either load schema or re - run all migrations to restore that info. Please enter YES if you want to continue anyway: ".squish
|
15
|
+
|
16
|
+
if STDIN.gets.chomp == "YES"
|
17
|
+
Mv::Core::Services::Uninstall.new.execute
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task :install => :environment do
|
22
|
+
Mv::Core::Services::CreateMigrationValidatorsTable.new.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
task :show_constraints, [:tables] => :environment do |task, args|
|
26
|
+
Mv::Core::Services::ShowConstraints.new((args[:tables] || '').split(/\s+/)).execute
|
27
|
+
end
|
28
|
+
|
29
|
+
task :delete_constraints, [:tables] => :environment do |task, args|
|
30
|
+
Mv::Core::Services::DeleteConstraints.new((args[:tables] || '').split(/\s+/)).execute
|
31
|
+
end
|
32
|
+
|
33
|
+
task :create_constraints, [:tables] => :environment do |task, args|
|
34
|
+
Mv::Core::Services::CreateConstraints.new((args[:tables] || '').split(/\s+/)).execute
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'mv/core/constraint/description'
|
2
|
+
|
3
|
+
module Mv
|
4
|
+
module Core
|
5
|
+
module Route
|
6
|
+
class Base
|
7
|
+
attr_reader :validation
|
8
|
+
|
9
|
+
def initialize(validation)
|
10
|
+
@validation = validation
|
11
|
+
end
|
12
|
+
|
13
|
+
def route
|
14
|
+
[Mv::Core::Constraint::Description.new(validation.index_name, :index)]
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def description(name, type, opts = {})
|
20
|
+
Mv::Core::Constraint::Description.new(name, type, opts)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
module Route
|
4
|
+
class Index
|
5
|
+
attr_reader :validation
|
6
|
+
|
7
|
+
def initialize(validation)
|
8
|
+
@validation = validation
|
9
|
+
end
|
10
|
+
|
11
|
+
def route
|
12
|
+
[Mv::Core::Constraint::Description.new(validation.index_name, :index)]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mv
|
2
|
+
module Core
|
3
|
+
module Route
|
4
|
+
class Trigger
|
5
|
+
attr_reader :validation
|
6
|
+
|
7
|
+
def initialize(validation)
|
8
|
+
@validation = validation
|
9
|
+
end
|
10
|
+
|
11
|
+
def route
|
12
|
+
[validation.create? && Mv::Core::Constraint::Description.new(validation.create_trigger_name,
|
13
|
+
:trigger,
|
14
|
+
{ event: :create }),
|
15
|
+
validation.update? && Mv::Core::Constraint::Description.new(validation.update_trigger_name,
|
16
|
+
:trigger,
|
17
|
+
{ event: :update })].select(&:present?)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'mv/core/constraint/description'
|
2
|
+
|
3
|
+
require 'mv/core/route/trigger'
|
4
|
+
require 'mv/core/route/index'
|
5
|
+
|
6
|
+
module Mv
|
7
|
+
module Core
|
8
|
+
class Router
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def route validation
|
12
|
+
routing_table[validation.as.to_sym].new(validation).route
|
13
|
+
end
|
14
|
+
|
15
|
+
def define_route as, klass
|
16
|
+
routing_table[as.to_sym] = klass
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def routing_table
|
22
|
+
@routing_table ||= {
|
23
|
+
trigger: Mv::Core::Route::Trigger,
|
24
|
+
index: Mv::Core::Route::Index
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
delegate :route, :define_route, to: :instance
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|