Migrating db from postgres to mysql rounding problems

Hi

I have a rails 3 app that has been using postgres database up until
now. I’m in the processing to switching to mysql so that I can avail
amazon’s rds. I have noticed when running my tests that in all my
models that should have decimals values the values are being rounded
to integers.

I think the problem is that the migrations don’t set :precision
and :scale values for decimal values which seem to be needed for
mysql. Looking at the tables directly this seems to be the case

Is the a better solution to this problem than editing all the
migration files?

Any pointer would be great appreciated

Conor N. wrote in post #980324:

I have a rails 3 app that has been using postgres database up until
now. I’m in the processing to switching to mysql so that I can avail
amazon’s rds. I have noticed when running my tests that in all my
models that should have decimals values the values are being rounded
to integers.

I think the problem is that the migrations don’t set :precision
and :scale values for decimal values which seem to be needed for
mysql. Looking at the tables directly this seems to be the case

Is the a better solution to this problem than editing all the
migration files?

Any pointer would be great appreciated

I wouldn’t be surprised that there are differences in the behavior
between decimal types between different databases. So yes, I’d say the
easiest fix to would be to specify the precision and scale in the
migrations, which should have been done to begin with.

An alternative to editing all the existing migration files would be to
create a new migration and modify all the affected tables/columns there.
That would keep your migrations moving forward.

I always prefer to specify precision and scale for all my decimal
columns. It helps to alleviate this problem, and makes the intent clear
for later reference as well.

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