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

Postgresql doesn't accepts limits on text columns #8276

Merged
merged 1 commit into from Nov 20, 2012

Conversation

pwnall
Copy link
Contributor

@pwnall pwnall commented Nov 20, 2012

TL;DR similar to accepted pull request #6328, but this time targeting text columns
#6238

The long story: PostgreSQL doesn't take a limit for "text" columns so developers must choose between removing :limit from their binary column definitions, and not being able to target pgsql.

This change drops :limit specifications, when migrations are applied against a pgsql database. It's not ideal, because the limit information is lost. However, the mysql adapters do something similar, so I hope the approach is OK.

A better long-term solution might be to map :text columns without :limit to "text", and :text columns with :limit to "character varying(xxx)". However, that requires changes in the code that maps postgresql types back into Rails types, and this change seems like a smaller step in the same direction.

Testing: I added a table to postgresql_specific_schema that uses :limit on :text and :binary columns. Setting up this table fails without the patch in this pull request. I also added a couple of unit tests to a new sql_types_test file, which follows the convention in the MySQL adapter tests.

Please let me know if this patch needs more work, and thank you very much for Rails!

create_table :limitless_fields, force: true do |t|
t.binary :binary, limit: 100_000
t.text :text, limit: 100_000
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this table being used anywhere else, is it really necessary?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed the detail about this new table in your comments.

@carlosantoniodasilva
Copy link
Member

It's going to need a changelog entry.

/cc @rafaelfranca @tenderlove

@rafaelfranca
Copy link
Member

Seems good. We need the CHANGELOG entry

@pwnall
Copy link
Contributor Author

pwnall commented Nov 20, 2012

@carlosantoniodasilva Sorry for being confusing! Should I add a comment saying what the table is for?

@rafaelfranca I was hoping to backport this to 3-2-stable, like I did for #6328 / #6418. Should I add the entry to the CHANGELOG there? I'm sorry if I'm doing this wrong by the way, I thought bug fixes should first be applied to master and then backported, but I'm not sure how well that works for the CHANGELOG.

Thank you for your guidance!

@rafaelfranca
Copy link
Member

We are adding CHANGELOG entries for all the branches that we apply the patch. So bug fixes are first in master and then backported, but the CHANGELOG entry need to be added to master too.

@pwnall
Copy link
Contributor Author

pwnall commented Nov 20, 2012

@rafaelfranca Thank you very much for explaining! Should my CHANGELOG entry describe the :limit changes to both :binary and :text then?

@rafaelfranca
Copy link
Member

Yes

rafaelfranca added a commit that referenced this pull request Nov 20, 2012
Postgresql doesn't accepts limits on text columns
@rafaelfranca rafaelfranca merged commit 3a89068 into rails:master Nov 20, 2012
@pwnall
Copy link
Contributor Author

pwnall commented Nov 20, 2012

@rafaelfranca wow that was fast. Thank you so much! 👍 👍 👍

@carlosantoniodasilva
Copy link
Member

@pwnall no need for comments now :), thanks.

rafaelfranca added a commit that referenced this pull request Nov 20, 2012
Postgresql doesn't accepts limits on text columns
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants