Add redmine_plugin_migration generator (#31498).

Patch by Kouhei Sutou.


git-svn-id: http://svn.redmine.org/redmine/trunk@18223 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2019-06-03 14:56:09 +00:00
parent 4e9bf7310c
commit c1bb0e70a3
3 changed files with 29 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
Description:
Generates a plugin migration.
Examples:
bin/rails generate redmine_plugin_migration my_plugin add_new_column_to_table

View File

@@ -0,0 +1,20 @@
class RedminePluginMigrationGenerator < Rails::Generators::NamedBase
include Rails::Generators::Migration
source_root File.expand_path("../templates", __FILE__)
argument :migration, :type => :string
class << self
def next_migration_number(dirname)
next_migration_number = current_migration_number(dirname) + 1
ActiveRecord::Migration.next_migration_number(next_migration_number)
end
end
def create_migration_file
plugin_name = file_name.underscore
plugin_path = File.join(Redmine::Plugin.directory, plugin_name)
migration_template "migration.rb",
"#{plugin_path}/db/migrate/#{@migration}.rb"
end
end

View File

@@ -0,0 +1,4 @@
class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
end
end