Patch #31498 » add-redmine-plugin-migration-generator-v2.diff
| lib/generators/redmine_plugin_migration/USAGE | ||
|---|---|---|
| 1 | 
    Description:  | 
|
| 2 | 
    Generates a plugin migration.  | 
|
| 3 | ||
| 4 | 
    Examples:  | 
|
| 5 | 
    bin/rails generate redmine_plugin_migration my_plugin add_new_column_to_table  | 
|
| lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb | ||
|---|---|---|
| 1 | 
    class RedminePluginMigrationGenerator < Rails::Generators::NamedBase  | 
|
| 2 | 
    include Rails::Generators::Migration  | 
|
| 3 | ||
| 4 | 
      source_root File.expand_path("../templates", __FILE__)
   | 
|
| 5 | 
    argument :migration, :type => :string  | 
|
| 6 | ||
| 7 | 
    class << self  | 
|
| 8 | 
    def next_migration_number(dirname)  | 
|
| 9 | 
    next_migration_number = current_migration_number(dirname) + 1  | 
|
| 10 | 
    ActiveRecord::Migration.next_migration_number(next_migration_number)  | 
|
| 11 | 
    end  | 
|
| 12 | 
    end  | 
|
| 13 | ||
| 14 | 
    def create_migration_file  | 
|
| 15 | 
    plugin_name = file_name.underscore  | 
|
| 16 | 
    plugin_path = File.join(Redmine::Plugin.directory, plugin_name)  | 
|
| 17 | 
    migration_template "migration.rb",  | 
|
| 18 | 
                           "#{plugin_path}/db/migrate/#{@migration}.rb"
   | 
|
| 19 | 
    end  | 
|
| 20 | 
    end  | 
|
| lib/generators/redmine_plugin_migration/templates/migration.rb.tt | ||
|---|---|---|
| 1 | 
    class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]  | 
|
| 2 | 
    def change  | 
|
| 3 | 
    end  | 
|
| 4 | 
    end  | 
|
- « Previous
 - 1
 - 2
 - Next »