Class: DbAgile::Command::Schema::Merge

Inherits:
DbAgile::Command show all
Includes:
Commons
Defined in:
lib/dbagile/command/schema/merge.rb

Overview

Merge a list of schemas

Usage: dba #DbAgile::Command#command_name SCHEMA_ARG, …

This command merges all schema in arguments into a single schema and dumps the result in YAML on the output console. Schema arguments may be schema files or schemas installed on the current database [announced|effective|physical]. This command uses the fallback chain (announced -> effective -> physical) and has no side-effect on the database itself (read-only).

NOTE: Schema-checking is on by default and applied on the resulting schema.

This which may lead to checking errors when reverse engineering poorly 
designed databases. Doing so immediately informs you about a potential 
problem.

Use --no-check to bypass schema checking. See also schema:check.

Constant Summary

Constants inherited from DbAgile::Command

CATEGORIES, CATEGORY_NAMES

Instance Attribute Summary

Attributes included from Commons

#check_schemas, #on_stdin, #schema_arguments

Attributes inherited from DbAgile::Command

#environment

Attributes included from ClassMethods

#description, #summary, #usage

Instance Method Summary collapse

Methods included from Commons

#add_check_options, #add_stdin_options, #load_schema, #normalize_pending_arguments, #normalize_schema_argument, #normalize_schema_arguments, #with_schemas

Methods inherited from DbAgile::Command

#category, #check_command, #command_name, #description, #initialize, #normalize_pending_arguments, #options, #run, #set_default_options, #show_help, #summary, #unsecure_run, #usage

Methods included from ClassMethods

#build_command_options, #build_me, #category, #command_for, #command_name, #command_name_of, #each_subclass, #inherited, #ruby_method_for, #subclasses

Methods included from Robust

#ambigous_argument_list!, #assumption_error!, #bad_argument_list!, #has_command!, #is_in!, #valid_argument_list!, #valid_read_file!

Methods included from DbAgile::Core::IO::Robustness

#has_database!, #valid_database_name!, #valid_database_uri!, #valid_schema_files!

Constructor Details

This class inherits a constructor from DbAgile::Command

Instance Method Details

#add_options(opt) ⇒ Object

Contribute to options



27
28
29
30
31
# File 'lib/dbagile/command/schema/merge.rb', line 27

def add_options(opt)
  opt.separator nil
  opt.separator "Options:"
  add_check_options(opt)
end

#execute_commandObject

Executes the command



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dbagile/command/schema/merge.rb', line 39

def execute_command
  with_schemas(false) do |schemas|
    empty = DbAgile::Core::Schema::EMPTY_SCHEMA
    result = schemas.inject(empty){|memo,schema| memo + schema}
    if self.check_schemas
      result.check!
      say("# And the result is valid!", :green)
    end
    flush(result.to_yaml)
    result
  end
end

#kind_of_schema_argumentsObject

Returns :single



34
35
36
# File 'lib/dbagile/command/schema/merge.rb', line 34

def kind_of_schema_arguments
  :multiple
end