##// END OF EJS Templates
Rewrites UpdateMailNotificationValues migration to avoid model validations and failures....
Jean-Philippe Lang -
r4254:73167fb4f26b
parent child
Show More
@@ -1,22 +1,9
1 # Patch the data from a boolean change.
1 # Patch the data from a boolean change.
2 class UpdateMailNotificationValues < ActiveRecord::Migration
2 class UpdateMailNotificationValues < ActiveRecord::Migration
3 def self.up
3 def self.up
4 User.record_timestamps = false
4 User.update_all("mail_notification = 'all'", "mail_notification IN ('1', 't')")
5 User.all.each do |u|
5 User.update_all("mail_notification = 'selected'", "EXISTS (SELECT 1 FROM #{Member.table_name} WHERE #{Member.table_name}.mail_notification = #{connection.quoted_true} AND #{Member.table_name}.user_id = #{User.table_name}.id)")
6 u.mail_notification = if u.mail_notification =~ /\A(1|t)\z/
6 User.update_all("mail_notification = 'only_my_events'", "mail_notification NOT IN ('all', 'selected')")
7 # User set for all email (t is for sqlite)
8 'all'
9 else
10 # User wants to recieve notifications on specific projects?
11 if u.memberships.count(:conditions => {:mail_notification => true}) > 0
12 'selected'
13 else
14 'only_my_events'
15 end
16 end
17 u.save!
18 end
19 User.record_timestamps = true
20 end
7 end
21
8
22 def self.down
9 def self.down
General Comments 0
You need to be logged in to leave comments. Login now