Class: Brut::CLI::Apps::DB::Seed
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
292
|
# File 'lib/brut/cli/apps/db.rb', line 292
def bootstrap? = true
|
#default_rack_env ⇒ Object
291
|
# File 'lib/brut/cli/apps/db.rb', line 291
def default_rack_env = "development"
|
#description ⇒ Object
290
|
# File 'lib/brut/cli/apps/db.rb', line 290
def description = "Load seed data into the database"
|
#run ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
# File 'lib/brut/cli/apps/db.rb', line 294
def run
seeds_dir = Brut.container.db_seeds_dir
info "Using seeds from #{seeds_dir}"
Dir["#{seeds_dir}/*.rb"].each do |file|
info "Loading seed file #{file}"
friendly_filename = Pathname(file).relative_path_from(Brut.container.project_root)
puts "Loading seed data from #{theme.code.render(friendly_filename.to_s)}"
require file
end
seed_data = Brut::BackEnd::SeedData.new
seed_data.setup!
seed_data.load_seeds!
puts theme.success.render("✅ Seed data loaded")
0
rescue Sequel::UniqueConstraintViolation => ex
puts theme.error.render("Seed data may have already been loaded:")
puts theme.exception.render(" #{ex}".strip)
puts [
theme.error.render("You can re-load it using"),
theme.code.render("brut db rebuild && brut db seed"),
].join(" ")
1
end
|