Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres Schema adapter ignores limit argument for binary columns #29922

Closed
betesh opened this issue Jul 24, 2017 · 3 comments
Closed

Postgres Schema adapter ignores limit argument for binary columns #29922

betesh opened this issue Jul 24, 2017 · 3 comments

Comments

@betesh
Copy link
Contributor

betesh commented Jul 24, 2017

Steps to reproduce

$ rails new postgres-without-limits

Create this migration:

class CreateAttachments < ActiveRecord::Migration[5.1]
  def change
    create_table :attachments, id: false do |t|
      t.binary :content, limit: 1.megabyte
    end
  end
end
$ bin/rake db:setup
$ bin/rake db:migrate

Expected behavior

db/schema.rb should show that the column has a size limit, and the column should actually have that limit.
http://api.rubyonrails.org/v5.1.2/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column states: :limit - Requests a maximum column length. This is the number of characters for a :string column and number of bytes for :text, :binary and :integer columns, so it should be valid for a binary type.

Actual behavior

The limit argument is not passed along to the CREATE command. It does not show up in the db/schema.rb file, and I can create records with more than 1 MB in the column.

System configuration

Rails version: 5.1.2

Ruby version: 2.4.0

@rafaelfranca
Copy link
Member

PostgreSQL doesn't support limit for binary columns

@betesh
Copy link
Contributor Author

betesh commented Jul 25, 2017

Can we update the docs to not be confusing then?

@sgrif
Copy link
Contributor

sgrif commented Jul 25, 2017

The docs do explicitly say "This is the number of bytes for binary columns". We should probably just not list the types affected by it explicitly, or at least mention "this field is ignored by some backends" since I don't think there is any type we support for which postgres will actually apply a limit.

@sgrif sgrif reopened this Jul 25, 2017
lugray pushed a commit to lugray/rails that referenced this issue Jul 25, 2017
The limit option is ignored by PostgreSQL and may be ignored by 3rd
party backends.  Make this clear in the docs.  Fixes rails#29922.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants