Class: Brut::CLI::Apps::DB::Drop
- Defined in:
- lib/brut/cli/apps/db.rb
Instance Method Summary collapse
Methods inherited from Command
#after_bootstrap, args, #args, #before_execute, command_name, default_env, #delegate_to_commands, description, detailed_description, env_var, #err, #global_options, #initialize, name_matches?, option_parser, #options, opts, #out, requires_project_env, requires_project_env?, #system!
Methods included from Framework::Errors
Methods included from I18n::ForCLI
Methods included from I18n::BaseMethods
#l, #t, #t_direct, #this_field_value
Methods included from ExecutionResults
#abort_execution, #as_execution_result, #cli_usage_error, #continue_execution, #show_cli_usage, #stop_execution
Constructor Details
This class inherits a constructor from Brut::CLI::Command
Instance Method Details
#execute ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/brut/cli/apps/db.rb', line 128 def execute uri_no_database = URI(Brut.container.database_url.to_s) database_name = uri_no_database.path.gsub(/^\//,"") uri_no_database.path = "" out.puts "Database exists. Dropping..." begin Brut.container.sequel_db_handle.disconnect rescue Sequel::DatabaseConnectionError end connection = Sequel.connect(uri_no_database.to_s) connection.run("DROP DATABASE IF EXISTS \"#{database_name}\"") connection.disconnect 0 rescue => ex handle_bootstrap_exception(ex) end |
#handle_bootstrap_exception(ex) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/brut/cli/apps/db.rb', line 112 def handle_bootstrap_exception(ex) case ex when Sequel::DatabaseConnectionError out.puts "Database does not exist" stop_execution when Sequel::DatabaseError if ex.cause.kind_of?(PG::UndefinedTable) continue_execution else super end else super end end |