Fix for long index names in rails using postgresql (fix for "Input string is longer than NAMEDATALEN-1 (63)")
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
endTo 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 Ruby on Rails, PostgreSQL | 2 comments |
Trackbacks<
Use the following link to trackback from your own site:
http://nopugs.com/trackbacks?article_id=32
24/05/2010 at 11h37
After installing this plugin my rake tests won’t run, I get :
/dependencies.rb:440:in `loadmissingconstant’: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter (NameError)
Is there any way to fix this?
24/05/2010 at 12h53
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.