framework icon indicating copy to clipboard operation
framework copied to clipboard

[10.x] Fix: select maximum supported timestamp precision

Open nandi95 opened this issue 1 year ago • 0 comments

Targeting master as did not get a response to https://github.com/laravel/framework/pull/43535#issuecomment-1223161842

On the latest version (9.23.0) when renaming a timestamp column, it does not correctly gets the precision when using the TIMESTAMP() function in the generated alter statement. $table->renameColumn('created_at', 'old_created_at'); would result something similar to:

Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1426 Too big precision 10 specified for 'old_created_at'. Maximum is 6....

To replicate, rename a timestamp while using sql server, postgres or mysql.

NOTE: In testing, I cannot replicate the issue as the test suit seems to be ran with sqlite which ignores the precision and uses DATETIME. If the testing workflow also run the tests using the above platforms, then they won't fail due to my changes and this was not covered before. In any case my migration now succesfully runs after this change.

This PR ensures when the inferred precision value is higher than what the platform supports, it defaults back to the highest supported value.

Rest of the changes are updates advised by deprecations (using classnames as oppoed to deprecated ->getName() and match the abstract function's argument name).

Issue where this was previously reported: https://github.com/laravel/framework/issues/43535

nandi95 avatar Sep 20 '22 23:09 nandi95