Skip to content

Commit

Permalink
Ensure UI tests use the correct charset / collation on TiDb (#22486)
Browse files Browse the repository at this point in the history
* Ensure UI tests use the correct charset / collation on TiDb

* Apply review feedback

Co-authored-by: Marc Neudert <[email protected]>

---------

Co-authored-by: Marc Neudert <[email protected]>
  • Loading branch information
sgiehl and mneudert committed Aug 7, 2024
1 parent 885de52 commit ff1b746
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/PHPUnit/Fixtures/SqlDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Piwik\Access;
use Piwik\ArchiveProcessor\Rules;
use Piwik\Config;
use Piwik\Config\DatabaseConfig;
use Piwik\Db;
use Piwik\Tests\Framework\Fixture;
use Exception;
Expand Down Expand Up @@ -68,6 +69,12 @@ public function setUp(): void
$defaultsFile = $this->makeMysqlDefaultsFile($user, $password);

$cmd = "mysql --defaults-extra-file=\"$defaultsFile\" -h \"$host\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1";

if (DatabaseConfig::getConfigValue('schema') === 'Tidb') {
// For TiDb we need to remove the default charset from the create table statements, otherwise it will use the default charset collation, which differs from database default collation
$cmd = "sed 's/ DEFAULT CHARSET=utf8mb4//' \"$deflatedDumpPath\" | mysql --defaults-extra-file=\"$defaultsFile\" -h \"$host\" {$this->dbName} 2>&1";
}

exec($cmd, $output, $return);
if ($return !== 0) {
throw new Exception("Failed to load sql dump: " . implode("\n", $output));
Expand Down

0 comments on commit ff1b746

Please sign in to comment.