Patch #27659

redmine_plugin_model_generator improvements(fixes and timestamps)

Added by Javier Menéndez Rizo 15 days ago. Updated 14 days ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

Problems fixed:
  • parent option not working
  • migration option not working
Things added:
  • Timestamp for migrations

It would be really nice to add this to the migration generator for plugins.

redmine_plugin_model_generator.patch Magnifier (2.89 KB) Javier Menéndez Rizo, 2017-11-27 22:11


Related issues

Related to Redmine - Defect #11024: redmine_plugin_model generator does not create the migration Closed

History

#1 Updated by Toshi MARUYAMA 15 days ago

  • Related to Defect #11024: redmine_plugin_model generator does not create the migration added

#2 Updated by Toshi MARUYAMA 15 days ago

Javier Menéndez Rizo wrote:

Problems fixed:
  • parent option not working
  • migration option not working

Please explain more details.
AFAIK Redmine plugin is based old Rails engines, but current Redmine does not implement full feature of Rails engines.

#3 Updated by Javier Menéndez Rizo 14 days ago

Problems:
  • parent option: before the patch the parent option do nothing because in the model.rb template is not defined

Before patch model.rb template only inherits from ActiveRecord::Base

class <%= @model_class %> < ActiveRecord::Base

After patch model.rb template uses the method parent_class_name to calculate the parent and put it on the template

class <%= @model_class %> < <%= parent_class_name.classify %>
  • migration option: before the patch the generator alway generates the migration file, even if you pass --no-migration

After patch redmine_plugin_model_generator.rb i put a guard clause for generate the migration or not

    return unless options[:migration]
    migration_filename = "%.14d_#{@migration_filename}.rb" % migration_number
    template "migration.rb", "#{plugin_path}/db/migrate/#{migration_filename}" 

#4 Updated by Javier Menéndez Rizo 14 days ago

New feature:

Timestamps in the name of the generated migration file, right now redmine plugins generates the migrations in this form:

001_create_polls.rb

After patch

20171127212003_create_polls.rb

Also available in: Atom PDF