From b7cffbddd07447ff4b3d79c8f0907e513d8e5b8f Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 27 Jun 2022 19:05:57 +0200 Subject: [PATCH 1/3] CREATE INDEX IF NOT EXISTS is not supported as of MySQL <= 8.0, fixes #943 --- lib/Data/Database.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Data/Database.php b/lib/Data/Database.php index f9a8ae8..a5b5136 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -837,8 +837,9 @@ class Database extends AbstractData end;' ); } else { + // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 self::$_db->exec( - 'CREATE INDEX IF NOT EXISTS "comment_parent" ON "' . + 'CREATE INDEX "comment_parent" ON "' . self::_sanitizeIdentifier('comment') . '" ("pasteid")' ); } @@ -949,8 +950,9 @@ class Database extends AbstractData self::_sanitizeIdentifier('comment') . '" ("dataid")' ); } + // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 self::$_db->exec( - 'CREATE INDEX IF NOT EXISTS "comment_parent" ON "' . + 'CREATE INDEX "comment_parent" ON "' . self::_sanitizeIdentifier('comment') . '" ("pasteid")' ); // no break, continue with updates for 0.22 and later From 4ad4aed875e0af79b3bbe4b1ae8060567c101c8a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 28 Jun 2022 06:51:21 +0200 Subject: [PATCH 2/3] apply table prefix to indexes as well, to support multiple instances sharing a single database --- CHANGELOG.md | 2 ++ lib/Data/Database.php | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c036ad..1343024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * **1.4.1 (not yet released)** * ADDED: Translations for Turkish * CHANGED: Avoid `SUPER` privilege for setting the `sql_mode` for MariaDB/MySQL (#919) + * FIXED: Revert to CREATE INDEX without IF NOT EXISTS clauses, to support MySQL (#943) + * FIXED: Apply table prefix to indexes as well, to support multiple instances sharing a single database (#943) * **1.4 (2022-04-09)** * ADDED: Translations for Corsican, Estonian, Finnish and Lojban * ADDED: new HTTP headers improving security (#765) diff --git a/lib/Data/Database.php b/lib/Data/Database.php index a5b5136..b42c76b 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -839,7 +839,8 @@ class Database extends AbstractData } else { // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 self::$_db->exec( - 'CREATE INDEX "comment_parent" ON "' . + 'CREATE INDEX "' . + self::_sanitizeIdentifier('comment_parent') . '" ON "' . self::_sanitizeIdentifier('comment') . '" ("pasteid")' ); } @@ -942,17 +943,20 @@ class Database extends AbstractData ); } else { self::$_db->exec( - 'CREATE UNIQUE INDEX IF NOT EXISTS "paste_dataid" ON "' . + 'CREATE UNIQUE INDEX IF NOT EXISTS "' . + self::_sanitizeIdentifier('paste_dataid') . '" ON "' . self::_sanitizeIdentifier('paste') . '" ("dataid")' ); self::$_db->exec( - 'CREATE UNIQUE INDEX IF NOT EXISTS "comment_dataid" ON "' . + 'CREATE UNIQUE INDEX IF NOT EXISTS "' . + self::_sanitizeIdentifier('comment_dataid') . '" ON "' . self::_sanitizeIdentifier('comment') . '" ("dataid")' ); } // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 self::$_db->exec( - 'CREATE INDEX "comment_parent" ON "' . + 'CREATE INDEX "' . + self::_sanitizeIdentifier('comment_parent') . '" ON "' . self::_sanitizeIdentifier('comment') . '" ("pasteid")' ); // no break, continue with updates for 0.22 and later From e6d606ba8812b9780f8030238bd17901a7b6f81a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 29 Jun 2022 22:25:54 +0200 Subject: [PATCH 3/3] clarify that it is only unsupported by Oracle MySQL, while supported in MariaDB, Postgres, SQLite, ... --- lib/Data/Database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Data/Database.php b/lib/Data/Database.php index b42c76b..c34ee13 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -837,7 +837,7 @@ class Database extends AbstractData end;' ); } else { - // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 + // CREATE INDEX IF NOT EXISTS not supported as of Oracle MySQL <= 8.0 self::$_db->exec( 'CREATE INDEX "' . self::_sanitizeIdentifier('comment_parent') . '" ON "' . @@ -953,7 +953,7 @@ class Database extends AbstractData self::_sanitizeIdentifier('comment') . '" ("dataid")' ); } - // CREATE INDEX IF NOT EXISTS not supported as of MySQL <= 8.0 + // CREATE INDEX IF NOT EXISTS not supported as of Oracle MySQL <= 8.0 self::$_db->exec( 'CREATE INDEX "' . self::_sanitizeIdentifier('comment_parent') . '" ON "' .