mirror of
https://github.com/redmine/redmine.git
synced 2025-11-09 06:46:01 +01:00
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:
5
lib/generators/redmine_plugin_migration/USAGE
Normal file
5
lib/generators/redmine_plugin_migration/USAGE
Normal file
@@ -0,0 +1,5 @@
|
||||
Description:
|
||||
Generates a plugin migration.
|
||||
|
||||
Examples:
|
||||
bin/rails generate redmine_plugin_migration my_plugin add_new_column_to_table
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
||||
def change
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user