@@ -1,169 +1,178 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | namespace :redmine do |
|
19 | 19 | namespace :attachments do |
|
20 | 20 | desc 'Removes uploaded files left unattached after one day.' |
|
21 | 21 | task :prune => :environment do |
|
22 | 22 | Attachment.prune |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | desc 'Moves attachments stored at the root of the file directory (ie. created before Redmine 2.3) to their subdirectories' |
|
26 | 26 | task :move_to_subdirectories => :environment do |
|
27 | 27 | Attachment.move_from_root_to_target_directory |
|
28 | 28 | end |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | namespace :tokens do |
|
32 | 32 | desc 'Removes expired tokens.' |
|
33 | 33 | task :prune => :environment do |
|
34 | 34 | Token.destroy_expired |
|
35 | 35 | end |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | namespace :watchers do |
|
39 | 39 | desc 'Removes watchers from what they can no longer view.' |
|
40 | 40 | task :prune => :environment do |
|
41 | 41 | Watcher.prune |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | desc 'Fetch changesets from the repositories' |
|
46 | 46 | task :fetch_changesets => :environment do |
|
47 | 47 | Repository.fetch_changesets |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | desc 'Migrates and copies plugins assets.' |
|
51 | 51 | task :plugins do |
|
52 | 52 | Rake::Task["redmine:plugins:migrate"].invoke |
|
53 | 53 | Rake::Task["redmine:plugins:assets"].invoke |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | desc <<-DESC |
|
57 | 57 | FOR EXPERIMENTAL USE ONLY, Moves Redmine data from production database to the development database. |
|
58 | 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 | 59 | WARNING: All data in the development database is deleted. |
|
60 | 60 | DESC |
|
61 | 61 | |
|
62 | 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 | ||
|
63 | 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 | |
|
64 | 73 | |
|
65 | (ActiveRecord::Base.connection.tables - %w(schema_migrations plugin_schema_info)).each do |table_name| | |
|
74 | tables.each do |table_name| | |
|
66 | 75 | Source = Class.new(ActiveRecord::Base) |
|
67 | 76 | Target = Class.new(ActiveRecord::Base) |
|
68 | 77 | Target.establish_connection(:development) |
|
69 | 78 | |
|
70 | 79 | [Source, Target].each do |klass| |
|
71 | 80 | klass.table_name = table_name |
|
72 | 81 | klass.reset_column_information |
|
73 | 82 | klass.inheritance_column = "foo" |
|
74 | 83 | klass.record_timestamps = false |
|
75 | 84 | end |
|
76 | 85 | Target.primary_key = (Target.column_names.include?("id") ? "id" : nil) |
|
77 | 86 | |
|
78 | 87 | source_count = Source.count |
|
79 | 88 | puts "Migrating %6d records from #{table_name}..." % source_count |
|
80 | 89 | |
|
81 | 90 | Target.delete_all |
|
82 | 91 | offset = 0 |
|
83 | 92 | while (objects = Source.offset(offset).limit(5000).order("1,2").to_a) && objects.any? |
|
84 | 93 | offset += objects.size |
|
85 | 94 | Target.transaction do |
|
86 | 95 | objects.each do |object| |
|
87 | 96 | new_object = Target.new(object.attributes) |
|
88 | 97 | new_object.id = object.id if Target.primary_key |
|
89 | 98 | new_object.save(:validate => false) |
|
90 | 99 | end |
|
91 | 100 | end |
|
92 | 101 | end |
|
93 | 102 | Target.connection.reset_pk_sequence!(table_name) if Target.primary_key |
|
94 | 103 | target_count = Target.count |
|
95 | 104 | abort "Some records were not migrated" unless source_count == target_count |
|
96 | 105 | end |
|
97 | 106 | end |
|
98 | 107 | |
|
99 | 108 | namespace :plugins do |
|
100 | 109 | desc 'Migrates installed plugins.' |
|
101 | 110 | task :migrate => :environment do |
|
102 | 111 | name = ENV['NAME'] |
|
103 | 112 | version = nil |
|
104 | 113 | version_string = ENV['VERSION'] |
|
105 | 114 | if version_string |
|
106 | 115 | if version_string =~ /^\d+$/ |
|
107 | 116 | version = version_string.to_i |
|
108 | 117 | if name.nil? |
|
109 | 118 | abort "The VERSION argument requires a plugin NAME." |
|
110 | 119 | end |
|
111 | 120 | else |
|
112 | 121 | abort "Invalid VERSION #{version_string} given." |
|
113 | 122 | end |
|
114 | 123 | end |
|
115 | 124 | |
|
116 | 125 | begin |
|
117 | 126 | Redmine::Plugin.migrate(name, version) |
|
118 | 127 | rescue Redmine::PluginNotFound |
|
119 | 128 | abort "Plugin #{name} was not found." |
|
120 | 129 | end |
|
121 | 130 | |
|
122 | 131 | Rake::Task["db:schema:dump"].invoke |
|
123 | 132 | end |
|
124 | 133 | |
|
125 | 134 | desc 'Copies plugins assets into the public directory.' |
|
126 | 135 | task :assets => :environment do |
|
127 | 136 | name = ENV['NAME'] |
|
128 | 137 | |
|
129 | 138 | begin |
|
130 | 139 | Redmine::Plugin.mirror_assets(name) |
|
131 | 140 | rescue Redmine::PluginNotFound |
|
132 | 141 | abort "Plugin #{name} was not found." |
|
133 | 142 | end |
|
134 | 143 | end |
|
135 | 144 | |
|
136 | 145 | desc 'Runs the plugins tests.' |
|
137 | 146 | task :test do |
|
138 | 147 | Rake::Task["redmine:plugins:test:units"].invoke |
|
139 | 148 | Rake::Task["redmine:plugins:test:functionals"].invoke |
|
140 | 149 | Rake::Task["redmine:plugins:test:integration"].invoke |
|
141 | 150 | end |
|
142 | 151 | |
|
143 | 152 | namespace :test do |
|
144 | 153 | desc 'Runs the plugins unit tests.' |
|
145 | 154 | Rake::TestTask.new :units => "db:test:prepare" do |t| |
|
146 | 155 | t.libs << "test" |
|
147 | 156 | t.verbose = true |
|
148 | 157 | t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb" |
|
149 | 158 | end |
|
150 | 159 | |
|
151 | 160 | desc 'Runs the plugins functional tests.' |
|
152 | 161 | Rake::TestTask.new :functionals => "db:test:prepare" do |t| |
|
153 | 162 | t.libs << "test" |
|
154 | 163 | t.verbose = true |
|
155 | 164 | t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/functional/**/*_test.rb" |
|
156 | 165 | end |
|
157 | 166 | |
|
158 | 167 | desc 'Runs the plugins integration tests.' |
|
159 | 168 | Rake::TestTask.new :integration => "db:test:prepare" do |t| |
|
160 | 169 | t.libs << "test" |
|
161 | 170 | t.verbose = true |
|
162 | 171 | t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/integration/**/*_test.rb" |
|
163 | 172 | end |
|
164 | 173 | end |
|
165 | 174 | end |
|
166 | 175 | end |
|
167 | 176 | |
|
168 | 177 | # Load plugins' rake tasks |
|
169 | 178 | Dir[File.join(Rails.root, "plugins/*/lib/tasks/**/*.rake")].sort.each { |ext| load ext } |
General Comments 0
You need to be logged in to leave comments.
Login now