-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Make floating-point types consistent #48861
Conversation
Please provide the documentation that would need to be included in a step by step upgrade for Laravel 11 if this PR was merged. |
Mark as ready for review when done please. |
Why was the unsigned removed from decimal()? Who made the decision to merge this. I use this and am having issues upgrading to 11. 1 database out of them all deprecating a feature doesn't mean it should be removed. Mariadb still has it and mysql hasn't got rid of it yet. What a stupid decision to allow the removal of the unsigned attribute on decimal() |
@bluedreamer just use |
But why was a breaking public API change allowed for what amounts to a cosmetic reason? Why wasn't the param deprecated in documentation only? Wasted my time. |
Regardless of anything, the PRs that @hafezdivandari delivers are always of a high standard of description, incredible! |
Laravel: Heads up, your documentation specifies before your PR This is not the case.
I have found having to set the precision explicitly to |
@Vimiso I've explained that the default
|
Ah got you, my bad! |
Fixes #3151, #7298, #9089, #9103, #13258, #18776, #21032, #21827, #42308 Related to laravel/ideas#1527 and #47080
This PR makes
float
anddouble
column types consistent across all databases and also removesunsignedDecimal
,unsignedDouble
, andunsignedFloat
column types.Why?
Almost all databases have 4-bytes single-precision and 8-bytes double-precision storage types when declaring floating-point types (approximate numeric data values). Current syntax is inconsistent on Laravel and there is no way to declare precision value.
FLOAT(M,D)
andDOUBLE(M,D)
syntax is deprecated and you should expect support for it to be removed in a future version of MySQL. SourceUNSIGNED
attribute is deprecated for columns of typeFLOAT
,DOUBLE
, andDECIMAL
(and any synonyms); you should expect support for it to be removed in a future version of MySQL. SourceChanges
$blueprint->float($column, $total = 8, $places = 2, $unsigned = false)
to$blueprint->float($column, $precision = 53)
$blueprint->double($column, $total = 8, $places = 2, $unsigned = false)
to$blueprint->double($column)
$blueprint->decimal($column, $total = 8, $places = 2, $unsigned = false)
to$blueprint->decimal($column, $total = 8, $places = 2)
$blueprint->unsignedFloat()
$blueprint->unsignedDouble()
$blueprint->unsignedDecimal()
Before this PR
$table->float('foo')
double(8, 2)
double precision
float
float
$table->float('foo', 9)
double(9, 2)
double precision
float
float
$table->float('foo', 9, 3)
double(9, 3)
double precision
float
float
$table->float('foo', 9, null)
double
double precision
float
float
$table->float('foo', null, null)
double
double precision
float
float
$table->double('foo')
double(8, 2)
double precision
float
float
$table->double('foo', 9)
double(9, 2)
double precision
float
float
$table->double('foo', 9, 3)
double(9, 3)
double precision
float
float
$table->double('foo', 9, null)
double
double precision
float
float
$table->double('foo', null, null)
double
double precision
float
float
After this PR
$table->float('foo')
float(53)
float(53)
float(53)
float
$table->float('foo', 24)
float(24)
float(24)
float(24)
float
$table->float('foo', null)
float
float
float
float
$table->double('foo')
double
double precision
double precision
double
Comparison of Floating-Point Types on Different DBs
FLOAT(M, D)
REAL
)DOUBLE(M, D)
REAL
)FLOAT(1 to 24)
FLOAT
)real
)float(24)
)REAL
)FLOAT(25 to 53)
DOUBLE
)double precision
)float(53)
)REAL
)FLOAT
FLOAT
)double precision
)float(53)
)REAL
)DOUBLE
DOUBLE
)REAL
)DOUBLE PRECISION
DOUBLE
)double precision
)float(53)
)REAL
)REAL
DOUBLE
)real
)float(24)
)REAL
)Upgrade guide
The
double
andfloat
column types of database migrations have been rewritten to make these types consistent across all databases:The
double
column type now creates aDOUBLE
equivalent column without total digits and places (digits after decimal point), which is the standard syntax in SQL. Therefore, you may remove the arguments for$total
and$places
:The
float
column type now creates aFLOAT
equivalent column without total digits and places (digits after decimal point), but with an optional$precision
specification to determine storage size as a 4-byte single-precision column or an 8-byte double-precision column. Therefore, you may remove the arguments for$total
and$places
and specify the optional$precision
to your desired value and according to your database's documentation. The default$precision
is set to 53 that would result in 8-byte double-precision column on all database drivers:The
$unsigned
parameter of the$table->decimal()
,$table->double()
, and$table->float()
methods has been removed. Actually, this were only supported on MySQL. However, You may force deprecatedUNSIGNED
attribute using->unsigned()
modifier:The
unsignedDecimal
,unsignedDouble
, andunsignedFloat
column types have been removed. Therefore, you may use equivalent column types and forcing deprecatedUNSIGNED
attribute using->unsigned()
modifier. Actually, this were only supported on MySQL: