mirror of
https://github.com/bitwarden/server.git
synced 2024-12-30 18:17:36 +01:00
7cbc4a8970
* Add Sqlite as EF DB provider Note: In-memory sqlite does not work across projects, since the migrator only runs on the Admin project Co-authored-by: Justin Baur <justindbaur@users.noreply.github.com> * Include example sqlite connection string * Add migrator assembly to sqlite connection * Update initial migration to current schema state * dotnet format 🤖 * Update package locks * Respect name set in BW_SSL_KEY for cert generation (#2490) (cherry picked from commit2469e10110
) * [PS-2016] Add ability to change UID/GID for Bitwarden unified (#2495) (cherry picked from commitc6fbe8cc44
) * Add SqliteMigrations project to unified Dockerfile Co-authored-by: Justin Baur <justindbaur@users.noreply.github.com> Co-authored-by: accolon <mail@accolon.net> Co-authored-by: Vince Grassia <593223+vgrassia@users.noreply.github.com>
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Bit.Core.Settings;
|
|
using Bit.Infrastructure.EntityFramework.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Bit.SqliteMigrations;
|
|
|
|
public static class GlobalSettingsFactory
|
|
{
|
|
public static GlobalSettings GlobalSettings { get; } = new GlobalSettings();
|
|
static GlobalSettingsFactory()
|
|
{
|
|
var configBuilder = new ConfigurationBuilder().AddUserSecrets("bitwarden-Api");
|
|
var Configuration = configBuilder.Build();
|
|
ConfigurationBinder.Bind(Configuration.GetSection("GlobalSettings"), GlobalSettings);
|
|
}
|
|
}
|
|
|
|
public class DatabaseContextFactory : IDesignTimeDbContextFactory<DatabaseContext>
|
|
{
|
|
public DatabaseContext CreateDbContext(string[] args)
|
|
{
|
|
var globalSettings = GlobalSettingsFactory.GlobalSettings;
|
|
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
|
|
var connectionString = globalSettings.Sqlite?.ConnectionString ?? "Data Source=:memory:";
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
{
|
|
throw new Exception("No Sqlite connection string found.");
|
|
}
|
|
optionsBuilder.UseSqlite(
|
|
connectionString,
|
|
b => b.MigrationsAssembly("SqliteMigrations"));
|
|
return new DatabaseContext(optionsBuilder.Options);
|
|
}
|
|
}
|