Skip to content

Commit

Permalink
Merge pull request #4394 from NuGet/prefix-db-changes
Browse files Browse the repository at this point in the history
[Prefix] DB changes for Prefix reservation
  • Loading branch information
shishirx34 committed Jul 19, 2017
2 parents 8215eff + 4aeac85 commit 78b7d77
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NuGetGallery.Core/Entities/PackageRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ public PackageRegistration()
{
Owners = new HashSet<User>();
Packages = new HashSet<Package>();
ReservedNamespaces = new HashSet<ReservedNamespace>();
}

[StringLength(CoreConstants.MaxPackageIdLength)]
[Required]
public string Id { get; set; }

public int DownloadCount { get; set; }

public bool IsVerified { get; set; }

public virtual ICollection<User> Owners { get; set; }
public virtual ICollection<Package> Packages { get; set; }
public virtual ICollection<ReservedNamespace> ReservedNamespaces { get; set; }

public int Key { get; set; }
}
}
39 changes: 39 additions & 0 deletions src/NuGetGallery.Core/Entities/ReservedNamespace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace NuGetGallery
{
public class ReservedNamespace : IEntity
{
public ReservedNamespace()
: this(value: null, isSharedNamespace: false, isExactMatch: false)
{
}

public ReservedNamespace(string value, bool isSharedNamespace, bool isExactMatch)
{
Value = value;
IsSharedNamespace = isSharedNamespace;
IsPrefix = isExactMatch;
PackageRegistrations = new HashSet<PackageRegistration>();
ReservedNamespaceOwners = new HashSet<User>();
}

[StringLength(CoreConstants.MaxPackageIdLength)]
[Required]
public string Value { get; set; }

public bool IsSharedNamespace { get; set; }

public bool IsPrefix { get; set; }

public virtual ICollection<PackageRegistration> PackageRegistrations { get; set; }
public virtual ICollection<User> ReservedNamespaceOwners { get; set; }

[Key]
public int Key { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/NuGetGallery.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public User(string username)
{
Credentials = new List<Credential>();
SecurityPolicies = new List<UserSecurityPolicy>();
ReservedNamespaces = new HashSet<ReservedNamespace>();
Roles = new List<Role>();
Username = username;
}
Expand All @@ -36,8 +37,11 @@ public User(string username)
public string Username { get; set; }

public virtual ICollection<Role> Roles { get; set; }

public bool EmailAllowed { get; set; }

public virtual ICollection<ReservedNamespace> ReservedNamespaces { get; set; }

[DefaultValue(true)]
public bool NotifyPackagePushed { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<Compile Include="Entities\PackageLicense.cs" />
<Compile Include="Entities\PackageLicenseReport.cs" />
<Compile Include="Entities\PackageOwnerRequest.cs" />
<Compile Include="Entities\ReservedNamespace.cs" />
<Compile Include="Entities\PackageRegistration.cs" />
<Compile Include="Entities\PackageType.cs" />
<Compile Include="Entities\ReadOnlyModeException.cs" />
Expand Down

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

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

public partial class PrefixReservation : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.ReservedNamespaces",
c => new
{
Key = c.Int(nullable: false, identity: true),
Value = c.String(nullable: false, maxLength: 128),
IsSharedNamespace = c.Boolean(nullable: false),
IsPrefix = c.Boolean(nullable: false),
})
.PrimaryKey(t => t.Key);

CreateTable(
"dbo.PackageRegistrationReservedNamespaces",
c => new
{
PackageRegistration_Key = c.Int(nullable: false),
ReservedNamespace_Key = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.PackageRegistration_Key, t.ReservedNamespace_Key })
.ForeignKey("dbo.PackageRegistrations", t => t.PackageRegistration_Key, cascadeDelete: true)
.ForeignKey("dbo.ReservedNamespaces", t => t.ReservedNamespace_Key, cascadeDelete: true)
.Index(t => t.PackageRegistration_Key)
.Index(t => t.ReservedNamespace_Key);

CreateTable(
"dbo.ReservedNamespaceUsers",
c => new
{
ReservedNamespace_Key = c.Int(nullable: false),
User_Key = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.ReservedNamespace_Key, t.User_Key })
.ForeignKey("dbo.ReservedNamespaces", t => t.ReservedNamespace_Key, cascadeDelete: true)
.ForeignKey("dbo.Users", t => t.User_Key, cascadeDelete: true)
.Index(t => t.ReservedNamespace_Key)
.Index(t => t.User_Key);

AddColumn("dbo.PackageRegistrations", "IsVerified", c => c.Boolean(nullable: false));
}

public override void Down()
{
DropForeignKey("dbo.ReservedNamespaceUsers", "User_Key", "dbo.Users");
DropForeignKey("dbo.ReservedNamespaceUsers", "ReservedNamespace_Key", "dbo.ReservedNamespaces");
DropForeignKey("dbo.PackageRegistrationReservedNamespaces", "ReservedNamespace_Key", "dbo.ReservedNamespaces");
DropForeignKey("dbo.PackageRegistrationReservedNamespaces", "PackageRegistration_Key", "dbo.PackageRegistrations");
DropIndex("dbo.ReservedNamespaceUsers", new[] { "User_Key" });
DropIndex("dbo.ReservedNamespaceUsers", new[] { "ReservedNamespace_Key" });
DropIndex("dbo.PackageRegistrationReservedNamespaces", new[] { "ReservedNamespace_Key" });
DropIndex("dbo.PackageRegistrationReservedNamespaces", new[] { "PackageRegistration_Key" });
DropColumn("dbo.PackageRegistrations", "IsVerified");
DropTable("dbo.ReservedNamespaceUsers");
DropTable("dbo.PackageRegistrationReservedNamespaces");
DropTable("dbo.ReservedNamespaces");
}
}
}
126 changes: 126 additions & 0 deletions src/NuGetGallery/Migrations/201707131923337_PrefixReservation.resx

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,10 @@
<Compile Include="Migrations\201706080930506_AddIndexSemVerLevelKeyPackageRegistrationKey.Designer.cs">
<DependentUpon>201706080930506_AddIndexSemVerLevelKeyPackageRegistrationKey.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201707131923337_PrefixReservation.cs" />
<Compile Include="Migrations\201707131923337_PrefixReservation.Designer.cs">
<DependentUpon>201707131923337_PrefixReservation.cs</DependentUpon>
</Compile>
<Compile Include="Security\RequireSecurePushForCoOwnersPolicy.cs" />
<Compile Include="Security\SecurePushSubscription.cs" />
<Compile Include="Security\IUserSecurityPolicySubscription.cs" />
Expand Down Expand Up @@ -1765,6 +1769,9 @@
<EmbeddedResource Include="Migrations\201706080930506_AddIndexSemVerLevelKeyPackageRegistrationKey.resx">
<DependentUpon>201706080930506_AddIndexSemVerLevelKeyPackageRegistrationKey.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201707131923337_PrefixReservation.resx">
<DependentUpon>201707131923337_PrefixReservation.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="OData\QueryAllowed\Data\apiv1packages.json" />
<EmbeddedResource Include="OData\QueryAllowed\Data\apiv1search.json" />
<EmbeddedResource Include="OData\QueryAllowed\Data\apiv2getupdates.json" />
Expand Down

0 comments on commit 78b7d77

Please sign in to comment.