mirror of
https://github.com/bitwarden/server
synced 2026-01-08 19:43:34 +00:00
[SM-394] Secrets Manager (#2164)
Long lived feature branch for Secrets Manager Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Co-authored-by: cd-bitwarden <106776772+cd-bitwarden@users.noreply.github.com> Co-authored-by: CarleyDiaz-Bitwarden <103955722+CarleyDiaz-Bitwarden@users.noreply.github.com> Co-authored-by: Thomas Avery <tavery@bitwarden.com> Co-authored-by: Colton Hurst <colton@coltonhurst.com>
This commit is contained in:
36
util/SqlServerEFScaffold/Factories.cs
Normal file
36
util/SqlServerEFScaffold/Factories.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SqlServerEFScaffold;
|
||||
|
||||
public static class GlobalSettingsFactory
|
||||
{
|
||||
public static GlobalSettings GlobalSettings { get; } = new GlobalSettings();
|
||||
static GlobalSettingsFactory()
|
||||
{
|
||||
var configBuilder = new ConfigurationBuilder().AddUserSecrets<Bit.Api.Startup>();
|
||||
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.SqlServer?.ConnectionString;
|
||||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
{
|
||||
throw new Exception("No SqlServer connection string found.");
|
||||
}
|
||||
optionsBuilder.UseSqlServer(
|
||||
connectionString,
|
||||
b => b.MigrationsAssembly("SqlServerEFScaffold"));
|
||||
return new DatabaseContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
1729
util/SqlServerEFScaffold/Migrations/DatabaseContextModelSnapshot.cs
Normal file
1729
util/SqlServerEFScaffold/Migrations/DatabaseContextModelSnapshot.cs
Normal file
File diff suppressed because it is too large
Load Diff
27
util/SqlServerEFScaffold/README.MD
Normal file
27
util/SqlServerEFScaffold/README.MD
Normal file
@@ -0,0 +1,27 @@
|
||||
## Usage
|
||||
|
||||
The SqlServerEFScaffold project is intended to be used as a tool for developers to validate their Microsoft SQL Server database changes and Infrastructure.EntityFramework.Models stay in sync for entity framework MS SQL Server repositories.
|
||||
|
||||
## Check Infrastructure.EntityFramework.Models (Database First)
|
||||
|
||||
Run the following:
|
||||
|
||||
```dotnet ef dbcontext scaffold "<local db connection string>" Microsoft.EntityFrameworkCore.SqlServer -o Model```
|
||||
|
||||
The dotnet entity framework command will generate models from the local database provided.
|
||||
|
||||
Engineers can reference these models and validate they match with Infrastructure.EntityFramework.Models.
|
||||
|
||||
|
||||
## Check Microsoft SQL Server Database changes (Code/Model First)
|
||||
|
||||
Run the following:
|
||||
|
||||
```
|
||||
dotnet ef migrations add Init
|
||||
dotnet ef migrations script
|
||||
```
|
||||
|
||||
This will generate a SQL script to initialize a database based on the models in Infrastructure.EntityFramework.Models.
|
||||
|
||||
This is helpful to check against the proposed database changes provided in /src/SQL
|
||||
18
util/SqlServerEFScaffold/SqlServerEFScaffold.csproj
Normal file
18
util/SqlServerEFScaffold/SqlServerEFScaffold.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\EfShared\MigrationBuilderExtensions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Api\Api.csproj" />
|
||||
<ProjectReference Include="..\..\src\Core\Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\Infrastructure.EntityFramework\Infrastructure.EntityFramework.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2894
util/SqlServerEFScaffold/packages.lock.json
Normal file
2894
util/SqlServerEFScaffold/packages.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user