From b154bc7a10e46dc9fa0406996507c4fd410366da Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 12:59:00 +0300 Subject: initial attempt to remove mysql-related stuff from tt-rss --- classes/Config.php | 49 +------------------------------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) (limited to 'classes/Config.php') diff --git a/classes/Config.php b/classes/Config.php index 5098bfe68..f8f9aaa18 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -24,7 +24,7 @@ class Config { * */ - /** database type: pgsql or mysql */ + /** database type: pgsql */ const DB_TYPE = "DB_TYPE"; /** database server hostname */ @@ -42,10 +42,6 @@ class Config { /** database server port */ const DB_PORT = "DB_PORT"; - /** connection charset for MySQL. if you have a legacy database and/or experience - * garbage unicode characters with this option, try setting it to a blank string. */ - const MYSQL_CHARSET = "MYSQL_CHARSET"; - /** this is a fallback falue for the CLI SAPI, it should be set to a fully-qualified tt-rss URL */ const SELF_URL_PATH = "SELF_URL_PATH"; @@ -204,7 +200,6 @@ class Config { Config::DB_NAME => [ "", Config::T_STRING ], Config::DB_PASS => [ "", Config::T_STRING ], Config::DB_PORT => [ "5432", Config::T_STRING ], - Config::MYSQL_CHARSET => [ "UTF8", Config::T_STRING ], Config::SELF_URL_PATH => [ "https://example.com/tt-rss", Config::T_STRING ], Config::SINGLE_USER_MODE => [ "", Config::T_BOOL ], Config::SIMPLE_UPDATE_MODE => [ "", Config::T_BOOL ], @@ -481,25 +476,6 @@ class Config { } /* sanity check stuff */ - /** checks for mysql tables not using InnoDB (tt-rss is incompatible with MyISAM) - * @return array> A list of entries identifying tt-rss tables with bad config - */ - private static function check_mysql_tables() { - $pdo = Db::pdo(); - - $sth = $pdo->prepare("SELECT engine, table_name FROM information_schema.tables WHERE - table_schema = ? AND table_name LIKE 'ttrss_%' AND engine != 'InnoDB'"); - $sth->execute([self::get(Config::DB_NAME)]); - - $bad_tables = []; - - while ($line = $sth->fetch()) { - array_push($bad_tables, $line); - } - - return $bad_tables; - } - static function sanity_check(): void { /* @@ -604,29 +580,6 @@ class Config { } } - if (self::get(Config::DB_TYPE) == "mysql") { - $bad_tables = self::check_mysql_tables(); - - if (count($bad_tables) > 0) { - $bad_tables_fmt = []; - - foreach ($bad_tables as $bt) { - array_push($bad_tables_fmt, sprintf("%s (%s)", $bt['table_name'], $bt['engine'])); - } - - $msg = "

The following tables use an unsupported MySQL engine: " . - implode(", ", $bad_tables_fmt) . ".

"; - - $msg .= "

The only supported engine on MySQL is InnoDB. MyISAM lacks functionality to run - tt-rss. - Please backup your data (via OPML) and re-import the schema before continuing.

-

WARNING: importing the schema would mean LOSS OF ALL YOUR DATA.

"; - - - array_push($errors, $msg); - } - } - if (count($errors) > 0 && php_sapi_name() != "cli") { http_response_code(503); ?> -- cgit v1.2.3-54-g00ecf From 7e403aae92166de6e83a5ab39738ea8ffe6eb713 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 15:21:10 +0300 Subject: further mysql/DB_TYPE related cleanup --- .docker/app/Dockerfile | 1 - classes/Config.php | 7 +++- classes/Db.php | 2 +- classes/Db_Migrations.php | 2 +- plugins/af_psql_trgm/init.php | 91 +++++++++++++------------------------------ 5 files changed, 34 insertions(+), 69 deletions(-) (limited to 'classes/Config.php') diff --git a/.docker/app/Dockerfile b/.docker/app/Dockerfile index 9ca767608..786179bd5 100644 --- a/.docker/app/Dockerfile +++ b/.docker/app/Dockerfile @@ -91,7 +91,6 @@ ENV TTRSS_XDEBUG_ENABLED="" ENV TTRSS_XDEBUG_HOST="" ENV TTRSS_XDEBUG_PORT="9000" -ENV TTRSS_DB_TYPE="pgsql" ENV TTRSS_DB_HOST="db" ENV TTRSS_DB_PORT="5432" diff --git a/classes/Config.php b/classes/Config.php index f8f9aaa18..1921796db 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -18,13 +18,16 @@ class Config { * * or config.php: * - * putenv('TTRSS_DB_TYPE=pgsql'); + * putenv('TTRSS_DB_HOST=my-patroni.example.com'); * * note lack of quotes and spaces before and after "=". * */ - /** database type: pgsql */ + /** this is kept for backwards/plugin compatibility, the only supported database is PostgreSQL + * + * @deprecated could be replaced with default (and only) value: `pgsql` + */ const DB_TYPE = "DB_TYPE"; /** database server hostname */ diff --git a/classes/Db.php b/classes/Db.php index 92bbec8b4..6310d11e3 100644 --- a/classes/Db.php +++ b/classes/Db.php @@ -27,7 +27,7 @@ class Db { $db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : ''; $db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : ''; - return Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port; + return 'pgsql:dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port; } // this really shouldn't be used unless a separate PDO connection is needed diff --git a/classes/Db_Migrations.php b/classes/Db_Migrations.php index 62619b377..33bc64a32 100644 --- a/classes/Db_Migrations.php +++ b/classes/Db_Migrations.php @@ -23,7 +23,7 @@ class Db_Migrations { } function initialize(string $root_path, string $migrations_table, bool $base_is_latest = true, int $max_version_override = 0): void { - $this->base_path = "$root_path/" . Config::get(Config::DB_TYPE); + $this->base_path = "$root_path/pgsql"; $this->migrations_path = $this->base_path . "/migrations"; $this->migrations_table = $migrations_table; $this->base_is_latest = $base_is_latest; diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 28a0ab933..5832320e8 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -63,41 +63,22 @@ class Af_Psql_Trgm extends Plugin { print "

$title

"; - if (Config::get(Config::DB_TYPE) == "pgsql") { - $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, - feed_id, - ttrss_entries.title AS title, - updated, link, - ttrss_feeds.title AS feed_title, - SIMILARITY(ttrss_entries.title, :title) AS sm - FROM - ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) - WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = :owner_uid AND - ttrss_entries.id != :id AND - date_entered >= NOW() - INTERVAL '2 weeks' - ORDER BY - sm DESC, date_entered DESC - LIMIT 10"); - } else { - $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, - feed_id, - ttrss_entries.title AS title, - updated, link, - ttrss_feeds.title AS feed_title, - (MATCH (ttrss_entries.title) AGAINST (:title) / LENGTH(ttrss_entries.title)) AS sm - FROM - ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) - WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = :owner_uid AND - ttrss_entries.id != :id AND - date_entered >= DATE_SUB(NOW(), INTERVAL 2 WEEK) - ORDER BY - sm DESC, date_entered DESC - LIMIT 10"); - } + $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, + feed_id, + ttrss_entries.title AS title, + updated, link, + ttrss_feeds.title AS feed_title, + SIMILARITY(ttrss_entries.title, :title) AS sm + FROM + ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) + WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.owner_uid = :owner_uid AND + ttrss_entries.id != :id AND + date_entered >= NOW() - INTERVAL '2 weeks' + ORDER BY + sm DESC, date_entered DESC + LIMIT 10"); $sth->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]); @@ -157,12 +138,10 @@ class Af_Psql_Trgm extends Plugin { title="extension "> pdo->query("select 'similarity'::regproc"); + $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res || !$res->fetch()) { - print_error("pg_trgm extension not found."); - } + if (!$res || !$res->fetch()) { + print_error("pg_trgm extension not found."); } ?>
@@ -190,11 +169,7 @@ class Af_Psql_Trgm extends Plugin { name="similarity" value="">
- - - - - +
@@ -283,10 +258,8 @@ class Af_Psql_Trgm extends Plugin { function hook_article_filter($article) { - if (Config::get(Config::DB_TYPE) == "pgsql") { - $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res || !$res->fetch()) return $article; - } + $res = $this->pdo->query("select 'similarity'::regproc"); + if (!$res || !$res->fetch()) return $article; $enable_globally = $this->host->get($this, "enable_globally"); @@ -336,21 +309,11 @@ class Af_Psql_Trgm extends Plugin { return $article; } */ - if (Config::get(Config::DB_TYPE) == "pgsql") { - $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms - FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND - date_entered >= NOW() - interval '1 day' AND - guid != :guid AND - owner_uid = :uid"); - } else { - $sth = $this->pdo->prepare("SELECT (MATCH(title) AGAINST (:title) / LENGTH(title)) AS ms - FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND - date_entered >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND - guid != :guid AND - owner_uid = :uid - ORDER BY ms DESC - LIMIT 1"); - } + $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms + FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND + date_entered >= NOW() - interval '1 day' AND + guid != :guid AND + owner_uid = :uid"); $sth->execute(['title' => $title_escaped, 'guid' => $entry_guid, 'uid' => $owner_uid]); -- cgit v1.2.3-54-g00ecf From 54e8ab7e3d4fa99e9acfc069c963fe41cfb0cd32 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 15:24:34 +0300 Subject: update DB_TYPE deprecation notice --- classes/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes/Config.php') diff --git a/classes/Config.php b/classes/Config.php index 1921796db..798cc7001 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -26,7 +26,7 @@ class Config { /** this is kept for backwards/plugin compatibility, the only supported database is PostgreSQL * - * @deprecated could be replaced with default (and only) value: `pgsql` + * @deprecated usages of `Config::get(Config::DB_TYPE)` should be replaced with default (and only) value: `pgsql` or removed */ const DB_TYPE = "DB_TYPE"; -- cgit v1.2.3-54-g00ecf