]> source.dussan.org Git - redmine.git/commitdiff
Rails4: replace deprecated Relation#update_all at db migrations
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 7 Jan 2014 10:03:11 +0000 (10:03 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Tue, 7 Jan 2014 10:03:11 +0000 (10:03 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12488 e93f8b46-1217-0410-a6f0-8f06a7374b81

db/migrate/20090401221305_update_enumerations_to_sti.rb
db/migrate/20090614091200_fix_messages_sticky_null.rb
db/migrate/20090704172350_populate_users_type.rb
db/migrate/20091010093521_fix_users_custom_values.rb
db/migrate/20100129193402_change_users_mail_notification_to_string.rb
db/migrate/20110228000100_copy_repositories_log_encoding.rb
db/migrate/20120223110929_change_attachments_container_defaults.rb

index 50bd52010520dd481e9c746b16ff8066c27a737d..031dd4656ae2dc3f836839cab1af0ab5ba14858b 100644 (file)
@@ -1,8 +1,8 @@
 class UpdateEnumerationsToSti < ActiveRecord::Migration
   def self.up
-    Enumeration.update_all("type = 'IssuePriority'", "opt = 'IPRI'")
-    Enumeration.update_all("type = 'DocumentCategory'", "opt = 'DCAT'")
-    Enumeration.update_all("type = 'TimeEntryActivity'", "opt = 'ACTI'")
+    Enumeration.where("opt = 'IPRI'").update_all("type = 'IssuePriority'")
+    Enumeration.where("opt = 'DCAT'").update_all("type = 'DocumentCategory'")
+    Enumeration.where("opt = 'ACTI'").update_all("type = 'TimeEntryActivity'")
   end
 
   def self.down
index cbe741732ec23089a0303dd6e2d58070e124fbfa..fcb8b45045bcea4a07111c8a9ad051ac72e28e90 100644 (file)
@@ -1,6 +1,6 @@
 class FixMessagesStickyNull < ActiveRecord::Migration
   def self.up
-    Message.update_all('sticky = 0', 'sticky IS NULL')
+    Message.where('sticky IS NULL').update_all('sticky = 0')
   end
 
   def self.down
index 1c31feced04f0531722ed178f560419f9e60734c..e7c72d53274e3d839315d50f8beacd84d4c468b1 100644 (file)
@@ -1,6 +1,6 @@
 class PopulateUsersType < ActiveRecord::Migration
   def self.up
-    Principal.update_all("type = 'User'", "type IS NULL")
+    Principal.where("type IS NULL").update_all("type = 'User'")
   end
 
   def self.down
index 923c78fc0f316a4f2933fba300bc7d443722d5dc..93c5cfba2c9c328a31b0a0140718d3aa2a58d699 100644 (file)
@@ -1,9 +1,11 @@
 class FixUsersCustomValues < ActiveRecord::Migration
   def self.up
-    CustomValue.update_all("customized_type = 'Principal'", "customized_type = 'User'")
+    CustomValue.where("customized_type = 'User'").
+      update_all("customized_type = 'Principal'")
   end
 
   def self.down
-    CustomValue.update_all("customized_type = 'User'", "customized_type = 'Principal'")
+    CustomValue.where("customized_type = 'Principal'").
+      update_all("customized_type = 'User'")
   end
 end
index 401f634079c9d10c505117fdff2b79761ec4d324..518a450f4e2c620663406d9e0c11125ad33edc0c 100644 (file)
@@ -2,16 +2,20 @@ class ChangeUsersMailNotificationToString < ActiveRecord::Migration
   def self.up
     rename_column :users, :mail_notification, :mail_notification_bool
     add_column :users, :mail_notification, :string, :default => '', :null => false
-    User.update_all("mail_notification = 'all'", "mail_notification_bool = #{connection.quoted_true}")
-    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)")
-    User.update_all("mail_notification = 'only_my_events'", "mail_notification NOT IN ('all', 'selected')")
+    User.where("mail_notification_bool = #{connection.quoted_true}").
+      update_all("mail_notification = 'all'")
+    User.where("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)").
+      update_all("mail_notification = 'selected'")
+    User.where("mail_notification NOT IN ('all', 'selected')").
+      update_all("mail_notification = 'only_my_events'")
     remove_column :users, :mail_notification_bool
   end
 
   def self.down
     rename_column :users, :mail_notification, :mail_notification_char
     add_column :users, :mail_notification, :boolean, :default => true, :null => false
-    User.update_all("mail_notification = #{connection.quoted_false}", "mail_notification_char <> 'all'")
+    User.where("mail_notification_char <> 'all'").
+      update_all("mail_notification = #{connection.quoted_false}")
     remove_column :users, :mail_notification_char
   end
 end
index 314932883bf3392cb8464b5e5421c1e45c24d42c..48d38713870f13dde8dbef7e98b93b2bc9a94388 100644 (file)
@@ -3,7 +3,8 @@ class CopyRepositoriesLogEncoding < ActiveRecord::Migration
     encoding = Setting.commit_logs_encoding.to_s.strip
     encoding = encoding.blank? ? 'UTF-8' : encoding
     # encoding is NULL by default
-    Repository.update_all(["log_encoding = ?", encoding], "type IN ('Bazaar', 'Cvs', 'Darcs')")
+    Repository.where("type IN ('Bazaar', 'Cvs', 'Darcs')").
+                 update_all(["log_encoding = ?", encoding])
   end
 
   def self.down
index f959f4c339d54c5b20db8a6bc320d213a770811f..be720aafa93b9c6cfbb320606667ceeac75cfb53 100644 (file)
@@ -8,8 +8,8 @@ class ChangeAttachmentsContainerDefaults < ActiveRecord::Migration
 
     change_column :attachments, :container_id, :integer, :default => nil, :null => true
     change_column :attachments, :container_type, :string, :limit => 30, :default => nil, :null => true
-    Attachment.update_all "container_id = NULL", "container_id = 0"
-    Attachment.update_all "container_type = NULL", "container_type = ''"
+    Attachment.where("container_id = 0").update_all("container_id = NULL")
+    Attachment.where("container_type = ''").update_all("container_type = NULL")
 
     add_index :attachments, [:container_id, :container_type]
   end