Class: Brut::CLI::Apps::DB::NewMigration
- Defined in:
- lib/brut/cli/apps/db.rb
Instance Method Summary collapse
Methods inherited from Command
#after_bootstrap, args, #args, command_name, default_env, #delegate_to_commands, description, detailed_description, env_var, #err, #global_options, #handle_bootstrap_exception, #initialize, name_matches?, option_parser, #options, opts, #out, requires_project_env, requires_project_env?, #system!
Methods included from Framework::Errors
Methods included from I18n::ForCLI
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
#before_execute ⇒ Object
204 205 206 |
# File 'lib/brut/cli/apps/db.rb', line 204 def before_execute ENV["RACK_ENV"] = "development" end |
#execute ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/brut/cli/apps/db.rb', line 208 def execute if @args.length == 0 return abort_execution("You must provide a name for the migration") end migrations_dir = Brut.container.migrations_dir name = @args.join(" ").gsub(/[^\w\d\-]/,"-") date = DateTime.now.strftime("%Y%m%d%H%M%S") file_name = migrations_dir / "#{date}_#{name}.rb" File.open(file_name,"w") do |file| file.puts "Sequel.migration do" file.puts " up do" file.puts " end" file.puts "end" end relative_path = file_name.relative_path_from(Brut.container.project_root) out.puts "Migration created:\n #{relative_path}" end |