migrations-generator icon indicating copy to clipboard operation
migrations-generator copied to clipboard

Double converted to float(10,0)

Open codengine opened this issue 10 years ago • 7 comments

Hi, I've just tested your generator and its working pretty well. I just noticed that double columns are converted to float(10,0). Is this behaviour intended?

Greets

codengine avatar May 22 '14 08:05 codengine

No, this seems to be a bug. The whole idea was to generate migrations that resembles the database as closely as Laravel Migrations allow. Both float and double are available, so this shouldn't happen.

Thanks for reporting this, will take a look at it.

Xethron avatar May 22 '14 08:05 Xethron

:+1: Thanks. I've made a 1:1 comparison between my self-written migrations and the ones generated using your package.

They're almost 100% equal. I recommend a tool called Toad (http://www.quest.com/toad-for-mysql/) for comparisons. I use it for servers where native migrations aren't possible.

codengine avatar May 22 '14 09:05 codengine

I'm looking into it. It looks like it is the defaults precision/scale of Doctrine.

Edit: Yeah, so we're forcing decimal, double and float to specify their precision and scale, but there's no way to tell from the column details obtained from Doctrine whether or not those are default values or really those specified in the database...

Reading the doctrine docs (http://docs.doctrine-project.org/en/2.0.x/reference/annotations-reference.html), they say the following:

precision: The precision for a decimal (exact numeric) column (Applies only for decimal column)

scale: The scale for a decimal (exact numeric) column (Applies only for decimal column)

Thus it looks like we should only apply precision/scale to decimal and not offer the ability to specify those for float/double.

tomzx avatar May 27 '14 16:05 tomzx

@tomzx I'd second that.

codengine avatar May 27 '14 17:05 codengine

There's one thing to consider though, the current code of laravel will force float to be (8, 2) when you use ->float('my_column').

tomzx avatar May 27 '14 23:05 tomzx

Still not sure why it converts double fields to floats...

Xethron avatar May 28 '14 13:05 Xethron

Because the double type does not exist in Doctrine, they call it float. Here's the list of available types: http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html.

If you want to do it properly (respecting Doctrine), the SQL float type does not exist, and you must replace the type float with double when you are about to generate the Blueprint call ($table->float() -> $table->double()).

In other words:

Currently:

Source (in DB) Doctrine type Final (migrations-generator currently generates)
float float float
double float float

What it should do (respecting Doctrine):

Source (in DB) Doctrine type Final (migrations-generator should generate)
float float double
double float double

Thus it is not possible, at least using Doctrine, to generate the appropriate types due to the loss of information in the transformation process.

tomzx avatar May 30 '14 00:05 tomzx