Fix multiple migration sets.

This commit is contained in:
Jared 2020-10-04 22:15:01 -07:00 committed by Jared Goodwin
parent 62fcb60279
commit 14c05c3c43
8 changed files with 15 additions and 16 deletions

View File

@ -13,7 +13,7 @@ namespace Remotely.Server.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> context)
public ApplicationDbContext(DbContextOptions context)
: base(context)
{
}

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Npgsql;
using System;
@ -12,7 +13,7 @@ namespace Remotely.Server.Data
{
private readonly IConfiguration _configuration;
public PostgreSqlDbContext(DbContextOptions<ApplicationDbContext> context, IConfiguration configuration)
public PostgreSqlDbContext(DbContextOptions context, IConfiguration configuration)
: base(context)
{
_configuration = configuration;

View File

@ -12,7 +12,7 @@ namespace Remotely.Server.Data
{
private readonly IConfiguration _configuration;
public SqlServerDbContext(DbContextOptions<ApplicationDbContext> context, IConfiguration configuration)
public SqlServerDbContext(DbContextOptions context, IConfiguration configuration)
: base(context)
{
_configuration = configuration;

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
@ -11,7 +12,7 @@ namespace Remotely.Server.Data
{
private readonly IConfiguration _configuration;
public SqliteDbContext(DbContextOptions<ApplicationDbContext> context, IConfiguration configuration)
public SqliteDbContext(DbContextOptions context, IConfiguration configuration)
: base(context)
{
_configuration = configuration;

View File

@ -10,8 +10,8 @@ using Remotely.Server.Data;
namespace Remotely.Server.Migrations.PostgreSql
{
[DbContext(typeof(PostgreSqlDbContext))]
[Migration("20201002211851_InitialCreate")]
partial class InitialCreate
[Migration("20201005051254_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Remotely.Server.Migrations.PostgreSql
{
public partial class InitialCreate : Migration
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{

View File

@ -86,6 +86,7 @@
<ItemGroup>
<Folder Include="Migrations\PostgreSql\" />
<Folder Include="Properties\" />
</ItemGroup>

View File

@ -43,9 +43,7 @@ namespace Remotely.Server
var dbProvider = Configuration["ApplicationOptions:DBProvider"].ToLower();
if (dbProvider == "sqlite")
{
services.AddDbContext<SqliteDbContext>();
services.AddDbContext<ApplicationDbContext>(options =>
services.AddDbContext<ApplicationDbContext, SqliteDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("SQLite")));
services.AddIdentity<RemotelyUser, IdentityRole>(options => options.Stores.MaxLengthForKeys = 128)
@ -55,8 +53,7 @@ namespace Remotely.Server
}
else if (dbProvider == "sqlserver")
{
services.AddDbContext<SqlServerDbContext>();
services.AddDbContext<ApplicationDbContext>(options =>
services.AddDbContext<ApplicationDbContext, SqlServerDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SQLServer")));
@ -67,8 +64,7 @@ namespace Remotely.Server
}
else if (dbProvider == "postgresql")
{
services.AddDbContext<PostgreSqlDbContext>();
services.AddDbContext<ApplicationDbContext>(options =>
services.AddDbContext<ApplicationDbContext, PostgreSqlDbContext>(options =>
{
// Password should be set in User Secrets in dev environment.
// See https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1