-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi provider support for EF (SQL and Sqlite)
- Do not add the DbContext in DataAccess.EF any more - Add projects for MsSql and Sqlite which add the DbContext - Use the config value Database.Provider to determine which provider will be added - Delete all existing migrations - Generate migrations for each provider separately - Manually add trigger creation for concurrent modifications with the BaseEntity.Version field to Sqlite migration (dotnet/efcore#12260 (comment)) - Use Sqlite for integration and api tests
- Loading branch information
Showing
38 changed files
with
872 additions
and
2,205 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...0123341_UserProfileVisibility.Designer.cs → ...ations/20190501062329_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...frastructure.DataAccess.EF.MsSql/Sppd.TeamTuner.Infrastructure.DataAccess.EF.MsSql.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Sppd.TeamTuner.Core\Sppd.TeamTuner.Core.csproj" /> | ||
<ProjectReference Include="..\Sppd.TeamTuner.Infrastructure.DataAccess.EF\Sppd.TeamTuner.Infrastructure.DataAccess.EF.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
40 changes: 40 additions & 0 deletions
40
Backend/Sppd.TeamTuner.Infrastructure.DataAccess.EF.MsSql/StartupRegistrator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using Sppd.TeamTuner.Core; | ||
using Sppd.TeamTuner.Core.Services; | ||
using Sppd.TeamTuner.Core.Utils.Extensions; | ||
using Sppd.TeamTuner.Infrastructure.DataAccess.EF.Config; | ||
|
||
namespace Sppd.TeamTuner.Infrastructure.DataAccess.EF.MsSql | ||
{ | ||
public class StartupRegistrator : IStartupRegistrator | ||
{ | ||
private const string PROVIDER_NAME = "MsSql"; | ||
private const string ID_PLACEHOLDER = "{id}"; | ||
|
||
public int Priority => 90; | ||
|
||
public void Register(IServiceCollection services) | ||
{ | ||
var databaseConfig = services.BuildServiceProvider().GetConfig<DatabaseConfig>(); | ||
|
||
if (PROVIDER_NAME.Equals(databaseConfig.Provider, StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
// Add a random string if the {id} specifier is contained in the connection string | ||
var dbId = Guid.NewGuid().ToString("n").Substring(0, 8); | ||
databaseConfig.ConnectionString = databaseConfig.ConnectionString.Replace(ID_PLACEHOLDER, dbId); | ||
|
||
services.AddDbContext<TeamTunerContextMsSql>(options => options.UseSqlServer(databaseConfig.ConnectionString)) | ||
.AddScoped<TeamTunerContext, TeamTunerContextMsSql>() | ||
.AddScoped<IDatabaseService, TeamTunerContextMsSql>(); | ||
} | ||
} | ||
|
||
public void Configure(IServiceProvider serviceProvider) | ||
{ | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Backend/Sppd.TeamTuner.Infrastructure.DataAccess.EF.MsSql/TeamTunerContextMsSql.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
|
||
using Sppd.TeamTuner.Core.Domain.Interfaces; | ||
using Sppd.TeamTuner.Core.Services; | ||
|
||
namespace Sppd.TeamTuner.Infrastructure.DataAccess.EF.MsSql | ||
{ | ||
/// <summary> | ||
/// Extends <see cref="TeamTunerContext" /> to allow managing migrations in the project. | ||
/// </summary> | ||
/// <seealso cref="TeamTunerContext" /> | ||
internal class TeamTunerContextMsSql : TeamTunerContext | ||
{ | ||
public TeamTunerContextMsSql(DbContextOptions options, Lazy<IValidationService> validationService, IEnumerable<Lazy<IEntityMetadataProvider>> entityMetadataProviders) | ||
: base(options, validationService, entityMetadataProviders) | ||
{ | ||
} | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
...0190422085433_UniqueCardLevel.Designer.cs → ...ations/20190501061552_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.