Skip to content

Commit

Permalink
Fix migration issue #3865
Browse files Browse the repository at this point in the history
  • Loading branch information
chenriksson committed May 3, 2017
1 parent f862709 commit 9abf738
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/Entities/UserSecurityPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public UserSecurityPolicy(string name)
/// Type name for the policy handler that provides policy behavior.
/// </summary>
[Required]
[StringLength(256)]
public string Name { get; set; }

/// <summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/NuGetGallery/Migrations/201705032101231_SecurityPoliciesFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace NuGetGallery.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class SecurityPoliciesFix : DbMigration
{
public override void Up()
{
DropUserSecurityPoliciesIfExists();

CreateTable(
"dbo.UserSecurityPolicies",
c => new
{
Key = c.Int(nullable: false, identity: true),
UserKey = c.Int(nullable: false),
Name = c.String(nullable: false, maxLength: 256),
Value = c.String(),
})
.PrimaryKey(t => t.Key)
.ForeignKey("dbo.Users", t => t.UserKey, cascadeDelete: true)
.Index(t => t.UserKey);

}

public override void Down()
{
DropForeignKey("dbo.UserSecurityPolicies", "UserKey", "dbo.Users");
DropIndex("dbo.UserSecurityPolicies", new[] { "UserKey" });
DropTable("dbo.UserSecurityPolicies");
}

private void DropUserSecurityPoliciesIfExists()
{
try
{
DropForeignKey("dbo.UserSecurityPolicies", "UserKey", "dbo.Users");
DropTable("dbo.UserSecurityPolicies");
}
catch (Exception) { }
}
}
}
Loading

0 comments on commit 9abf738

Please sign in to comment.