From dee9c8b98adb21658c30ed5476b77d040a948bc7 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Thu, 11 Jan 2024 23:09:37 -0800 Subject: [PATCH] Fix: Properly detect a postgres connection Previously was looking for a ".db" in the connection string, which is the typical sqlite filename. The problem is if your connection string has a .db anywhere in it, such as postgres.db.internal it'll think its a sqlite file Solution borrowed from sonarr: https://github.com/Sonarr/Sonarr/blob/develop/src/NzbDrone.Core/Datastore/Database.cs#L43 --- src/NzbDrone.Core/Datastore/Database.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Core/Datastore/Database.cs b/src/NzbDrone.Core/Datastore/Database.cs index e36241ef0..b743fba13 100644 --- a/src/NzbDrone.Core/Datastore/Database.cs +++ b/src/NzbDrone.Core/Datastore/Database.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Data; +using System.Data.SQLite; using System.Text.RegularExpressions; using Dapper; using NLog; @@ -40,14 +41,7 @@ namespace NzbDrone.Core.Datastore { using (var db = _datamapperFactory()) { - if (db.ConnectionString.Contains(".db")) - { - return DatabaseType.SQLite; - } - else - { - return DatabaseType.PostgreSQL; - } + return db is SQLiteConnection ? DatabaseType.SQLite : DatabaseType.PostgreSQL; } } }