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, #default_command, #default_command_class, #env, #env_vars, #execute, #name, #options, #opts, #puts, #stderr, #stdin, #stdout, #system!

Instance Method Details

#bootstrap?Boolean

Returns:

  • (Boolean)


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

def bootstrap? = true

#default_rack_envObject



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

def default_rack_env = "development"

#descriptionObject



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

def description = "Load seed data into the database"

#runObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/brut/cli/apps/db.rb', line 184

def run
  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::DatabaseConnectionError => ex
  stderr.puts "Database doesn't exist. Create it with `brut db create`"
  1
rescue Sequel::UniqueConstraintViolation => ex
  stderr.puts "Seed data may have already been loaded: #{ex}. You can re-load it using `brut db rebuild`, then `brut db seed`"
  1
rescue Sequel::DatabaseError => ex
  if ex.cause.kind_of?(PG::UndefinedTable)
    stderr.puts "Migrations need to be run. Use `brut db migrate` to run them"
    1
  else
    raise ex
  end
end