From 14c05c3c4371ecdcdc72a523d2e22e5ba192142c Mon Sep 17 00:00:00 2001 From: Jared Date: Sun, 4 Oct 2020 22:15:01 -0700 Subject: [PATCH] Fix multiple migration sets. --- Server/Data/ApplicationDbContext.cs | 2 +- Server/Data/PostgreSqlDbContext.cs | 5 +++-- Server/Data/SqlServerDbContext.cs | 2 +- Server/Data/SqliteDbContext.cs | 5 +++-- ....Designer.cs => 20201005051254_Initial.Designer.cs} | 4 ++-- ...1851_InitialCreate.cs => 20201005051254_Initial.cs} | 2 +- Server/Server.csproj | 1 + Server/Startup.cs | 10 +++------- 8 files changed, 15 insertions(+), 16 deletions(-) rename Server/Migrations/PostgreSql/{20201002211851_InitialCreate.Designer.cs => 20201005051254_Initial.Designer.cs} (99%) rename Server/Migrations/PostgreSql/{20201002211851_InitialCreate.cs => 20201005051254_Initial.cs} (99%) diff --git a/Server/Data/ApplicationDbContext.cs b/Server/Data/ApplicationDbContext.cs index 1d7728dd..fc1bc855 100644 --- a/Server/Data/ApplicationDbContext.cs +++ b/Server/Data/ApplicationDbContext.cs @@ -13,7 +13,7 @@ namespace Remotely.Server.Data { public class ApplicationDbContext : IdentityDbContext { - public ApplicationDbContext(DbContextOptions context) + public ApplicationDbContext(DbContextOptions context) : base(context) { } diff --git a/Server/Data/PostgreSqlDbContext.cs b/Server/Data/PostgreSqlDbContext.cs index 07da8621..2e7c3d5e 100644 --- a/Server/Data/PostgreSqlDbContext.cs +++ b/Server/Data/PostgreSqlDbContext.cs @@ -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 context, IConfiguration configuration) + public PostgreSqlDbContext(DbContextOptions context, IConfiguration configuration) : base(context) { _configuration = configuration; diff --git a/Server/Data/SqlServerDbContext.cs b/Server/Data/SqlServerDbContext.cs index 6d0e0ff7..4f6b9dbe 100644 --- a/Server/Data/SqlServerDbContext.cs +++ b/Server/Data/SqlServerDbContext.cs @@ -12,7 +12,7 @@ namespace Remotely.Server.Data { private readonly IConfiguration _configuration; - public SqlServerDbContext(DbContextOptions context, IConfiguration configuration) + public SqlServerDbContext(DbContextOptions context, IConfiguration configuration) : base(context) { _configuration = configuration; diff --git a/Server/Data/SqliteDbContext.cs b/Server/Data/SqliteDbContext.cs index e4d31139..be7f98ac 100644 --- a/Server/Data/SqliteDbContext.cs +++ b/Server/Data/SqliteDbContext.cs @@ -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 context, IConfiguration configuration) + public SqliteDbContext(DbContextOptions context, IConfiguration configuration) : base(context) { _configuration = configuration; diff --git a/Server/Migrations/PostgreSql/20201002211851_InitialCreate.Designer.cs b/Server/Migrations/PostgreSql/20201005051254_Initial.Designer.cs similarity index 99% rename from Server/Migrations/PostgreSql/20201002211851_InitialCreate.Designer.cs rename to Server/Migrations/PostgreSql/20201005051254_Initial.Designer.cs index 8cf91f3c..fd0b53aa 100644 --- a/Server/Migrations/PostgreSql/20201002211851_InitialCreate.Designer.cs +++ b/Server/Migrations/PostgreSql/20201005051254_Initial.Designer.cs @@ -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) { diff --git a/Server/Migrations/PostgreSql/20201002211851_InitialCreate.cs b/Server/Migrations/PostgreSql/20201005051254_Initial.cs similarity index 99% rename from Server/Migrations/PostgreSql/20201002211851_InitialCreate.cs rename to Server/Migrations/PostgreSql/20201005051254_Initial.cs index ec9c767a..d919e55c 100644 --- a/Server/Migrations/PostgreSql/20201002211851_InitialCreate.cs +++ b/Server/Migrations/PostgreSql/20201005051254_Initial.cs @@ -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) { diff --git a/Server/Server.csproj b/Server/Server.csproj index 2be03471..5fa7dbb5 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -86,6 +86,7 @@ + diff --git a/Server/Startup.cs b/Server/Startup.cs index f6a923e5..d2f9c05c 100644 --- a/Server/Startup.cs +++ b/Server/Startup.cs @@ -43,9 +43,7 @@ namespace Remotely.Server var dbProvider = Configuration["ApplicationOptions:DBProvider"].ToLower(); if (dbProvider == "sqlite") { - services.AddDbContext(); - - services.AddDbContext(options => + services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("SQLite"))); services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128) @@ -55,8 +53,7 @@ namespace Remotely.Server } else if (dbProvider == "sqlserver") { - services.AddDbContext(); - services.AddDbContext(options => + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("SQLServer"))); @@ -67,8 +64,7 @@ namespace Remotely.Server } else if (dbProvider == "postgresql") { - services.AddDbContext(); - services.AddDbContext(options => + services.AddDbContext(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