1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Migration Fix (#1448)

* created stubs for missing ef provider methods

* fixed the initial postgres migration
This commit is contained in:
Addison Beck
2021-07-08 15:46:13 -04:00
committed by GitHub
parent b13dda2799
commit 4a828ad440
8 changed files with 318 additions and 344 deletions

View File

@ -26,42 +26,14 @@ namespace MySqlMigrations
{
var globalSettings = GlobalSettingsFactory.GlobalSettings;
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
var selectedDatabaseProvider = globalSettings.DatabaseProvider;
var provider = SupportedDatabaseProviders.Postgres;
var connectionString = string.Empty;
if (!string.IsNullOrWhiteSpace(selectedDatabaseProvider))
var connectionString = globalSettings.PostgreSql?.ConnectionString;
if (string.IsNullOrWhiteSpace(connectionString))
{
switch (selectedDatabaseProvider.ToLowerInvariant())
{
case "postgres":
case "postgresql":
provider = SupportedDatabaseProviders.Postgres;
connectionString = globalSettings.PostgreSql.ConnectionString;
break;
case "mysql":
case "mariadb":
provider = SupportedDatabaseProviders.MySql;
connectionString = globalSettings.MySql.ConnectionString;
break;
default:
throw new Exception("No database provider selected");
break;
}
}
if (provider.Equals(SupportedDatabaseProviders.Postgres))
{
optionsBuilder.UseNpgsql(
connectionString,
b => b.MigrationsAssembly("PostgresMigrations"));
}
else if (provider.Equals(SupportedDatabaseProviders.MySql))
{
optionsBuilder.UseMySql(
connectionString,
ServerVersion.AutoDetect(connectionString),
b => b.MigrationsAssembly("MySqlMigrations"));
throw new Exception("No Postgres connection string found.");
}
optionsBuilder.UseNpgsql(
connectionString,
b => b.MigrationsAssembly("PostgresMigrations"));
return new DatabaseContext(optionsBuilder.Options);
}
}