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.
…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.
…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.