Merge pull request #132 from PostgreSQL-For-Wordpress/hotfix/primary_key_rewriting

remove key names which are not supported during key creation in postgres
This commit is contained in:
Matthew Bucci
2024-10-17 05:10:46 -04:00
committed by GitHub
2 changed files with 7 additions and 1 deletions

View File

@ -82,10 +82,16 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
$sql = preg_replace($pattern, '', $sql);
// Rewrite unique keys to just be UNIQUE without a key name
$pattern = "/(,\s*)?UNIQUE KEY\s+[a-zA-Z0-9_]+\s+(\([a-zA-Z0-9_,\s]+\))/";
$replacement = "$1UNIQUE $2";
$sql = preg_replace($pattern, $replacement, $sql);
// Rewrite Primary keys to not have a key name
$pattern = '/PRIMARY KEY\s+\w+\s*\((.*?)\)/';
$replacement = 'PRIMARY KEY ($1)';
$sql = preg_replace($pattern, $replacement, $sql);
return $sql;
}

View File

@ -702,7 +702,7 @@ final class rewriteTest extends TestCase
mysqlcolumn_detail text NOT NULL DEFAULT '',
type varchar(210) NOT NULL DEFAULT 'post',
item bigint NOT NULL DEFAULT '0',
PRIMARY KEY doctermitem (doc, term, item)
PRIMARY KEY (doc, term, item)
);
SQL;