プロジェクト

全般

プロフィール

Vote #78973

完了

redmine_plugin_model_generator improvements(fixes and timestamps)

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
127
issue_org_id:
27659
author_id:
161471
assigned_to_id:
1
comments:
7
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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.


journals

--------------------------------------------------------------------------------
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.

--------------------------------------------------------------------------------
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*

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

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

<pre>
class <%= @model_class %> < <%= parent_class_name.classify %>
</pre>

* 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*

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

--------------------------------------------------------------------------------
New feature:

Timestamps in the name of the generated migration file, right now redmine plugins generates the migrations in this form:
<pre>
001_create_polls.rb
</pre>

*After patch*

<pre>
20171127212003_create_polls.rb
</pre>
--------------------------------------------------------------------------------
OK, I see.

On trunk r17132:

<pre>
$ rails generate redmine_plugin_model --help
Usage:
rails generate redmine_plugin_model NAME MODEL [field[:type][:index] field[:type][:index]] [options]

Options:
[--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications)
[--migration], [--no-migration] # Indicates when to generate migration
[--timestamps], [--no-timestamps] # Indicates when to generate timestamps
[--parent=PARENT] # The parent class for the generated model
[--indexes], [--no-indexes] # Add indexes for references and belongs_to columns
# Default: true

Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend], [--no-pretend] # Run but do not make any changes
-q, [--quiet], [--no-quiet] # Suppress status output
-s, [--skip], [--no-skip] # Skip files that already exist

Description:
Generates a plugin model.

Examples:
bundle exec rails generate redmine_plugin_model meetings pool
</pre>
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Committed, thanks.
--------------------------------------------------------------------------------


related_issues

relates,Closed,11024,redmine_plugin_model generator does not create the migration

Admin Redmine さんが約4年前に更新

  • カテゴリPlugin API_20 にセット
  • 対象バージョン4.1.0_127 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0