Mercurial > hg > soundsoftware-site
comparison lib/tasks/redmine.rake @ 1525:fb9a13467253 live
Merge from branch redmine-2.5-integration
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:45:02 +0100 |
parents | dffacf8a6908 |
children |
comparison
equal
deleted
inserted
replaced
1515:d98d22a98252 | 1525:fb9a13467253 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
18 namespace :redmine do | 18 namespace :redmine do |
19 namespace :attachments do | 19 namespace :attachments do |
20 desc 'Removes uploaded files left unattached after one day.' | 20 desc 'Removes uploaded files left unattached after one day.' |
21 task :prune => :environment do | 21 task :prune => :environment do |
22 Attachment.prune | 22 Attachment.prune |
23 end | |
24 | |
25 desc 'Moves attachments stored at the root of the file directory (ie. created before Redmine 2.3) to their subdirectories' | |
26 task :move_to_subdirectories => :environment do | |
27 Attachment.move_from_root_to_target_directory | |
23 end | 28 end |
24 end | 29 end |
25 | 30 |
26 namespace :tokens do | 31 namespace :tokens do |
27 desc 'Removes expired tokens.' | 32 desc 'Removes expired tokens.' |
44 | 49 |
45 desc 'Migrates and copies plugins assets.' | 50 desc 'Migrates and copies plugins assets.' |
46 task :plugins do | 51 task :plugins do |
47 Rake::Task["redmine:plugins:migrate"].invoke | 52 Rake::Task["redmine:plugins:migrate"].invoke |
48 Rake::Task["redmine:plugins:assets"].invoke | 53 Rake::Task["redmine:plugins:assets"].invoke |
54 end | |
55 | |
56 desc <<-DESC | |
57 FOR EXPERIMENTAL USE ONLY, Moves Redmine data from production database to the development database. | |
58 This task should only be used when you need to move data from one DBMS to a different one (eg. MySQL to PostgreSQL). | |
59 WARNING: All data in the development database is deleted. | |
60 DESC | |
61 | |
62 task :migrate_dbms => :environment do | |
63 ActiveRecord::Base.establish_connection :development | |
64 target_tables = ActiveRecord::Base.connection.tables | |
65 ActiveRecord::Base.remove_connection | |
66 | |
67 ActiveRecord::Base.establish_connection :production | |
68 tables = ActiveRecord::Base.connection.tables.sort - %w(schema_migrations plugin_schema_info) | |
69 | |
70 if (tables - target_tables).any? | |
71 abort "The following table(s) are missing from the target database: #{(tables - target_tables).join(', ')}" | |
72 end | |
73 | |
74 tables.each do |table_name| | |
75 Source = Class.new(ActiveRecord::Base) | |
76 Target = Class.new(ActiveRecord::Base) | |
77 Target.establish_connection(:development) | |
78 | |
79 [Source, Target].each do |klass| | |
80 klass.table_name = table_name | |
81 klass.reset_column_information | |
82 klass.inheritance_column = "foo" | |
83 klass.record_timestamps = false | |
84 end | |
85 Target.primary_key = (Target.column_names.include?("id") ? "id" : nil) | |
86 | |
87 source_count = Source.count | |
88 puts "Migrating %6d records from #{table_name}..." % source_count | |
89 | |
90 Target.delete_all | |
91 offset = 0 | |
92 while (objects = Source.offset(offset).limit(5000).order("1,2").to_a) && objects.any? | |
93 offset += objects.size | |
94 Target.transaction do | |
95 objects.each do |object| | |
96 new_object = Target.new(object.attributes) | |
97 new_object.id = object.id if Target.primary_key | |
98 new_object.save(:validate => false) | |
99 end | |
100 end | |
101 end | |
102 Target.connection.reset_pk_sequence!(table_name) if Target.primary_key | |
103 target_count = Target.count | |
104 abort "Some records were not migrated" unless source_count == target_count | |
105 end | |
49 end | 106 end |
50 | 107 |
51 namespace :plugins do | 108 namespace :plugins do |
52 desc 'Migrates installed plugins.' | 109 desc 'Migrates installed plugins.' |
53 task :migrate => :environment do | 110 task :migrate => :environment do |