From d46dba61489504e5b4226cde891c8c7822dde5f1 Mon Sep 17 00:00:00 2001 From: Matthew Bucci Date: Thu, 17 Oct 2024 01:18:11 -0700 Subject: [PATCH 1/2] numeric rewriting should be case insensitive --- pg4wp/rewriters/CreateTableSQLRewriter.php | 2 +- tests/rewriteTest.php | 27 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pg4wp/rewriters/CreateTableSQLRewriter.php b/pg4wp/rewriters/CreateTableSQLRewriter.php index 0e26ba4..66deb10 100644 --- a/pg4wp/rewriters/CreateTableSQLRewriter.php +++ b/pg4wp/rewriters/CreateTableSQLRewriter.php @@ -96,7 +96,7 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter $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) { diff --git a/tests/rewriteTest.php b/tests/rewriteTest.php index 2bbeeaf..4e81d5e 100644 --- a/tests/rewriteTest.php +++ b/tests/rewriteTest.php @@ -96,6 +96,29 @@ final class rewriteTest extends TestCase $this->assertSame(trim($expected), trim($postgresql)); } + public function test_it_handles_numerics_without_auto_incrment_case_insensitively() + { + $sql = <<assertSame(trim($expected), trim($postgresql)); + } public function test_it_handles_keys() { @@ -229,8 +252,8 @@ final class rewriteTest extends TestCase 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" ) ); From b463ead79fe2b3431c38a80faafee5a4109941b8 Mon Sep 17 00:00:00 2001 From: Matthew Bucci Date: Thu, 17 Oct 2024 01:25:16 -0700 Subject: [PATCH 2/2] convert mediumints to ints --- pg4wp/rewriters/CreateTableSQLRewriter.php | 4 +- tests/rewriteTest.php | 57 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/pg4wp/rewriters/CreateTableSQLRewriter.php b/pg4wp/rewriters/CreateTableSQLRewriter.php index 66deb10..3a1dcb8 100644 --- a/pg4wp/rewriters/CreateTableSQLRewriter.php +++ b/pg4wp/rewriters/CreateTableSQLRewriter.php @@ -21,8 +21,8 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter ' CHARACTER SET utf8' => '', ' DEFAULT CHARSET=utf8' => '', - // For flash-album-gallery plugin - ' tinyint' => ' smallint' + ' tinyint' => ' smallint', + ' mediumint' => ' integer' ]; public function rewrite(): string diff --git a/tests/rewriteTest.php b/tests/rewriteTest.php index 4e81d5e..e755540 100644 --- a/tests/rewriteTest.php +++ b/tests/rewriteTest.php @@ -654,6 +654,63 @@ final class rewriteTest extends TestCase $this->assertSame(trim($expected), trim($postgresql)); } + public function test_it_rewrites_mediumints() + { + $sql = <<assertSame(trim($expected), trim($postgresql)); + } + +