@@ -53,6 +53,49 namespace :redmine do | |||||
53 | Rake::Task["redmine:plugins:assets"].invoke |
|
53 | Rake::Task["redmine:plugins:assets"].invoke | |
54 | end |
|
54 | end | |
55 |
|
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 :production | |||
|
64 | ||||
|
65 | (ActiveRecord::Base.connection.tables - %w(schema_migrations plugin_schema_info)).each do |table_name| | |||
|
66 | Source = Class.new(ActiveRecord::Base) | |||
|
67 | Target = Class.new(ActiveRecord::Base) | |||
|
68 | Target.establish_connection(:development) | |||
|
69 | ||||
|
70 | [Source, Target].each do |klass| | |||
|
71 | klass.table_name = table_name | |||
|
72 | klass.reset_column_information | |||
|
73 | klass.inheritance_column = "foo" | |||
|
74 | klass.record_timestamps = false | |||
|
75 | end | |||
|
76 | Target.primary_key = (Target.column_names.include?("id") ? "id" : nil) | |||
|
77 | ||||
|
78 | source_count = Source.count | |||
|
79 | puts "Migrating %6d records from #{table_name}..." % source_count | |||
|
80 | ||||
|
81 | Target.delete_all | |||
|
82 | offset = 0 | |||
|
83 | while (objects = Source.offset(offset).limit(5000).order("1,2").to_a) && objects.any? | |||
|
84 | offset += objects.size | |||
|
85 | Target.transaction do | |||
|
86 | objects.each do |object| | |||
|
87 | new_object = Target.new(object.attributes) | |||
|
88 | new_object.id = object.id if Target.primary_key | |||
|
89 | new_object.save(:validate => false) | |||
|
90 | end | |||
|
91 | end | |||
|
92 | end | |||
|
93 | Target.connection.reset_pk_sequence!(table_name) if Target.primary_key | |||
|
94 | target_count = Target.count | |||
|
95 | abort "Some records were not migrated" unless source_count == target_count | |||
|
96 | end | |||
|
97 | end | |||
|
98 | ||||
56 | namespace :plugins do |
|
99 | namespace :plugins do | |
57 | desc 'Migrates installed plugins.' |
|
100 | desc 'Migrates installed plugins.' | |
58 | task :migrate => :environment do |
|
101 | task :migrate => :environment do |
General Comments 0
You need to be logged in to leave comments.
Login now