Class: Brut::CLI::Apps::DB::Seed

Inherits:
Commands::BaseCommand show all
Defined in:
lib/brut/cli/apps/db.rb

Instance Attribute Summary

Attributes inherited from Commands::BaseCommand

#parent_command

Instance Method Summary collapse

Methods inherited from Commands::BaseCommand

#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

Returns:

  • (Boolean)


292
# File 'lib/brut/cli/apps/db.rb', line 292

def bootstrap? = true

#default_rack_envObject



291
# File 'lib/brut/cli/apps/db.rb', line 291

def default_rack_env = "development"

#descriptionObject



290
# File 'lib/brut/cli/apps/db.rb', line 290

def description = "Load seed data into the database"

#runObject



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