Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add end to list of reserved columns #138

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pg4wp/rewriters/CreateTableSQLRewriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function rewrite_columns_with_protected_names($sql)
$columnsAndKeys = $matches[3];
$suffix = ')' . $matches[4];

$regex = '/(?:^|\s*,\s*)(\b(?:timestamp|date|time|default)\b)\s*(?=\s+\w+)/i';
$regex = '/(?:^|\s*,\s*)(\b(?:timestamp|date|time|default|end)\b)\s*(?=\s+\w+)/i';

// Callback function to add quotes around protected column names
$callback = function($matches) {
Expand Down
61 changes: 61 additions & 0 deletions tests/rewriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,67 @@ public function test_it_rewrites_utc_timestamp_selects()
$this->assertSame(trim($expected), trim($postgresql));
}

public function test_it_quotes_reserved_columns()
{
$sql = <<<SQL
CREATE TABLE wp_aioseo_notifications (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
slug varchar(13) NOT NULL,
title text NOT NULL,
content longtext NOT NULL,
type varchar(64) NOT NULL,
level text NOT NULL,
notification_id bigint(20) unsigned DEFAULT NULL,
notification_name varchar(255) DEFAULT NULL,
start datetime DEFAULT NULL,
end datetime DEFAULT NULL,
button1_label varchar(255) DEFAULT NULL,
button1_action varchar(255) DEFAULT NULL,
button2_label varchar(255) DEFAULT NULL,
button2_action varchar(255) DEFAULT NULL,
dismissed tinyint(1) NOT NULL DEFAULT 0,
created datetime NOT NULL,
updated datetime NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY ndx_aioseo_notifications_slug (slug),
KEY ndx_aioseo_notifications_dates (start, end),
KEY ndx_aioseo_notifications_type (type),
KEY ndx_aioseo_notifications_dismissed (dismissed)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
SQL;

$expected = <<<SQL
CREATE TABLE IF NOT EXISTS wp_aioseo_notifications (
id bigserial,
slug varchar(13) NOT NULL,
title text NOT NULL,
content text NOT NULL,
type varchar(64) NOT NULL,
level text NOT NULL,
notification_id bigint DEFAULT NULL,
notification_name varchar(255) DEFAULT NULL,
start timestamp DEFAULT NULL,
"end" timestamp DEFAULT NULL,
button1_label varchar(255) DEFAULT NULL,
button1_action varchar(255) DEFAULT NULL,
button2_label varchar(255) DEFAULT NULL,
button2_action varchar(255) DEFAULT NULL,
dismissed smallint NOT NULL DEFAULT 0,
created timestamp NOT NULL,
updated timestamp NOT NULL,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX IF NOT EXISTS wp_aioseo_notifications_ndx_aioseo_notifications_slug ON wp_aioseo_notifications (slug);
CREATE INDEX IF NOT EXISTS wp_aioseo_notifications_ndx_aioseo_notifications_dates ON wp_aioseo_notifications (start, end);
CREATE INDEX IF NOT EXISTS wp_aioseo_notifications_ndx_aioseo_notifications_type ON wp_aioseo_notifications (type);
CREATE INDEX IF NOT EXISTS wp_aioseo_notifications_ndx_aioseo_notifications_dismissed ON wp_aioseo_notifications (dismissed);
SQL;

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


protected function setUp(): void
{
global $wpdb;
Expand Down
Loading