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

feat(wizard): ✨ Added the ability to start with a different database #5208

Merged
merged 6 commits into from
Jan 3, 2025
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 src/.idea/.idea.Ombi/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 77 additions & 59 deletions src/.idea/.idea.Ombi/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;
using Ombi.Core.Models;
using Polly;
using Pomelo.EntityFrameworkCore.MySql.Storage.Internal;

namespace Ombi.Core.Helpers;

public static class DatabaseConfigurationSetup
{
public static void ConfigurePostgres(DbContextOptionsBuilder options, PerDatabaseConfiguration config)
{
options.UseNpgsql(config.ConnectionString, b =>
{
b.EnableRetryOnFailure();
}).ReplaceService<ISqlGenerationHelper, NpgsqlCaseInsensitiveSqlGenerationHelper>();
}

public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config)
{
if (string.IsNullOrEmpty(config.ConnectionString))
{
throw new ArgumentNullException("ConnectionString for the MySql/Mariadb database is empty");
}

options.UseMySql(config.ConnectionString, GetServerVersion(config.ConnectionString), b =>
{
//b.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend); // ##ISSUE, link to migrations?
b.EnableRetryOnFailure();
});
}

private static ServerVersion GetServerVersion(string connectionString)
{
// Workaround Windows bug, that can lead to the following exception:
//
// MySqlConnector.MySqlException (0x80004005): SSL Authentication Error
// ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
// ---> System.ComponentModel.Win32Exception (0x8009030F): The message or signature supplied for verification has been altered
//
// See https://github.com/dotnet/runtime/issues/17005#issuecomment-305848835
//
// Also workaround for the fact, that ServerVersion.AutoDetect() does not use any retrying strategy.
ServerVersion serverVersion = null;
#pragma warning disable EF1001
var retryPolicy = Policy.Handle<Exception>(exception => MySqlTransientExceptionDetector.ShouldRetryOn(exception))
#pragma warning restore EF1001
.WaitAndRetry(3, (count, context) => TimeSpan.FromMilliseconds(count * 250));

serverVersion = retryPolicy.Execute(() => serverVersion = ServerVersion.AutoDetect(connectionString));

return serverVersion;
}
public class NpgsqlCaseInsensitiveSqlGenerationHelper : NpgsqlSqlGenerationHelper

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / unit-test

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x86, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-x64, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x64, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (osx-x64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.
{
const string EFMigrationsHisory = "__EFMigrationsHistory";
public NpgsqlCaseInsensitiveSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies)
: base(dependencies) { }

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / unit-test

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x86, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-x64, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x64, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (osx-x64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.
public override string DelimitIdentifier(string identifier) =>
base.DelimitIdentifier(identifier == EFMigrationsHisory ? identifier : identifier.ToLower());

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / unit-test

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x86, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-x64, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x64, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (osx-x64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.
public override void DelimitIdentifier(StringBuilder builder, string identifier)
=> base.DelimitIdentifier(builder, identifier == EFMigrationsHisory ? identifier : identifier.ToLower());

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / unit-test

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x86, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-x64, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm, tar.gz, tar)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (win-x64, zip, zip)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (osx-x64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.

Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs

View workflow job for this annotation

GitHub Actions / publish (linux-arm64, tar, tar.gz)

Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlSqlGenerationHelper is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release.
}
}
10 changes: 10 additions & 0 deletions src/Ombi.Core/Helpers/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ombi.Core.Helpers;

public class FileSystem : IFileSystem
{
public bool FileExists(string path)
{
return System.IO.File.Exists(path);
}
// Implement other file system operations as needed
}
7 changes: 7 additions & 0 deletions src/Ombi.Core/Helpers/IFileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Ombi.Core.Helpers;

public interface IFileSystem
{
bool FileExists(string path);
// Add other file system operations as needed
}
Loading
Loading