Class: Brut::CLI::Apps::DB::Drop
Instance Attribute Summary
#parent_command
Instance Method Summary
collapse
#accepts, #args_description, #argv, #commands, #delegate_to_command, #detailed_description, #env, #env_vars, #execute, #name, #options, #opts, #puts, #stdin, #system!, #theme
Instance Method Details
#bootstrap? ⇒ Boolean
157
|
# File 'lib/brut/cli/apps/db.rb', line 157
def bootstrap? = false
|
#default_rack_env ⇒ Object
156
|
# File 'lib/brut/cli/apps/db.rb', line 156
def default_rack_env = "development"
|
#description ⇒ Object
155
|
# File 'lib/brut/cli/apps/db.rb', line 155
def description = "Drop the database if it exists"
|
#run ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/brut/cli/apps/db.rb', line 159
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
puts "Database #{theme.code.render(database_name)} exists. Dropping..."
connection = Sequel.connect(uri_no_database.to_s)
connection.run("DROP DATABASE IF EXISTS \"#{database_name}\"")
connection.disconnect
puts [
theme.success.render("✅ Database"),
theme.code.render(database_name),
theme.success.render("dropped"),
].join(" ")
0
rescue Sequel::DatabaseConnectionError => ex
begin
connection = Sequel.connect(uri_no_database.to_s)
puts [
theme.success.render("✅ Database"),
theme.code.render(database_name),
theme.success.render("has already been dropped"),
].join(" ")
connection.disconnect
0
rescue Sequel::DatabaseConnectionError => ex2
puts [
theme.error.render("Database server is not running at"),
theme.code.render(uri_no_database.to_s),
].join(" ")
puts [
theme.error.render(ex2.class.name),
theme.exception.render(ex2.message),
].join(": ")
puts theme.error.render("This could be a problem with your dev environment")
puts [
theme.error.render("Check"),
theme.code.render(".env.test"),
theme.error.render("and"),
theme.code.render(".env.test.local"),
theme.error.render("to see if "),
theme.code.render("DATABASE_URL"),
theme.error.render("is set correctly"),
].join(" ")
1
end
end
end
|