mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-31 10:17:13 +02:00
handle unique keys
This commit is contained in:
@ -98,6 +98,11 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
|
|||||||
// Now remove handled indexes
|
// Now remove handled indexes
|
||||||
$sql = preg_replace($pattern, '', $sql);
|
$sql = preg_replace($pattern, '', $sql);
|
||||||
|
|
||||||
|
|
||||||
|
$pattern = "/(,\s*)?UNIQUE KEY\s+[a-zA-Z0-9_]+\s+(\([a-zA-Z0-9_,\s]+\))/";
|
||||||
|
$replacement = "$1UNIQUE $2";
|
||||||
|
$sql = preg_replace($pattern, $replacement, $sql);
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,4 +93,35 @@ final class rewriteTest extends TestCase
|
|||||||
$postgresql = pg4wp_rewrite($sql);
|
$postgresql = pg4wp_rewrite($sql);
|
||||||
$this->assertSame(trim($postgresql), trim($expected));
|
$this->assertSame(trim($postgresql), trim($expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function test_it_handles_keys()
|
||||||
|
{
|
||||||
|
$sql = <<<SQL
|
||||||
|
CREATE TABLE 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 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user