From de9cdd44511f3c0c5a5ef5ce01f52b7efe35b4e0 Mon Sep 17 00:00:00 2001 From: David Benson Date: Tue, 12 Dec 2023 15:58:10 -0500 Subject: [PATCH] Switching the migrations to use case-insensitive labels. --- .../Postgres/PostgresModuleInitializer.cs | 17 ----------------- src/Ombi/Extensions/DatabaseExtensions.cs | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 src/Ombi.Store/Context/Postgres/PostgresModuleInitializer.cs diff --git a/src/Ombi.Store/Context/Postgres/PostgresModuleInitializer.cs b/src/Ombi.Store/Context/Postgres/PostgresModuleInitializer.cs deleted file mode 100644 index 8fdab7cf3..000000000 --- a/src/Ombi.Store/Context/Postgres/PostgresModuleInitializer.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace Ombi.Store.Context.Postgres; - -public static class PostgresModuleInitializer -{ -#pragma warning disable CA2255 - // This is required to ensure that Npgsql uses a timestamp behavior that does not require a timezone - // Reference: https://stackoverflow.com/a/73586129 - [ModuleInitializer] -#pragma warning restore CA2255 - public static void Initialize() - { - AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - } -} \ No newline at end of file diff --git a/src/Ombi/Extensions/DatabaseExtensions.cs b/src/Ombi/Extensions/DatabaseExtensions.cs index 56d046648..336bb2823 100644 --- a/src/Ombi/Extensions/DatabaseExtensions.cs +++ b/src/Ombi/Extensions/DatabaseExtensions.cs @@ -1,9 +1,12 @@ using System; using System.IO; +using System.Text; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Newtonsoft.Json; +using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal; using Ombi.Helpers; using Ombi.Store.Context; using Ombi.Store.Context.MySql; @@ -159,7 +162,7 @@ public static void ConfigurePostgres(DbContextOptionsBuilder options, PerDatabas options.UseNpgsql(config.ConnectionString, b => { b.EnableRetryOnFailure(); - }); + }).ReplaceService(); } public class DatabaseConfiguration @@ -196,5 +199,16 @@ public PerDatabaseConfiguration() public string Type { get; set; } public string ConnectionString { get; set; } } + + public class NpgsqlCaseInsensitiveSqlGenerationHelper : NpgsqlSqlGenerationHelper + { + const string EFMigrationsHisory = "__EFMigrationsHistory"; + public NpgsqlCaseInsensitiveSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) + : base(dependencies) { } + public override string DelimitIdentifier(string identifier) => + base.DelimitIdentifier(identifier == EFMigrationsHisory ? identifier : identifier.ToLower()); + public override void DelimitIdentifier(StringBuilder builder, string identifier) + => base.DelimitIdentifier(builder, identifier == EFMigrationsHisory ? identifier : identifier.ToLower()); + } } } \ No newline at end of file