Remove db plugin migration code

We now use rake <plugin>:install:migrations.
pull/131/head
Michael Frister 12 years ago committed by Christian Ratz
parent 5a892b7813
commit 2dd1898e78
  1. 72
      lib/redmine/plugin.rb
  2. 2
      lib/tasks/ci.rake
  3. 17
      lib/tasks/deprecated.rake
  4. 33
      lib/tasks/plugins.rake
  5. 7
      setup.rb

@ -403,77 +403,5 @@ module Redmine #:nodoc:
end
end
end
# The directory containing this plugin's migrations (<tt>plugin/db/migrate</tt>)
def migration_directory
File.join(Rails.root, 'vendor/plugins', id.to_s, 'db', 'migrate')
end
# Returns the version number of the latest migration for this plugin. Returns
# nil if this plugin has no migrations.
def latest_migration
migrations.last
end
# Returns the version numbers of all migrations for this plugin.
def migrations
migrations = Dir[migration_directory+"/*.rb"]
migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
end
# Migrate this plugin to the given version
def migrate(version = nil)
puts "Migrating #{id} (#{name})..."
Redmine::Plugin::Migrator.migrate_plugin(self, version)
end
# Migrates all plugins or a single plugin to a given version
# Exemples:
# Plugin.migrate
# Plugin.migrate('sample_plugin')
# Plugin.migrate('sample_plugin', 1)
#
def self.migrate(name=nil, version=nil)
if name.present?
find(name).migrate(version)
else
all.each do |plugin|
plugin.migrate
end
end
end
class Migrator < ActiveRecord::Migrator
# We need to be able to set the 'current' plugin being migrated.
cattr_accessor :current_plugin
class << self
# Runs the migrations from a plugin, up (or down) to the version given
def migrate_plugin(plugin, version)
self.current_plugin = plugin
require 'ruby-debug'; debugger
return if current_version(plugin) == version
migrate(plugin.migration_directory, version)
end
def current_version(plugin=current_plugin)
# Delete migrations that don't match .. to_i will work because the number comes first
::ActiveRecord::Base.connection.select_values(
"SELECT version FROM #{schema_migrations_table_name}"
).delete_if{ |v| v.match(/-#{plugin.id}/) == nil }.map(&:to_i).max || 0
end
end
def migrated
sm_table = self.class.schema_migrations_table_name
::ActiveRecord::Base.connection.select_values(
"SELECT version FROM #{sm_table}"
).delete_if{ |v| v.match(/-#{current_plugin.id}/) == nil }.map(&:to_i).sort
end
def record_version_state_after_migrating(version)
super(version.to_s + "-" + current_plugin.id.to_s)
end
end
end
end

@ -62,7 +62,6 @@ namespace :ci do
# Create and migrate the database
Rake::Task["db:create"].invoke
Rake::Task["db:migrate"].invoke
Rake::Task["db:migrate:plugins"].invoke #noop currently
Rake::Task["db:schema:dump"].invoke
# Create test repositories
@ -76,7 +75,6 @@ namespace :ci do
Rake::Task["db:drop"].invoke
Rake::Task["db:create"].invoke
Rake::Task["db:migrate"].invoke
Rake::Task["db:migrate:plugins"].invoke
Rake::Task["db:schema:dump"].invoke
Rake::Task["test:scm:update"].invoke
end

@ -12,14 +12,27 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
def deprecated_task(name, new_name)
task name=>new_name do
$stderr.puts "\nNote: The rake task #{name} has been deprecated, please use the replacement version #{new_name}"
end
end
def removed_task(name, message)
task name do
$stderr.puts "\nError: The rake task #{name} has been removed. #{message}"
raise
end
end
deprecated_task :load_default_data, "redmine:load_default_data"
deprecated_task :migrate_from_mantis, "redmine:migrate_from_mantis"
deprecated_task :migrate_from_trac, "redmine:migrate_from_trac"
deprecated_task "db:migrate_plugins", "redmine:plugins:migrate"
deprecated_task "db:migrate:plugin", "redmine:plugins:migrate"
plugin_migrate_message = "<plugin>:install:migrations is used now to copy" +
" migrations to the rails application directory." +
" After installation, use db:migrate."
removed_task "db:migrate_plugins", plugin_migrate_message
removed_task "db:migrate:plugin", plugin_migrate_message
removed_task "redmine:plugins:migrate", plugin_migrate_message

@ -49,31 +49,6 @@ namespace :redmine do
PluginSourceAnnotationExtractor.enumerate 'call_hook'
end
desc 'Migrates installed plugins.'
task :migrate => :environment do
name = ENV['NAME']
version = nil
version_string = ENV['VERSION']
if version_string
if version_string =~ /^\d+$/
version = version_string.to_i
if name.nil?
abort "The VERSION argument requires a plugin NAME."
end
else
abort "Invalid VERSION #{version_string} given."
end
end
begin
Redmine::Plugin.migrate(name, version)
rescue Redmine::PluginNotFound
abort "Plugin #{name} was not found."
end
Rake::Task["db:schema:dump"].invoke
end
desc 'Copies plugins assets into the public directory.'
task :assets => :environment do
name = ENV['NAME']
@ -116,11 +91,3 @@ namespace :redmine do
end
end
end
namespace :db do
namespace :migrate do
task :plugins do
#noop
end
end
end

@ -147,7 +147,7 @@ def setup_openproject
return false unless system("rake db:drop:all")
end
return false unless system("rake db:create:all") and migrate_core and migrate_plugins
return false unless system("rake db:create:all") and migrate_core
else
return false
end
@ -156,11 +156,6 @@ def setup_openproject
system("rake generate_session_store")
end
def migrate_plugins
puts $output_prefix + "Migrate Plugins"
return system("rake db:migrate:plugins")
end
def migrate_core
puts $output_prefix + "Migrate Core"
return system("rake db:migrate")

Loading…
Cancel
Save