React to Migrations changes
This commit is contained in:
parent
4139f3f18b
commit
a09d8a4ead
|
|
@ -8,14 +8,9 @@ using Microsoft.AspNet.Diagnostics.Entity.Views;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.RequestContainer;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Internal;
|
||||
using Microsoft.Data.Entity.Relational;
|
||||
using Microsoft.Data.Entity.Relational.Migrations;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Utilities;
|
||||
using Microsoft.Data.Entity.Utilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
|
@ -54,7 +49,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
try
|
||||
{
|
||||
#if !ASPNETCORE50
|
||||
// TODO This probably isn't the correct place for this workaround, it
|
||||
// TODO This probably isn't the correct place for this workaround, it
|
||||
// needs to be called before anything is written to CallContext
|
||||
// http://msdn.microsoft.com/en-us/library/dn458353(v=vs.110).aspx
|
||||
System.Configuration.ConfigurationManager.GetSection("system.xml/xmlReader");
|
||||
|
|
@ -89,14 +84,9 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
|
||||
var migrator = ((IAccessor<Migrator>)dbContext.Database).Service;
|
||||
|
||||
var pendingMigrations = migrator.GetPendingMigrations().Select(m => m.GetMigrationId());
|
||||
var pendingMigrations = migrator.GetUnappliedMigrations().Select(m => m.Id);
|
||||
|
||||
var pendingModelChanges = true;
|
||||
var snapshot = migrator.MigrationAssembly.ModelSnapshot;
|
||||
if (snapshot != null)
|
||||
{
|
||||
pendingModelChanges = migrator.ModelDiffer.Diff(snapshot.Model, dbContext.Model).Any();
|
||||
}
|
||||
var pendingModelChanges = migrator.HasPendingModelChanges();
|
||||
|
||||
if ((!databaseExists && pendingMigrations.Any()) || pendingMigrations.Any() || pendingModelChanges)
|
||||
{
|
||||
|
|
@ -128,7 +118,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
logger.WriteVerbose(Strings.DatabaseErrorPage_NoRecordedException);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool match = false;
|
||||
for (var e = exception; e != null && !match; e = e.InnerException)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,15 +11,12 @@ using Microsoft.AspNet.Builder;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Internal;
|
||||
using Microsoft.Data.Entity.Relational.Migrations;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Utilities;
|
||||
using Microsoft.Data.Entity.Utilities;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.History;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Tests.Helpers;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
||||
{
|
||||
|
|
@ -105,11 +102,11 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
|
||||
Assert.True(db.Database.AsRelational().Exists());
|
||||
|
||||
var migrator = ((IAccessor<Migrator>)db.Database).Service;
|
||||
var appliedMigrations = migrator.GetDatabaseMigrations();
|
||||
var historyRepository = ((IAccessor<IServiceProvider>)db).Service.GetRequiredService<DbContextService<IHistoryRepository>>().Service;
|
||||
var appliedMigrations = historyRepository.GetAppliedMigrations();
|
||||
Assert.Equal(2, appliedMigrations.Count);
|
||||
Assert.Equal("111111111111111_MigrationOne", appliedMigrations.ElementAt(0).GetMigrationId());
|
||||
Assert.Equal("222222222222222_MigrationTwo", appliedMigrations.ElementAt(1).GetMigrationId());
|
||||
Assert.Equal("111111111111111_MigrationOne", appliedMigrations.ElementAt(0).MigrationId);
|
||||
Assert.Equal("222222222222222_MigrationTwo", appliedMigrations.ElementAt(1).MigrationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -208,7 +205,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
await server.CreateClient().PostAsync("http://localhost" + MigrationsEndPointOptions.DefaultPath, formData));
|
||||
|
||||
Assert.Equal(StringsHelpers.GetResourceString("FormatMigrationsEndPointMiddleware_Exception", typeof(BloggingContextWithSnapshotThatThrows)), ex.Message);
|
||||
Assert.Equal("Welcome to the invalid snapshot!", ex.InnerException.Message);
|
||||
Assert.Equal("Welcome to the invalid migration!", ex.InnerException.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
_connectionString = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = @"(localdb)\v11.0",
|
||||
DataSource = @"(localdb)\MSSQLLocalDB",
|
||||
InitialCatalog = name,
|
||||
IntegratedSecurity = true,
|
||||
ConnectTimeout = 30
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Relational.Migrations;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
public class BloggingContext : DbContext
|
||||
{
|
||||
protected static readonly string CurrentProductVersion = typeof(HistoryRepository)
|
||||
protected static readonly string CurrentProductVersion = typeof(Migrator)
|
||||
.GetTypeInfo()
|
||||
.Assembly
|
||||
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ using Microsoft.Data.Entity.Relational.Migrations;
|
|||
using Microsoft.Data.Entity.Relational.Migrations.Builders;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
||||
{
|
||||
|
|
@ -51,19 +50,19 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
}
|
||||
|
||||
[ContextType(typeof(BloggingContextWithMigrations))]
|
||||
public class MigrationOne : Migration, IMigrationMetadata
|
||||
public class MigrationOne : Migration
|
||||
{
|
||||
string IMigrationMetadata.MigrationId
|
||||
public override string Id
|
||||
{
|
||||
get { return "111111111111111_MigrationOne"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.ProductVersion
|
||||
public override string ProductVersion
|
||||
{
|
||||
get { return CurrentProductVersion; }
|
||||
}
|
||||
|
||||
IModel IMigrationMetadata.TargetModel
|
||||
public override IModel Target
|
||||
{
|
||||
get { return new BloggingContextWithMigrationsModelSnapshot().Model; }
|
||||
}
|
||||
|
|
@ -73,10 +72,10 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
migrationBuilder.CreateTable("Blog",
|
||||
c => new
|
||||
{
|
||||
BlogId = c.Int(nullable: false, identity: true),
|
||||
Name = c.String(),
|
||||
BlogId = c.Column("int", annotations: new Dictionary<string, string> { { "SqlServer:ValueGeneration", "Identity" } }),
|
||||
Name = c.Column("nvarchar(max)", nullable: true),
|
||||
})
|
||||
.PrimaryKey("PK_Blog", t => t.BlogId);
|
||||
.PrimaryKey(t => t.BlogId, name: "PK_Blog");
|
||||
}
|
||||
|
||||
public override void Down(MigrationBuilder migrationBuilder)
|
||||
|
|
@ -86,19 +85,19 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
}
|
||||
|
||||
[ContextType(typeof(BloggingContextWithMigrations))]
|
||||
public class MigrationTwo : Migration, IMigrationMetadata
|
||||
public class MigrationTwo : Migration
|
||||
{
|
||||
string IMigrationMetadata.MigrationId
|
||||
public override string Id
|
||||
{
|
||||
get { return "222222222222222_MigrationTwo"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.ProductVersion
|
||||
public override string ProductVersion
|
||||
{
|
||||
get { return CurrentProductVersion; }
|
||||
}
|
||||
|
||||
IModel IMigrationMetadata.TargetModel
|
||||
public override IModel Target
|
||||
{
|
||||
get { return new BloggingContextWithMigrationsModelSnapshot().Model; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,19 +26,19 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
}
|
||||
|
||||
[ContextType(typeof(BloggingContextWithPendingModelChanges))]
|
||||
public partial class MigrationOne : Migration, IMigrationMetadata
|
||||
public partial class MigrationOne : Migration
|
||||
{
|
||||
string IMigrationMetadata.MigrationId
|
||||
public override string Id
|
||||
{
|
||||
get { return "111111111111111_MigrationOne"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.ProductVersion
|
||||
public override string ProductVersion
|
||||
{
|
||||
get { return CurrentProductVersion; }
|
||||
}
|
||||
|
||||
IModel IMigrationMetadata.TargetModel
|
||||
public override IModel Target
|
||||
{
|
||||
get { return new BasicModelBuilder().Model; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ using Microsoft.Data.Entity.Relational.Migrations;
|
|||
using Microsoft.Data.Entity.Relational.Migrations.Builders;
|
||||
using Microsoft.Data.Entity.Relational.Migrations.Infrastructure;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
||||
{
|
||||
|
|
@ -31,19 +29,19 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
}
|
||||
|
||||
[ContextType(typeof(BloggingContextWithSnapshotThatThrows))]
|
||||
public class MigrationOne : Migration, IMigrationMetadata
|
||||
public class MigrationOne : Migration
|
||||
{
|
||||
string IMigrationMetadata.MigrationId
|
||||
public override string Id
|
||||
{
|
||||
get { return "111111111111111_MigrationOne"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.ProductVersion
|
||||
public override string ProductVersion
|
||||
{
|
||||
get { return CurrentProductVersion; }
|
||||
}
|
||||
|
||||
IModel IMigrationMetadata.TargetModel
|
||||
public override IModel Target
|
||||
{
|
||||
get { return new BloggingContextWithSnapshotThatThrowsModelSnapshot().Model; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue