summaryrefslogtreecommitdiffstats
path: root/lib/generators
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-06-03 14:56:09 +0000
committerGo MAEDA <maeda@farend.jp>2019-06-03 14:56:09 +0000
commitc1bb0e70a3a1c7ebacf51e828648f36990721f3c (patch)
tree651b947c0b9c6a732a2cdb3adea46c0e4532c3ec /lib/generators
parent4e9bf7310c0a41a0ac9e16dfe2d3c6396d600c74 (diff)
downloadredmine-c1bb0e70a3a1c7ebacf51e828648f36990721f3c.tar.gz
redmine-c1bb0e70a3a1c7ebacf51e828648f36990721f3c.zip
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
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/redmine_plugin_migration/USAGE5
-rw-r--r--lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb20
-rw-r--r--lib/generators/redmine_plugin_migration/templates/migration.rb.tt4
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/generators/redmine_plugin_migration/USAGE b/lib/generators/redmine_plugin_migration/USAGE
new file mode 100644
index 000000000..4e324bffb
--- /dev/null
+++ b/lib/generators/redmine_plugin_migration/USAGE
@@ -0,0 +1,5 @@
+Description:
+ Generates a plugin migration.
+
+Examples:
+ bin/rails generate redmine_plugin_migration my_plugin add_new_column_to_table
diff --git a/lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb b/lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb
new file mode 100644
index 000000000..ed3d87506
--- /dev/null
+++ b/lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb
@@ -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
diff --git a/lib/generators/redmine_plugin_migration/templates/migration.rb.tt b/lib/generators/redmine_plugin_migration/templates/migration.rb.tt
new file mode 100644
index 000000000..c759c2a68
--- /dev/null
+++ b/lib/generators/redmine_plugin_migration/templates/migration.rb.tt
@@ -0,0 +1,4 @@
+class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
+ def change
+ end
+end