Class: Ardb::CLI::GenerateMigrationCommand

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

Instance Method Summary collapse

Instance Method Details

#helpObject



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

def help
  "Usage: ardb generate-migration [options] MIGRATION-NAME\n\n" \
  "Options: #{@clirb}\n" \
  "Description:\n" \
  "  #{self.summary}"
end

#run(argv, *args) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ardb/cli/commands.rb', line 192

def run(argv, *args)
  super

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

#summaryObject



213
214
215
# File 'lib/ardb/cli/commands.rb', line 213

def summary
  "Generate a migration file given a MIGRATION-NAME"
end