Commit 34ec355e by Alen Zamanyan Committed by Mike Burns

Increase attachment file size from int (4 bytes) to bigint (8 bytes).

The 4 byte limit is starting to wrap around; some complaints are being seen
online, e.g.
https://stackoverflow.com/questions/34477248/rails-paperclip-rangeerror/47999887#47999887 .

Use `#sql_type` instead of `#type` in the tests. The `#type` is the category --
string, integer, datetime -- but the `#sql_type` is the storage specifics --
`TEXT`, `VARCHAR`, `BIGINT`, `DATE. Switch to the `#sql_type` so we can be sure
it's being stored correctly.
parent 90f9121a
...@@ -3,6 +3,9 @@ master: ...@@ -3,6 +3,9 @@ master:
* Improvement: Better handling of the content-disposition header. Now supports file name that is either * Improvement: Better handling of the content-disposition header. Now supports file name that is either
enclosed or not in double quotes and is case insensitive as per RC6266 grammar enclosed or not in double quotes and is case insensitive as per RC6266 grammar
* Improvement: Files without an extension will now be checked for spoofing attempts * Improvement: Files without an extension will now be checked for spoofing attempts
* Change database column type of attachment file size from unsigned 4-byte
`integer` to unsigned 8-byte `bigint`. The former type limits attachment
size to just over 2GB, which can easily be exceeded by a large video file.
6.0.0 (2018-03-09): 6.0.0 (2018-03-09):
......
...@@ -88,7 +88,7 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name| ...@@ -88,7 +88,7 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
expect_columns = [ expect_columns = [
["#{attachment_name}_file_name", :string], ["#{attachment_name}_file_name", :string],
["#{attachment_name}_content_type", :string], ["#{attachment_name}_content_type", :string],
["#{attachment_name}_file_size", :integer], ["#{attachment_name}_file_size", :bigint],
["#{attachment_name}_updated_at", :datetime] ["#{attachment_name}_updated_at", :datetime]
] ]
expect(columns).to include(*expect_columns) expect(columns).to include(*expect_columns)
...@@ -101,7 +101,7 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name| ...@@ -101,7 +101,7 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
expect_columns = [ expect_columns = [
["#{attachment_name}_file_name", :string], ["#{attachment_name}_file_name", :string],
["#{attachment_name}_content_type", :string], ["#{attachment_name}_content_type", :string],
["#{attachment_name}_file_size", :integer], ["#{attachment_name}_file_size", :bigint],
["#{attachment_name}_updated_at", :datetime] ["#{attachment_name}_updated_at", :datetime]
] ]
......
...@@ -5,7 +5,7 @@ module Paperclip ...@@ -5,7 +5,7 @@ module Paperclip
module Schema module Schema
COLUMNS = {:file_name => :string, COLUMNS = {:file_name => :string,
:content_type => :string, :content_type => :string,
:file_size => :integer, :file_size => :bigint,
:updated_at => :datetime} :updated_at => :datetime}
def self.included(base) def self.included(base)
......
...@@ -1416,7 +1416,7 @@ describe Paperclip::Attachment do ...@@ -1416,7 +1416,7 @@ describe Paperclip::Attachment do
context "and avatar_file_size column" do context "and avatar_file_size column" do
before do before do
ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :integer ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :bigint
rebuild_class rebuild_class
@dummy = Dummy.new @dummy = Dummy.new
end end
......
...@@ -7,7 +7,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do ...@@ -7,7 +7,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
before do before do
reset_table("dummies") do |d| reset_table("dummies") do |d|
d.string :avatar_file_name d.string :avatar_file_name
d.integer :avatar_file_size d.bigint :avatar_file_size
end end
reset_class "Dummy" reset_class "Dummy"
Dummy.do_not_validate_attachment_file_type :avatar Dummy.do_not_validate_attachment_file_type :avatar
......
...@@ -25,12 +25,12 @@ describe Paperclip::Schema do ...@@ -25,12 +25,12 @@ describe Paperclip::Schema do
end end
end end
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', :string]) expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', :integer]) expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', :datetime]) expect(columns).to include(['avatar_updated_at', "datetime"])
end end
it "displays deprecation warning" do it "displays deprecation warning" do
...@@ -50,12 +50,12 @@ describe Paperclip::Schema do ...@@ -50,12 +50,12 @@ describe Paperclip::Schema do
end end
it "creates attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', :string]) expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', :integer]) expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', :datetime]) expect(columns).to include(['avatar_updated_at', "datetime"])
end end
end end
...@@ -89,12 +89,12 @@ describe Paperclip::Schema do ...@@ -89,12 +89,12 @@ describe Paperclip::Schema do
end end
it "creates attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', :string]) expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', :integer]) expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', :datetime]) expect(columns).to include(['avatar_updated_at', "datetime"])
end end
end end
...@@ -119,16 +119,16 @@ describe Paperclip::Schema do ...@@ -119,16 +119,16 @@ describe Paperclip::Schema do
end end
it "creates attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', :string]) expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', :integer]) expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', :datetime]) expect(columns).to include(['avatar_updated_at', "datetime"])
expect(columns).to include(['photo_file_name', :string]) expect(columns).to include(['photo_file_name', "varchar"])
expect(columns).to include(['photo_content_type', :string]) expect(columns).to include(['photo_content_type', "varchar"])
expect(columns).to include(['photo_file_size', :integer]) expect(columns).to include(['photo_file_size', "bigint"])
expect(columns).to include(['photo_updated_at', :datetime]) expect(columns).to include(['photo_updated_at', "datetime"])
end end
end end
...@@ -164,7 +164,7 @@ describe Paperclip::Schema do ...@@ -164,7 +164,7 @@ describe Paperclip::Schema do
Dummy.connection.change_table :dummies do |t| Dummy.connection.change_table :dummies do |t|
t.column :avatar_file_name, :string t.column :avatar_file_name, :string
t.column :avatar_content_type, :string t.column :avatar_content_type, :string
t.column :avatar_file_size, :integer t.column :avatar_file_size, :bigint
t.column :avatar_updated_at, :datetime t.column :avatar_updated_at, :datetime
end end
end end
...@@ -178,12 +178,12 @@ describe Paperclip::Schema do ...@@ -178,12 +178,12 @@ describe Paperclip::Schema do
Dummy.connection.drop_attached_file :dummies, :avatar Dummy.connection.drop_attached_file :dummies, :avatar
end end
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to_not include(['avatar_file_name', :string]) expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', :string]) expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', :integer]) expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', :datetime]) expect(columns).to_not include(['avatar_updated_at', "datetime"])
end end
it "displays a deprecation warning" do it "displays a deprecation warning" do
...@@ -200,12 +200,12 @@ describe Paperclip::Schema do ...@@ -200,12 +200,12 @@ describe Paperclip::Schema do
end end
it "removes the attachment columns" do it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to_not include(['avatar_file_name', :string]) expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', :string]) expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', :integer]) expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', :datetime]) expect(columns).to_not include(['avatar_updated_at', "datetime"])
end end
end end
...@@ -214,7 +214,7 @@ describe Paperclip::Schema do ...@@ -214,7 +214,7 @@ describe Paperclip::Schema do
Dummy.connection.change_table :dummies do |t| Dummy.connection.change_table :dummies do |t|
t.column :photo_file_name, :string t.column :photo_file_name, :string
t.column :photo_content_type, :string t.column :photo_content_type, :string
t.column :photo_file_size, :integer t.column :photo_file_size, :bigint
t.column :photo_updated_at, :datetime t.column :photo_updated_at, :datetime
end end
...@@ -222,16 +222,16 @@ describe Paperclip::Schema do ...@@ -222,16 +222,16 @@ describe Paperclip::Schema do
end end
it "removes the attachment columns" do it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }
expect(columns).to_not include(['avatar_file_name', :string]) expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', :string]) expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', :integer]) expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', :datetime]) expect(columns).to_not include(['avatar_updated_at', "datetime"])
expect(columns).to_not include(['photo_file_name', :string]) expect(columns).to_not include(['photo_file_name', "varchar"])
expect(columns).to_not include(['photo_content_type', :string]) expect(columns).to_not include(['photo_content_type', "varchar"])
expect(columns).to_not include(['photo_file_size', :integer]) expect(columns).to_not include(['photo_file_size', "bigint"])
expect(columns).to_not include(['photo_updated_at', :datetime]) expect(columns).to_not include(['photo_updated_at', "datetime"])
end end
end end
......
...@@ -37,7 +37,7 @@ module ModelReconstruction ...@@ -37,7 +37,7 @@ module ModelReconstruction
table.column :other, :string table.column :other, :string
table.column :avatar_file_name, :string table.column :avatar_file_name, :string
table.column :avatar_content_type, :string table.column :avatar_content_type, :string
table.column :avatar_file_size, :integer table.column :avatar_file_size, :bigint
table.column :avatar_updated_at, :datetime table.column :avatar_updated_at, :datetime
table.column :avatar_fingerprint, :string table.column :avatar_fingerprint, :string
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment