finish conversion of storage_quota to bytes from MB

At this point, nobody should be writing quotas as bytes anymore, so we mass
convert the remainder to bytes and get rid of the backwards-compatible code.

Change-Id: Ic5d6f8c8eaed947aef48dd7b1da348158f4ea2a4
Reviewed-on: https://gerrit.instructure.com/4276
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
Zach Wily 2011-06-17 14:19:46 -06:00
parent 65ed1dac46
commit 4cf56a75b1
4 changed files with 25 additions and 4 deletions

View File

@ -403,8 +403,6 @@ class ApplicationController < ActionController::Base
return unless @context
@quota = Setting.get_cached('context_default_quota', 50.megabytes.to_s).to_i
@quota = @context.quota if (@context.respond_to?("quota") && @context.quota)
# TODO: remove this once values in the db have been migrated to be in bytes and not MB.
@quota = @quota.megabytes if @quota < 1.megabyte
@quota_used = @context.attachments.active.sum('COALESCE(size, 0)', :conditions => { :root_attachment_id => nil }).to_i
end

View File

@ -309,7 +309,7 @@ class Account < ActiveRecord::Base
end
def default_storage_quota_mb
default_storage_quota < 1.megabyte ? default_storage_quota : default_storage_quota / 1.megabyte
default_storage_quota / 1.megabyte
end
def default_storage_quota_mb=(val)

View File

@ -703,7 +703,7 @@ class Course < ActiveRecord::Base
end
def storage_quota_mb
storage_quota < 1.megabyte ? storage_quota : storage_quota / 1.megabyte
storage_quota / 1.megabyte
end
def storage_quota_mb=(val)

View File

@ -0,0 +1,23 @@
class ConvertStorageQuotasToBytes < ActiveRecord::Migration
FIELDS_TO_FIX = [
[ User, :storage_quota ],
[ Account, :storage_quota ],
[ Account, :default_storage_quota ],
[ Course, :storage_quota ],
[ Group, :storage_quota ],
]
def self.up
FIELDS_TO_FIX.each do |klass, field|
change_column klass.table_name.to_s, field, :integer, :limit => 8
klass.connection.execute("UPDATE #{klass.table_name} SET #{field.to_s} = #{field.to_s} * 1024 * 1024 WHERE #{field.to_s} IS NOT NULL AND #{field.to_s} < 1024 * 1024")
end
end
def self.down
FIELDS_TO_FIX.each do |klass, field|
change_column klass.table_name.to_s, field, :integer, :limit => 4
klass.connection.execute("UPDATE #{klass.table_name} SET #{field.to_s} = #{field.to_s} / 1024 * 1024 WHERE #{field.to_s} IS NOT NULL AND #{field.to_s} >= 1024 * 1024")
end
end
end