views:

203

answers:

2

This is a follow-up to a question I'd asked earlier which phrased this as more of a programming problem than a database problem.

http://stackoverflow.com/questions/2935985/postgres-error-with-sinatra-haml-datamapper-on-heroku

I believe the problem has been isolated to the storage of the ID column in Heroku's Postgres database after running db:push.

In short, my app runs properly on my original MySQL database, but throws Postgres errors on Heroku when executing any query on the ID column, which seems to have been stored in Postgres as TEXT even though it is stored as INT in MySQL. My question is why the ID column is being created as INT in Postgres on the data transfer to Heroku, and whether there's any way for me to prevent this.

Here's the output from a heroku console session which demonstrates the issue:

Ruby console for myapp.heroku.com
>> Post.first.title
=> "Welcome to First!"
>> Post.first.title.class
=> String
>> Post.first.id
=> 1
>> Post.first.id.class
=> Fixnum
>> Post[1]
PostgresError: ERROR:  operator does not exist: text = integer
LINE 1: ...", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER...
                                                         ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Query: SELECT "id", "name", "email", "url", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER BY "id" LIMIT 1

Thanks!

A: 

Can't you pull it to a local postgres database. Do the necessaery ALTER/COPY?MOVE TABLE magic and push it back again?

Peter Tillemans
sevennineteen
I'll keep my fingers crossed.
Peter Tillemans
+1  A: 

I opened a support request at Heroku and their guys were able to quickly resolve this for me. After sending them my MySQL table schema, they suggested that I remove UNSIGNED from my ID columns:

Can you remove the UNSIGNED bit and see if that works? I don't think sequel supports that. If that works, I'll write a patch to sequel.

Once I did that, I was able to migrate the database the same way as before using db:push, and the app was fully functional.

Continually more impressed w/ Heroku, both for their platform and support.

sevennineteen
This should be fixed in the next version of Sequel: http://github.com/jeremyevans/sequel/commit/ee087d67654ce4b295a6cf645bbf1d8b76efd8c3
Jeremy Evans