Class: DbAgile::Command::Schema::Check

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

Overview

Check a database schema

Usage: dba #DbAgile::Command#command_name [options] [SCHEMA.yaml|announced|effective|physical]

This command informs you about bad smells and good practices with relational schemas (i.e. forgetting to create keys, not providing unique constraint names, and so on).

dba #DbAgile::Command#command_name SCHEMA.yaml

Load the schema from file and check it, printing advices and errors on the 
message console. The command does not connect any database in this mode.

dba #DbAgile::Command#command_name [announced|effective|physical]

Checks a schema of the current database. Announced schema is implicit without
any argument. This command uses a fallback chain (announced -> effective -> 
physical) and has no side-effect on the database itself (read-only).

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



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

def add_options(opt)
  self.check_schemas = false
  add_stdin_options(opt)
end

#execute_commandObject

Executes the command



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dbagile/command/schema/check.rb', line 40

def execute_command
  with_schema do |schema|
    errors = schema.check!(false)
    say("\n")
    if errors.empty?
      say("Valid schema (#{schema.schema_identifier.inspect})!", :green)
      say("\n")
      [ schema, errors ]
    else
      say("Invalid schema (#{schema.schema_identifier.inspect}):", :red)
      errors.error_messages.each{|m| say("  * #{m}")}
      say("\n")
      [ schema, errors ]
    end
  end
end

#kind_of_schema_argumentsObject

Returns :single



29
30
31
# File 'lib/dbagile/command/schema/check.rb', line 29

def kind_of_schema_arguments
  :single
end