Why can't I run a Rake task inside my migration?

I have a Rake task which I’ve developed as part of a set of data
migrations. The task has to be run after a particular migration has run.
The migration changes the table structure and then the Rake task comes
in and plays with the data.

So the obvious thing is to invoke the Rake task at the end of the table
structure changes in the migration. But if I do that then I get an error
coming back from the database. It’s an error from Postgresql, but I
don’t get the error if I run the Rake task from the command line. Is
there something that’s going on inside the migration which might change
the way a Rake task would work. The only thing I can see is that in a
migration it’s inside a transaction, but I can’t see why that would give
me an error.

Thanks

John S.

What error is coming back from the database? How are you executing the
rake task? When you’re running a migration, you are running a rake
task.

Robby

On Mon, Aug 10, 2009 at 7:00 AM, John
Small[email protected] wrote:

there something that’s going on inside the migration which might change


Robby R.
Chief Evangelist, Partner

PLANET ARGON, LLC
design // development // hosting w/Ruby on Rails

http://planetargon.com/
http://robbyonrails.com/
http://twitter.com/planetargon
aim: planetargon

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]

Robby R. wrote:

…When you’re running a migration, you are running a rake
task.

Which is exactly why I’m so puzzled. The postgres adapter gets a problem
when trying to get the data structure for a table, it fails on this
query

SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,
a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = ‘territories’::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Which isn’t going to tell you very much.

I’ve got no time to dig down into the depths of the postresql adapter
and I can work with the problem by running the rake task outside of a
migration. I was just hoping to be able to package everything up inside
a single call to rake db:migrate, obviously not.

Ta

John S.

John S. wrote:

Robby R. wrote:

…When you’re running a migration, you are running a rake
task.

Which is exactly why I’m so puzzled. The postgres adapter gets a problem
when trying to get the data structure for a table, it fails on this
query

SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,
a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = ‘territories’::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Which isn’t going to tell you very much.

Don’t assume that. Anyway, you still haven’t told us what the error
message is!

I’ve got no time to dig down into the depths of the postresql adapter
and I can work with the problem by running the rake task outside of a
migration. I was just hoping to be able to package everything up inside
a single call to rake db:migrate, obviously not.

You might still be able to. But we can’t help unless you actually
provide things like error messages. :slight_smile:

Ta

John S.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

By chance are you attempting to add a new table for a new model? (and
then trying to add some data to populate it?)

Robby

On Mon, Aug 10, 2009 at 11:21 AM, John
Small[email protected] wrote:

 SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,
and I can work with the problem by running the rake task outside of a


Robby R.
Chief Evangelist, Partner

PLANET ARGON, LLC
design // development // hosting w/Ruby on Rails

http://planetargon.com/
http://robbyonrails.com/
http://twitter.com/planetargon
aim: planetargon

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs