handle table charsets

This commit is contained in:
mattbucci
2024-01-08 05:08:57 +00:00
parent 53125aec2d
commit a90ab01a9b
2 changed files with 33 additions and 1 deletions

View File

@ -30,6 +30,7 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
' COLLATE utf8mb4_unicode_520_ci' => '',
' COLLATE utf8_general_ci' => '',
' CHARACTER SET utf8' => '',
' DEFAULT CHARSET=utf8' => '',
// For flash-album-gallery plugin
' tinyint' => ' smallint'
@ -46,7 +47,12 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
$table = $matches[1];
// Remove trailing spaces
$sql = trim($sql) . ';';
$sql = trim($sql);
// Add a slash if needed
if (substr($sql,strlen($sql)-1, 1) != ";") {
$sql = $sql . ";";
}
// Translate types and some other replacements
$sql = str_ireplace(

View File

@ -280,6 +280,32 @@ final class rewriteTest extends TestCase
$this->assertSame(trim($expected), trim($postgresql));
}
public function test_it_removes_table_charsets()
{
$sql = <<<SQL
CREATE TABLE `wp_yoast_migrations` (
`id` int(11) UNSIGNED auto_increment NOT NULL,
`version` varchar(191),
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
SQL;
$expected = <<<SQL
CREATE TABLE wp_yoast_migrations (
id serial NOT NULL,
version varchar(191),
PRIMARY KEY (id)
);
SQL;
$postgresql = pg4wp_rewrite($sql);
$this->assertSame(trim($expected), trim($postgresql));
}
protected function setUp(): void
{
global $wpdb;