[11.x] Make floating-point types consistent #48861
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: