No Pugs

they're evil

Fix for long index names in rails using postgresql (fix for "Input string is longer than NAMEDATALEN-1 (63)")

Posted by miles Sun, 02 May 2010 23:26:00 GMT

If you are getting this when running rails migrations using a postgresql adapter:

Input string is longer than NAMEDATALEN-1 (63)

Then this tiny plugin can solve this problem. Index names longer than 63 characters work fine with some postgresql adapters and not others. I’m not sure why. This adds a method to ActiveRecord::ConnectionAdapters::PostgreSQLAdapter that keeps the index_names under the limit.

here’s the entire piece of code:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
  #There are PostgreSQL drivers/versions of drivers that truncate
  #index names to 63 characters. Since some do not, this override makes
  #sure that the truncate occurs regardless of PostgreSQL driver.
  def index_name(table, columns)
    super(table, columns)[0..62]
  end
end

To install this plugin using ext, you can use:

ext install git://github.com/azimux/ax_fix_long_psql_index_names.git

or, using rake plugin:

./script/plugin install git://github.com/azimux/ax_fix_long_psql_index_names.git

Posted in , | 2 comments |

Trackbacks

Use the following link to trackback from your own site:
http://nopugs.com/trackbacks?article_id=32

Comments

Leave a comment

  1. Jereme Monteau
    21 days later:
    After installing this plugin my rake tests won’t run, I get : /dependencies.rb:440:in `load_missing_constant’: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter (NameError) Is there any way to fix this?
  2. miles
    21 days later:

    Hi Jereme, Interesting.

    What version of Rails are you using?

    I’m using 2.3.6

    I haven’t tested this on any other versions.

    If I can reproduce the problem I can see if I can fix it for your version.

Leave a comment