Class: Ardb::CLI::GenerateMigrationCommand

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



188
189
190
# File 'lib/ardb/cli/commands.rb', line 188

def self.command_name
  "generate-migration"
end

.command_summaryObject



192
193
194
# File 'lib/ardb/cli/commands.rb', line 192

def self.command_summary
  "Generate a MIGRATION-NAME migration file"
end

Instance Method Details

#command_helpObject



218
219
220
221
222
223
# File 'lib/ardb/cli/commands.rb', line 218

def command_help
  "Usage: ardb #{command_name} MIGRATION-NAME [options]\n\n" \
  "Options: #{clirb}\n" \
  "Description:\n" \
  "  #{command_summary}"
end

#run(argv, *args) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ardb/cli/commands.rb', line 196

def run(argv, *args)
  super

  begin
    Ardb.init(false)

    require "ardb/migration"
    migration = Ardb::Migration.new(Ardb.config, @clirb.args.first)
    migration.save!
    @stdout.puts "generated #{migration.file_path}"
  rescue Ardb::Migration::NoIdentifierError => ex
    error = ArgumentError.new("MIGRATION-NAME must be provided")
    error.set_backtrace(ex.backtrace)
    raise error
  rescue => ex
    @stderr.puts ex
    @stderr.puts ex.backtrace.join("\n")
    @stderr.puts "error generating migration"
    raise CommandExitError
  end
end