1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

Bitwarden Unified Self-Host project (#2410)

This commit is contained in:
Vince Grassia
2022-11-18 14:39:01 -05:00
committed by GitHub
parent 3481fd76c1
commit 194dfe7e14
57 changed files with 1929 additions and 323 deletions

View File

@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\util\MySqlMigrations\MySqlMigrations.csproj" />
<ProjectReference Include="..\..\util\PostgresMigrations\PostgresMigrations.csproj" />
<ProjectReference Include="..\SharedWeb\SharedWeb.csproj" />
<ProjectReference Include="..\..\util\Migrator\Migrator.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />

View File

@ -1,25 +1,19 @@
using System.Data.SqlClient;
using Bit.Core.Jobs;
using Bit.Core.Settings;
using Bit.Migrator;
using Bit.Core.Utilities;
namespace Bit.Admin.HostedServices;
public class DatabaseMigrationHostedService : IHostedService, IDisposable
{
private readonly GlobalSettings _globalSettings;
private readonly ILogger<DatabaseMigrationHostedService> _logger;
private readonly DbMigrator _dbMigrator;
private readonly IDbMigrator _dbMigrator;
public DatabaseMigrationHostedService(
GlobalSettings globalSettings,
ILogger<DatabaseMigrationHostedService> logger,
ILogger<DbMigrator> migratorLogger,
ILogger<JobListener> listenerLogger)
IDbMigrator dbMigrator,
ILogger<DatabaseMigrationHostedService> logger)
{
_globalSettings = globalSettings;
_logger = logger;
_dbMigrator = new DbMigrator(globalSettings.SqlServer.ConnectionString, migratorLogger);
_dbMigrator = dbMigrator;
}
public virtual async Task StartAsync(CancellationToken cancellationToken)
@ -32,7 +26,7 @@ public class DatabaseMigrationHostedService : IHostedService, IDisposable
{
try
{
_dbMigrator.MigrateMsSqlDatabase(true, cancellationToken);
_dbMigrator.MigrateDatabase(true, cancellationToken);
// TODO: Maybe flip a flag somewhere to indicate migration is complete??
break;
}

View File

@ -42,7 +42,21 @@ public class Startup
StripeConfiguration.MaxNetworkRetries = globalSettings.Stripe.MaxNetworkRetries;
// Repositories
services.AddSqlServerRepositories(globalSettings);
var databaseProvider = services.AddDatabaseRepositories(globalSettings);
switch (databaseProvider)
{
case Core.Enums.SupportedDatabaseProviders.SqlServer:
services.AddSingleton<IDbMigrator, Migrator.SqlServerDbMigrator>();
break;
case Core.Enums.SupportedDatabaseProviders.MySql:
services.AddSingleton<IDbMigrator, MySqlMigrations.MySqlDbMigrator>();
break;
case Core.Enums.SupportedDatabaseProviders.Postgres:
services.AddSingleton<IDbMigrator, PostgresMigrations.PostgresDbMigrator>();
break;
default:
break;
}
// Context
services.AddScoped<ICurrentContext, CurrentContext>();

View File

@ -3211,82 +3211,96 @@
"commercial.core": {
"type": "Project",
"dependencies": {
"Core": "2022.8.4"
"Core": "[2022.10.0, )"
}
},
"core": {
"type": "Project",
"dependencies": {
"AWSSDK.SQS": "3.7.2.47",
"AWSSDK.SimpleEmail": "3.7.0.150",
"AspNetCoreRateLimit": "4.0.2",
"AspNetCoreRateLimit.Redis": "1.0.1",
"Azure.Extensions.AspNetCore.DataProtection.Blobs": "1.2.1",
"Azure.Storage.Blobs": "12.11.0",
"Azure.Storage.Queues": "12.9.0",
"BitPay.Light": "1.0.1907",
"Braintree": "5.12.0",
"Fido2.AspNet": "3.0.0-beta2",
"Handlebars.Net": "2.1.2",
"IdentityServer4": "4.1.2",
"IdentityServer4.AccessTokenValidation": "3.0.1",
"MailKit": "3.2.0",
"Microsoft.AspNetCore.Authentication.JwtBearer": "6.0.4",
"Microsoft.Azure.Cosmos.Table": "1.0.8",
"Microsoft.Azure.NotificationHubs": "4.1.0",
"Microsoft.Azure.ServiceBus": "5.2.0",
"Microsoft.Data.SqlClient": "4.1.0",
"Microsoft.Extensions.Caching.StackExchangeRedis": "6.0.6",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "6.0.1",
"Microsoft.Extensions.Configuration.UserSecrets": "6.0.1",
"Microsoft.Extensions.Identity.Stores": "6.0.4",
"Newtonsoft.Json": "13.0.1",
"Otp.NET": "1.2.2",
"Quartz": "3.4.0",
"SendGrid": "9.27.0",
"Sentry.Serilog": "3.16.0",
"Serilog.AspNetCore": "5.0.0",
"Serilog.Extensions.Logging": "3.1.0",
"Serilog.Extensions.Logging.File": "2.0.0",
"Serilog.Sinks.AzureCosmosDB": "2.0.0",
"Serilog.Sinks.SyslogMessages": "2.0.6",
"Stripe.net": "40.0.0",
"YubicoDotNetClient": "1.2.0"
"AWSSDK.SQS": "[3.7.2.47, )",
"AWSSDK.SimpleEmail": "[3.7.0.150, )",
"AspNetCoreRateLimit": "[4.0.2, )",
"AspNetCoreRateLimit.Redis": "[1.0.1, )",
"Azure.Extensions.AspNetCore.DataProtection.Blobs": "[1.2.1, )",
"Azure.Storage.Blobs": "[12.11.0, )",
"Azure.Storage.Queues": "[12.9.0, )",
"BitPay.Light": "[1.0.1907, )",
"Braintree": "[5.12.0, )",
"Fido2.AspNet": "[3.0.0-beta2, )",
"Handlebars.Net": "[2.1.2, )",
"IdentityServer4": "[4.1.2, )",
"IdentityServer4.AccessTokenValidation": "[3.0.1, )",
"MailKit": "[3.2.0, )",
"Microsoft.AspNetCore.Authentication.JwtBearer": "[6.0.4, )",
"Microsoft.Azure.Cosmos.Table": "[1.0.8, )",
"Microsoft.Azure.NotificationHubs": "[4.1.0, )",
"Microsoft.Azure.ServiceBus": "[5.2.0, )",
"Microsoft.Data.SqlClient": "[4.1.0, )",
"Microsoft.Extensions.Caching.StackExchangeRedis": "[6.0.6, )",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "[6.0.1, )",
"Microsoft.Extensions.Configuration.UserSecrets": "[6.0.1, )",
"Microsoft.Extensions.Identity.Stores": "[6.0.4, )",
"Newtonsoft.Json": "[13.0.1, )",
"Otp.NET": "[1.2.2, )",
"Quartz": "[3.4.0, )",
"SendGrid": "[9.27.0, )",
"Sentry.Serilog": "[3.16.0, )",
"Serilog.AspNetCore": "[5.0.0, )",
"Serilog.Extensions.Logging": "[3.1.0, )",
"Serilog.Extensions.Logging.File": "[2.0.0, )",
"Serilog.Sinks.AzureCosmosDB": "[2.0.0, )",
"Serilog.Sinks.SyslogMessages": "[2.0.6, )",
"Stripe.net": "[40.0.0, )",
"YubicoDotNetClient": "[1.2.0, )"
}
},
"infrastructure.dapper": {
"type": "Project",
"dependencies": {
"Core": "2022.8.4",
"Dapper": "2.0.123",
"System.Data.SqlClient": "4.8.3"
"Core": "[2022.10.0, )",
"Dapper": "[2.0.123, )",
"System.Data.SqlClient": "[4.8.3, )"
}
},
"infrastructure.entityframework": {
"type": "Project",
"dependencies": {
"AutoMapper.Extensions.Microsoft.DependencyInjection": "11.0.0",
"Core": "2022.8.4",
"Microsoft.EntityFrameworkCore.Relational": "6.0.4",
"Npgsql.EntityFrameworkCore.PostgreSQL": "6.0.4",
"Pomelo.EntityFrameworkCore.MySql": "6.0.1",
"linq2db.EntityFrameworkCore": "6.7.1"
"AutoMapper.Extensions.Microsoft.DependencyInjection": "[11.0.0, )",
"Core": "[2022.10.0, )",
"Microsoft.EntityFrameworkCore.Relational": "[6.0.4, )",
"Npgsql.EntityFrameworkCore.PostgreSQL": "[6.0.4, )",
"Pomelo.EntityFrameworkCore.MySql": "[6.0.1, )",
"linq2db.EntityFrameworkCore": "[6.7.1, )"
}
},
"migrator": {
"type": "Project",
"dependencies": {
"Core": "2022.8.4",
"Microsoft.Extensions.Logging": "6.0.0",
"dbup-sqlserver": "4.5.0"
"Core": "[2022.10.0, )",
"Microsoft.Extensions.Logging": "[6.0.0, )",
"dbup-sqlserver": "[4.5.0, )"
}
},
"mysqlmigrations": {
"type": "Project",
"dependencies": {
"Core": "[2022.10.0, )",
"Infrastructure.EntityFramework": "[2022.10.0, )"
}
},
"postgresmigrations": {
"type": "Project",
"dependencies": {
"Core": "[2022.10.0, )",
"Infrastructure.EntityFramework": "[2022.10.0, )"
}
},
"sharedweb": {
"type": "Project",
"dependencies": {
"Core": "2022.8.4",
"Infrastructure.Dapper": "2022.8.4",
"Infrastructure.EntityFramework": "2022.8.4"
"Core": "[2022.10.0, )",
"Infrastructure.Dapper": "[2022.10.0, )",
"Infrastructure.EntityFramework": "[2022.10.0, )"
}
}
}