mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-31 10:17:13 +02:00
pgrewrite should not remove IF NOT EXISTS
This commit is contained in:
@ -39,9 +39,9 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
|
|||||||
$sql = $this->original();
|
$sql = $this->original();
|
||||||
|
|
||||||
|
|
||||||
$sql = str_replace('CREATE TABLE IF NOT EXISTS ', 'CREATE TABLE ', $sql);
|
$tableSQL = str_replace('CREATE TABLE IF NOT EXISTS ', 'CREATE TABLE ', $sql);
|
||||||
$pattern = '/CREATE TABLE [`]?(\w+)[`]?/';
|
$pattern = '/CREATE TABLE [`]?(\w+)[`]?/';
|
||||||
preg_match($pattern, $sql, $matches);
|
preg_match($pattern, $tableSQL, $matches);
|
||||||
$table = $matches[1];
|
$table = $matches[1];
|
||||||
|
|
||||||
// Remove trailing spaces
|
// Remove trailing spaces
|
||||||
|
@ -167,6 +167,34 @@ final class rewriteTest extends TestCase
|
|||||||
$this->assertSame(trim($postgresql), trim($expected));
|
$this->assertSame(trim($postgresql), trim($expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_does_not_remove_if_not_exists()
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
CREATE TABLE IF NOT EXISTS wp_itsec_dashboard_lockouts (
|
||||||
|
id int NOT NULL AUTO_INCREMENT,
|
||||||
|
ip varchar(40),
|
||||||
|
time timestamp NOT NULL,
|
||||||
|
count int NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE KEY ip__time (ip, time)
|
||||||
|
)
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$expected = <<<SQL
|
||||||
|
CREATE TABLE IF NOT EXISTS wp_itsec_dashboard_lockouts (
|
||||||
|
id serial,
|
||||||
|
ip varchar(40),
|
||||||
|
time timestamp NOT NULL,
|
||||||
|
count int NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE (ip, time)
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
$postgresql = pg4wp_rewrite($sql);
|
||||||
|
$this->assertSame(trim($postgresql), trim($expected));
|
||||||
|
}
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
Reference in New Issue
Block a user