Class: Brut::CLI::Apps::DB::Drop
Instance Attribute Summary
#parent_command
Instance Method Summary
collapse
#accepts, #args_description, #argv, #commands, #default_command, #default_command_class, #env, #env_vars, #execute, #name, #options, #opts, #puts, #stderr, #stdin, #stdout, #system!
Instance Method Details
#bootstrap? ⇒ Boolean
89
|
# File 'lib/brut/cli/apps/db.rb', line 89
def bootstrap? = false
|
#default_rack_env ⇒ Object
88
|
# File 'lib/brut/cli/apps/db.rb', line 88
def default_rack_env = "development"
|
#description ⇒ Object
87
|
# File 'lib/brut/cli/apps/db.rb', line 87
def description = "Drop the database if it exists"
|
#run ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/brut/cli/apps/db.rb', line 91
def run
uri_no_database = URI(Brut.container.database_url.to_s)
database_name = uri_no_database.path.gsub(/^\//,"")
uri_no_database.path = ""
begin
Brut.container.sequel_db_handle.disconnect
stdout.puts "Database #{database_name} exists. Dropping..."
connection = Sequel.connect(uri_no_database.to_s)
connection.run("DROP DATABASE IF EXISTS \"#{database_name}\"")
connection.disconnect
0
rescue Sequel::DatabaseConnectionError => ex
begin
connection = Sequel.connect(uri_no_database.to_s)
stdout.puts "Database #{database_name} does not exist"
connection.disconnect
0
rescue Sequel::DatabaseConnectionError => ex2
stderr.puts "Database server is not running at #{uri_no_database}: #{ex2.message}"
stderr.puts "This could be a problem with your dev environment generally, or your .env.test or .env.test.local files"
1
end
end
end
|