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

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

Overview

XXX

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, #print, #puts, #stdin, #system!, #theme

Instance Method Details

#bootstrap?Boolean

Returns:

  • (Boolean)


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

def bootstrap? = true

#default_rack_envObject



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

def default_rack_env = "development"

#descriptionObject



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

def description = "Load seed data into the database"

#runObject



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/brut/cli/apps/db.rb', line 306

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 --seed"),
  ].join(" ")
  1
end