Skip to content

Commit

Permalink
numeric rewriting should be case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbucci committed Oct 17, 2024
1 parent d8b83c8 commit d46dba6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pg4wp/rewriters/CreateTableSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function rewrite_numeric_type($sql)
$numeric_types_imploded = implode('|', $numeric_types);

// Prepare regex pattern to match 'type(x)'
$pattern = "/(" . $numeric_types_imploded . ")\(\d+\)/";
$pattern = "/(" . $numeric_types_imploded . ")\(\d+\)/i";

// Execute type find & replace
$sql = preg_replace_callback($pattern, function ($matches) {
Expand Down
27 changes: 25 additions & 2 deletions tests/rewriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ public function test_it_handles_auto_increment_without_null()
$this->assertSame(trim($expected), trim($postgresql));
}

public function test_it_handles_numerics_without_auto_incrment_case_insensitively()
{
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS stars_votes (
voter_ip VARCHAR(150) NOT NULL,
post_id BIGINT(20) UNSIGNED NOT NULL,
rating INT(1) UNSIGNED NOT NULL,
PRIMARY KEY (voter_ip, post_id)
)
SQL;

$expected = <<<SQL
CREATE TABLE IF NOT EXISTS stars_votes (
voter_ip VARCHAR(150) NOT NULL,
post_id BIGINT NOT NULL,
rating INT NOT NULL,
PRIMARY KEY (voter_ip, post_id)
);
SQL;

$postgresql = pg4wp_rewrite($sql);
$this->assertSame(trim($expected), trim($postgresql));
}

public function test_it_handles_keys()
{
Expand Down Expand Up @@ -229,8 +252,8 @@ public function test_it_removes_character_sets()
platform varchar(255),
version varchar(255),
location varchar(10),
user_id BIGINT(48) NOT NULL,
page_id BIGINT(48) NOT NULL,
user_id BIGINT NOT NULL,
page_id BIGINT NOT NULL,
type VARCHAR(100) NOT NULL,
PRIMARY KEY ( "ID" )
);
Expand Down

0 comments on commit d46dba6

Please sign in to comment.