Skip to content

Commit

Permalink
Add patch to set maximum precision of timestamp DB columns [API-378]
Browse files Browse the repository at this point in the history
When running unit tests, running all the migrations on the project on a new database was throwing errors related to the precision of timestamp fields. This was fixed in Laravel 9, so until then we'll patch the package causing the issue.
  • Loading branch information
nikhiltri committed Jun 29, 2023
1 parent 318bc9c commit 720bfd5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
24 changes: 23 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
{
"type": "vcs",
"url": "https://github.com/jeskew/amazon-es-php.git"
},
{
"type": "package",
"package": {
"type": "metapackage",
"name": "vendor/package-patches",
"version": "1.1.0",
"require": {
"netresearch/composer-patches-plugin": "~1.2"
},
"extra": {
"patches": {
"marktopper/doctrine-dbal-timestamp-type": [
{
"title": "API-378: Get unit tests working with fresh database",
"url": "patches/API-378---set-maximum-precision-for-timestamp-types.diff"
}
]
}
}
}
}
],
"require": {
Expand All @@ -40,7 +61,8 @@
"league/flysystem-aws-s3-v3": "^1.0",
"marijnvdwerf/material-palette": "^1.3",
"marktopper/doctrine-dbal-timestamp-type": "^1.0",
"sentry/sentry-laravel": "^2.9"
"sentry/sentry-laravel": "^2.9",
"vendor/package-patches": "^1.1"
},
"require-dev": {
"brianium/paratest": "^6.4",
Expand Down
20 changes: 19 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions patches/API-378---set-maximum-precision-for-timestamp-types.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/TimestampType.php b/src/TimestampType.php
index 67c1126..6430e4a 100644
--- a/src/TimestampType.php
+++ b/src/TimestampType.php
@@ -45,7 +45,7 @@ class TimestampType extends Type
*/
protected function getMysqlPlatformSQLDeclaration(array $fieldDeclaration)
{
- $columnType = $fieldDeclaration['precision'] ? "TIMESTAMP({$fieldDeclaration['precision']})" : 'TIMESTAMP';
+ $columnType = $fieldDeclaration['precision'] ? "TIMESTAMP(".min((int) $fieldDeclaration['precision'], 6).")" : 'TIMESTAMP';

if (isset($fieldDeclaration['notnull']) && $fieldDeclaration['notnull'] == true) {
return $columnType;

0 comments on commit 720bfd5

Please sign in to comment.