So hey Mark. Kind of unfortunate Postgres doesn't cast this automatically within the alter table command. I just tinkered with a simple Postgres table and I have to do something like this to get it to work:
ALTER TABLE instances ALTER COLUMN instance_type_id TYPE integer USING instance_type_id::int;
Initially I just tried a simple:
ALTER TABLE instances ALTER COLUMN instance_type_id TYPE integer;
The second command gives a casting error.
In any case it looks like what you have done is the best we can do in terms of converting data in a database agnostic fashion.
So hey Mark. Kind of unfortunate Postgres doesn't cast this automatically within the alter table command. I just tinkered with a simple Postgres table and I have to do something like this to get it to work:
ALTER TABLE instances ALTER COLUMN instance_type_id TYPE integer USING instance_ type_id: :int;
Initially I just tried a simple:
ALTER TABLE instances ALTER COLUMN instance_type_id TYPE integer;
The second command gives a casting error.
In any case it looks like what you have done is the best we can do in terms of converting data in a database agnostic fashion.
Looks good.