does this only happen in CI or also in prod?
Where to store init sql query with databsase mode settings
Hi there, I need to run this sql
DB::statement("SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"); // This is copy from MySqlConnector.php
It is modification of MySqlConnector.php::configureConnection() without ONLY_FULL_GROUP_BY. I want to use strict mode but without ONLY_FULL_GROUP_BY. ChatGPT lead me to add it to the AppServiceProvider::boot() method. Everything works BUT when I try to run our Bitbucket pipeline which contains command php artisan cache:clear it fail on error:
RUN cd /application && php artisan cache:clear
#21 sha256:1b4a053901e3fd6704ba3b6c9e8095bf143bba4784f432ebd7cb6e6bfe8b2fda
#21 0.513
#21 0.513 Illuminate\Database\QueryException
#21 0.513
#21 0.513 SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION')
#21 0.513
#21 0.513 at vendor/laravel/framework/src/Illuminate/Database/Connection.php:825
#21 0.518 821▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
#21 0.518 822▕ );
#21 0.518 823▕ }
#21 0.518 824▕
#21 0.518 ➜ 825▕ throw new QueryException(
#21 0.518 826▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
#21 0.518 827▕ );
#21 0.518 828▕ }
#21 0.518 829▕ }
#21 0.518
#21 0.518 1 [internal]:0
#21 0.518 Illuminate\Foundation\Application::Illuminate\Foundation\{closure}()
#21 0.519 +16 vendor frames
#21 0.519
#21 0.519 18 app/Providers/AppServiceProvider.php:36
It seems the connection is not resolved yet when cache:clear is called. The question is what is better place where to store this command to avoid this behaviour? Thanks.
They go in the connection definitions in config/database.php, in a modes array:
'mysql' => [
(...)
'modes' => [
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
(...)
],
],
Please or to participate in this conversation.