Class: Brut::CLI::Apps::DB::Migrate
Defined Under Namespace
Classes: MessagingProxyLogger
Instance Attribute Summary
#parent_command
Instance Method Summary
collapse
#accepts, #args_description, #argv, #bootstrap?, #commands, #delegate_to_command, #detailed_description, #env, #env_vars, #execute, #name, #options, #puts, #stdin, #system!, #theme
Instance Method Details
#default_rack_env ⇒ Object
213
|
# File 'lib/brut/cli/apps/db.rb', line 213
def default_rack_env = "development"
|
#description ⇒ Object
212
|
# File 'lib/brut/cli/apps/db.rb', line 212
def description = "Apply any outstanding migrations to the database"
|
#opts ⇒ Object
228
229
230
|
# File 'lib/brut/cli/apps/db.rb', line 228
def opts = [
[ "--[no-]sequel-log", "Log Sequel activity at same level as --log-level. When disabled, Sequel will not log at all." ],
]
|
#run ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/brut/cli/apps/db.rb', line 232
def run
migrations_dir = Brut.container.migrations_dir
if !migrations_dir.exist?
puts "No migrations to run from #{migrations_dir}"
return 0
elsif Dir[migrations_dir / "*.rb"].empty?
puts "No migrations to run from #{migrations_dir}"
return 0
end
Sequel.extension :migration
Brut.container.sequel_db_handle.extension :brut_migrations
Brut.container.sequel_db_handle.extension :pg_array
Brut.container.sequel_db_handle.logger = MessagingProxyLogger.new(
execution_context.logger.without_stderr,
self
)
Sequel::Migrator.run(Brut.container.sequel_db_handle,migrations_dir)
puts theme.success.render("✅ All migrations have been applied")
0
rescue Sequel::DatabaseConnectionError => ex
database_name = URI(Brut.container.database_url).path.gsub(/^\//,"")
puts [
theme.error.render("Database"),
theme.code.render(database_name),
theme.error.render("does not exist."),
].join(" ")
puts [
theme.warning.render("Create it first with"),
theme.code.render("brut db create"),
].join(" ")
1
rescue Sequel::DatabaseError => ex
raise ex
end
|