Class: NcsNavigator::Warehouse::CLI
- Inherits:
-
Thor
- Object
- Thor
- NcsNavigator::Warehouse::CLI
- Defined in:
- lib/ncs_navigator/warehouse/cli.rb
Instance Method Summary collapse
- #clone_working ⇒ Object
- #compare ⇒ Object
- #count ⇒ Object
- #create_schema ⇒ Object
- #emit_xml(filename = nil) ⇒ Object
- #etl ⇒ Object
Instance Method Details
#clone_working ⇒ Object
41 42 43 44 45 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 41 def clone_working db = DatabaseInitializer.new(configuration) db.set_up_repository(:both) db.clone_working_to_reporting or exit(1) end |
#compare ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 166 def compare if ['warehouse-a'] ['config'] = ['warehouse-a'] end config_a = configuration config_b = Configuration.from_file(['warehouse-b']) Comparator.new(config_a, config_b, ).compare end |
#count ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 113 def count db = DatabaseInitializer.new(configuration) db.set_up_repository(['working'] ? :working : :reporting) configuration.shell.clear_line_then_say("Loading MDES models...") configuration.models_module configuration.shell.clear_line_then_say("Counting...") counts = configuration.models_module.mdes_order. collect { |model| [model.mdes_table_name, model.count] } unless ['include-empty'] counts.reject! { |table, count| count == 0 } end if counts.empty? configuration.shell.clear_line_and_say("All tables empty.\n") exit 1 else max_lengths = counts.inject([0, 0]) { |lengths, row| lengths.zip(row.collect { |e| e.to_s.size }).collect { |sizes| sizes.max } } configuration.shell.clear_line_and_say('') counts.each do |table_name, count| configuration.shell.say_line "%#{max_lengths[0]}s %d" % [table_name, count] end end end |
#create_schema ⇒ Object
34 35 36 37 38 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 34 def create_schema db = DatabaseInitializer.new(configuration) db.set_up_repository(:working) db.replace_schema end |
#emit_xml(filename = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 69 def emit_xml(filename=nil) use_database [:tables] = [:tables].try(:split, /\s*,\s*/) # need to prevent the addition of a :filters key entirely in order # to detect --no-filters, which shows up as :filters=>nil. if [:filters] [:filters] = [:filters].split(/\s*,\s*/) end XmlEmitter.new(configuration, filename, ).emit_xml end |
#etl ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ncs_navigator/warehouse/cli.rb', line 92 def etl db = DatabaseInitializer.new(configuration) db.set_up_repository(:both) db.replace_schema unless [:preserve] success = TransformLoad.new(configuration).run if success || ['force'] db.clone_working_to_reporting or exit(1) else configuration.shell.say_line "There were errors during ETL. Reporting database not updated." configuration.shell.say_line "See the log and the database table wh_transform_error for more details." exit 1 end end |