Class: Brut::CLI::Apps::DB::Create
- 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
98 99 100 101 102 103 104 105 |
# File 'lib/brut/cli/apps/db.rb', line 98 def execute connection = Sequel.connect(Brut.container.database_url) out.puts "Database already exists" connection.disconnect 0 rescue => ex handle_bootstrap_exception(ex) end |
#handle_bootstrap_exception(ex) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/brut/cli/apps/db.rb', line 71 def handle_bootstrap_exception(ex) case ex when Sequel::DatabaseConnectionError uri_no_database = URI(Brut.container.database_url.to_s) database_name = uri_no_database.path.gsub(/^\//,"") uri_no_database.path = "" begin connection = Sequel.connect(uri_no_database.to_s) out.puts "#{database_name} does not exit. Creating..." connection.run("CREATE DATABASE \"#{database_name}\"") connection.disconnect rescue => ex err.puts ex. end stop_execution when Sequel::DatabaseError if ex.cause.kind_of?(PG::UndefinedTable) out.puts ex. out.puts "Migrations need to be run" continue_execution else super end else super end end |