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