Class: Ardb::CLI::CreateCommand

Inherits:
Object
  • Object
show all
Includes:
ValidCommand
Defined in:
lib/ardb/cli/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command_nameObject



124
125
126
# File 'lib/ardb/cli/commands.rb', line 124

def self.command_name
  "create"
end

.command_summaryObject



128
129
130
# File 'lib/ardb/cli/commands.rb', line 128

def self.command_summary
  "Create the configured DB"
end

Instance Method Details

#run(argv, *args) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/ardb/cli/commands.rb', line 132

def run(argv, *args)
  super

  begin
    Ardb.init(false)
    Ardb.adapter.create_db
    @stdout.puts(
      "created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}",
    )
  rescue ActiveRecord::StatementInvalid
    @stderr.puts(
      "error: database #{Ardb.config.database.inspect} already exists",
    )
  rescue => ex
    @stderr.puts ex
    @stderr.puts "error creating #{Ardb.config.database.inspect} database"
    raise CommandExitError
  end
end