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

Inherits:
Command
  • Object
show all
Defined in:
lib/brut/cli/apps/db.rb

Instance Method Summary collapse

Methods inherited from Command

#after_bootstrap, args, #args, #before_execute, command_name, default_env, #delegate_to_commands, description, detailed_description, env_var, #err, #global_options, #initialize, name_matches?, option_parser, #options, opts, #out, requires_project_env, requires_project_env?, #system!

Methods included from Framework::Errors

#abstract_method!, #bug!

Methods included from I18n::ForCLI

#capture, #html_escape, #safe

Methods included from I18n::BaseMethods

#l, #t, #t_direct, #this_field_value

Methods included from ExecutionResults

#abort_execution, #as_execution_result, #cli_usage_error, #continue_execution, #show_cli_usage, #stop_execution

Constructor Details

This class inherits a constructor from Brut::CLI::Command

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/brut/cli/apps/db.rb', line 28

def execute
  seeds_dir = Brut.container.db_seeds_dir
  Dir["#{seeds_dir}/*.rb"].each do |file|
    require file
  end
  seed_data = Brut::BackEnd::SeedData.new
  seed_data.setup!
  seed_data.load_seeds!
  0
rescue Sequel::UniqueConstraintViolation => ex
  raise "Seed data may have already been loaded: #{ex}"
end

#handle_bootstrap_exception(ex) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/brut/cli/apps/db.rb', line 13

def handle_bootstrap_exception(ex)
  case ex
  when Sequel::DatabaseConnectionError
    abort_execution("Database needs to be created")
  when Sequel::DatabaseError
    if ex.cause.kind_of?(PG::UndefinedTable)
      abort_execution("Migrations need to be run")
    else
      super
    end
  else
    super
  end
end