rails/rails — pull request #8276 by pwnall (2012-11-20 03:47:16+00:00)
Title: Postgresql doesn't accepts limits on text columns

TL;DR similar to accepted pull request #6328, but this time targeting text columns
https://github.com/rails/rails/pull/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!