Class: DbAgile::Core::Schema::DatabaseSchema

Inherits:
Composite show all
Includes:
Enumerable
Defined in:
lib/dbagile/core/schema/database_schema.rb

Instance Attribute Summary collapse

Attributes inherited from SchemaObject

#parent, #status

Instance Method Summary collapse

Methods inherited from Composite

#[], #[]=, #each_part, #empty?, #look_same_as?, #part_keys, #parts, #size, #to_s, #visit

Methods inherited from SchemaObject

#ancestors, #attribute?, #builder_args, #builder_handler, #candidate_key?, #composite?, #constraint?, #foreign_key?, #index?, #logical?, #outside_dependencies, #outside_dependents, #part?, #physical?, #primary_key?, #relation_variable, #relvar?, #relview?

Constructor Details

#initialize(schema_identifier = nil, parts = _default_parts) ⇒ DatabaseSchema

Creates a schema instance



12
13
14
15
16
# File 'lib/dbagile/core/schema/database_schema.rb', line 12

def initialize(schema_identifier = nil, parts = _default_parts)
  @schema_identifier = schema_identifier
  super(parts)
  @insert_order = [:logical, :physical]
end

Instance Attribute Details

#schema_identifierObject

Identifier of this schema



9
10
11
# File 'lib/dbagile/core/schema/database_schema.rb', line 9

def schema_identifier
  @schema_identifier
end

Instance Method Details

#_default_partsObject

See Also:

  • Composite#_default_parts


29
30
31
32
# File 'lib/dbagile/core/schema/database_schema.rb', line 29

def _default_parts
  {:logical  => Schema::Logical.new,
   :physical => Schema::Physical.new}
end

#_install_eigenclass_methods?Boolean

Returns:

  • (Boolean)

See Also:

  • Composite#_install_eigenclass_methods?


24
25
26
# File 'lib/dbagile/core/schema/database_schema.rb', line 24

def _install_eigenclass_methods?
  true
end

#_strip!Object

Strips this schema



35
36
37
38
# File 'lib/dbagile/core/schema/database_schema.rb', line 35

def _strip!
  logical._strip!
  self
end

#check!(raise_on_error = true) ⇒ Object

Applies schema checking and raises a SchemaSemanticsError if something is wrong.



87
88
89
90
91
92
93
94
95
# File 'lib/dbagile/core/schema/database_schema.rb', line 87

def check!(raise_on_error = true)
  errors = SchemaSemanticsError.new(self)
  _semantics_check(SchemaSemanticsError, errors)
  if raise_on_error and not(errors.empty?)
    raise errors
  else
    errors
  end
end

#dependencies(include_parent = false) ⇒ Object

Returns an array with part dependencies



45
46
47
# File 'lib/dbagile/core/schema/database_schema.rb', line 45

def dependencies(include_parent = false)
  []
end

#dupObject

See Also:



55
56
57
# File 'lib/dbagile/core/schema/database_schema.rb', line 55

def dup
  DatabaseSchema.new(schema_identifier, _dup_parts)
end

#filter(options = {}, &filter_block) ⇒ Object

Applies schema filtering



115
116
117
# File 'lib/dbagile/core/schema/database_schema.rb', line 115

def filter(options = {}, &filter_block)
  Schema::filter(self, options, &filter_block)
end

#looks_valid?Boolean

Convenient method for schema.check!(false).empty?

Returns:

  • (Boolean)


98
99
100
# File 'lib/dbagile/core/schema/database_schema.rb', line 98

def looks_valid?
  check!(false).empty?
end

#merge(other) ⇒ Object Also known as: +

Applies schema merging



109
110
111
# File 'lib/dbagile/core/schema/database_schema.rb', line 109

def merge(other)
  Schema::merge(self, other)
end

#minus(other) ⇒ Object Also known as: -

Applies schema minus



103
104
105
# File 'lib/dbagile/core/schema/database_schema.rb', line 103

def minus(other)
  Schema::minus(self, other)
end

#schemaObject

Overrided to return self.



50
51
52
# File 'lib/dbagile/core/schema/database_schema.rb', line 50

def schema
  self
end

#split(options = {}, &split_block) ⇒ Object

Applies schema splitting



120
121
122
# File 'lib/dbagile/core/schema/database_schema.rb', line 120

def split(options = {}, &split_block)
  Schema::split(self, options, &split_block)
end

#to_yaml(opts = {}) ⇒ Object Also known as: inspect

Dumps the schema to YAML



65
66
67
# File 'lib/dbagile/core/schema/database_schema.rb', line 65

def to_yaml(opts = {})
  YAML::dump_stream({'logical' => logical}, {'physical' => physical})
end

#yaml_display(env, options = {}, colors = DbAgile::Core::Schema::STATUS_TO_COLOR, indent = 0) ⇒ Object

Returns a yaml string



72
73
74
75
76
77
78
79
80
# File 'lib/dbagile/core/schema/database_schema.rb', line 72

def yaml_display(env, 
                 options = {}, 
                 colors = DbAgile::Core::Schema::STATUS_TO_COLOR, 
                 indent = 0)
  env.display("---\nlogical:")
  logical.yaml_display(env, options, colors, indent + 1)
  env.display("\n---\nphysical:")
  physical.yaml_display(env, options, colors, indent + 1)
end