Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2493 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2009-02-21 11:04:50 +00:00
parent 9a986ac0a5
commit fe28193e4e
237 changed files with 27994 additions and 32194 deletions
+77 -3
View File
@@ -43,6 +43,80 @@ namespace :db do
end
end
desc 'For engines coming from Rails version < 2.0 or for those previously updated to work with Sven Fuch\'s fork of engines, you need to upgrade the schema info table'
task :upgrade_plugin_migrations => :environment do
svens_fork_table_name = 'plugin_schema_migrations'
# Check if app was previously using Sven's fork
if ActiveRecord::Base.connection.table_exists?(svens_fork_table_name)
old_sm_table = svens_fork_table_name
else
old_sm_table = ActiveRecord::Migrator.proper_table_name(Engines.schema_info_table)
end
unless ActiveRecord::Base.connection.table_exists?(old_sm_table)
abort "Cannot find old migration table - assuming nothing needs to be done"
end
# There are two forms of the engines schema info - pre-fix_plugin_migrations and post
# We need to figure this out before we continue.
results = ActiveRecord::Base.connection.select_rows(
"SELECT version, plugin_name FROM #{old_sm_table}"
).uniq
def insert_new_version(plugin_name, version)
version_string = "#{version}-#{plugin_name}"
new_sm_table = ActiveRecord::Migrator.schema_migrations_table_name
# Check if the row already exists for some reason - maybe run this task more than once.
return if ActiveRecord::Base.connection.select_rows("SELECT * FROM #{new_sm_table} WHERE version = #{version_string.dump.gsub("\"", "'")}").size > 0
puts "Inserting new version #{version} for plugin #{plugin_name}.."
ActiveRecord::Base.connection.insert("INSERT INTO #{new_sm_table} (version) VALUES (#{version_string.dump.gsub("\"", "'")})")
end
# We need to figure out if they already used "fix_plugin_migrations"
versions = {}
results.each do |r|
versions[r[1]] ||= []
versions[r[1]] << r[0].to_i
end
if versions.values.find{ |v| v.size > 1 } == nil
puts "Fixing migration info"
# We only have one listed migration per plugin - this is pre-fix_plugin_migrations,
# so we build all versions required. In this case, all migrations should
versions.each do |plugin_name, version|
version = version[0] # There is only one version
# We have to make an assumption that numeric migrations won't get this long..
# I'm not sure if there is a better assumption, it should work in all
# current cases.. (touch wood..)
if version.to_s.size < "YYYYMMDDHHMMSS".size
# Insert version records for each migration
(1..version).each do |v|
insert_new_version(plugin_name, v)
end
else
# If the plugin is new-format "YYYYMMDDHHMMSS", we just copy it across...
# The case in which this occurs is very rare..
insert_new_version(plugin_name, version)
end
end
else
puts "Moving migration info"
# We have multiple migrations listed per plugin - thus we can assume they have
# already applied fix_plugin_migrations - we just copy it across verbatim
versions.each do |plugin_name, version|
version.each { |v| insert_new_version(plugin_name, v) }
end
end
puts "Migration info successfully migrated - removing old schema info table"
ActiveRecord::Base.connection.drop_table(old_sm_table)
end
desc 'Migrate a specified plugin.'
task({:plugin => :environment}, :name, :version) do |task, args|
name = args[:name] || ENV['NAME']
@@ -53,7 +127,7 @@ namespace :db do
else
puts "Plugin #{name} does not exist."
end
end
end
end
end
@@ -174,5 +248,5 @@ Report any issues on http://dev.rails-engines.org. Thanks!
# Patch the default plugin testing task to have setup_plugin_fixtures as a prerequisite
Rake::Task["test:plugins"].prerequisites << "test:plugins:setup_plugin_fixtures"
end
end
end
end