Skip to content
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

Setting SQL mode by force #53

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ $dumper->setTableLimits([
'users' => [20, 10], //MySql query equivalent "... LIMIT 20 OFFSET 10"
]);
```

## SQL mode

Environment variable `SQL_MODE` can be used to set it forcefully e.g.:

```dotenv
SQL_MODE=REAL_AS_FLOAT,PIPES_AS_CONCAT,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,STRICT_ALL_TABLES
```

This will do basically following:

```php
SET SESSION sql_mode='" . getenv('SQL_MODE') . "'";
```

## Dump Settings

Dump settings can be changed from default values with 4th argument for Mysqldump constructor:
Expand Down
8 changes: 7 additions & 1 deletion src/DumpSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DumpSettings
'skip-definer' => false,
'where' => '',
/* deprecated */
'disable-foreign-keys-check' => true
'disable-foreign-keys-check' => true,
];
private array $settings;

Expand All @@ -62,6 +62,12 @@ public function __construct(array $settings)
$this->settings['init_commands'][] = "SET TIME_ZONE='+00:00'";
}

$sqlMode = getenv('SQL_MODE') ?? null;

if ($sqlMode && is_string($sqlMode)) {
$this->settings['init_commands'][] = "SET SESSION sql_mode='" . $sqlMode . "'";
}

$diff = array_diff(array_keys($this->settings), array_keys(self::$defaults));

if (count($diff) > 0) {
Expand Down