Skip to content

Commit

Permalink
Adding db migrations to fix column lengths for package tables
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Aug 22, 2012
1 parent 5e75072 commit e1f2302
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 3 deletions.
45 changes: 45 additions & 0 deletions Website/Entities/Package.cs
Expand Up @@ -22,32 +22,77 @@ public Package()

public virtual ICollection<PackageStatistics> DownloadStatistics { get; set; }
public virtual ICollection<PackageAuthor> Authors { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string Copyright { get; set; }
public DateTime Created { get; set; }
public virtual ICollection<PackageDependency> Dependencies { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed but *IS* used for searches. Db column is nvarchar(max).
/// </remarks>
public string Description { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string ReleaseNotes { get; set; }
public int DownloadCount { get; set; }

/// <remarks>
/// Is not a property that we support. Maintained for legacy reasons.
/// </remarks>
public string ExternalPackageUrl { get; set; }

[StringLength(10)]
public string HashAlgorithm { get; set; }

[StringLength(256), Required]
public string Hash { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string IconUrl { get; set; }
public bool IsLatest { get; set; }
public bool IsLatestStable { get; set; }
public DateTime LastUpdated { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string LicenseUrl { get; set; }

[StringLength(20)]
public string Language { get; set; }

public DateTime Published { get; set; }
public long PackageFileSize { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string ProjectUrl { get; set; }
public bool RequiresLicenseAcceptance { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string Summary { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and *IS* used for searches, but is maintained via Lucene. Db column is nvarchar(max).
/// </remarks>
public string Tags { get; set; }

[StringLength(256)]
public string Title { get; set; }

[StringLength(64), Required]
public string Version { get; set; }

public bool Listed { get; set; }
public bool IsPrerelease { get; set; }
public virtual ICollection<PackageFramework> SupportedFrameworks { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions Website/Entities/PackageAuthor.cs
Expand Up @@ -7,6 +7,10 @@ public class PackageAuthor : IEntity

public Package Package { get; set; }
public int PackageKey { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string Name { get; set; }
}
}
12 changes: 11 additions & 1 deletion Website/Entities/PackageDependency.cs
@@ -1,4 +1,5 @@

using System.ComponentModel.DataAnnotations;

namespace NuGetGallery
{
public class PackageDependency : IEntity
Expand All @@ -8,8 +9,17 @@ public class PackageDependency : IEntity
public Package Package { get; set; }
public int PackageKey { get; set; }

/// <remarks>
/// We insert a record with a null Id to indicate an empty package dependency set. In such a case, the Id would be empty and hence
/// we cannot mandate that it is required.
/// </remarks>
[StringLength(128)]
public string Id { get; set; }

[StringLength(256)]
public string VersionSpec { get; set; }

[StringLength(256)]
public string TargetFramework { get; set; }
}
}
2 changes: 2 additions & 0 deletions Website/Entities/PackageFramework.cs
Expand Up @@ -12,6 +12,8 @@ public class PackageFramework : IEntity, IEquatable<PackageFramework>
public int Key { get; set; }

public Package Package { get; set; }

[StringLength(256)]
public string TargetFramework
{
get
Expand Down
2 changes: 2 additions & 0 deletions Website/Entities/PackageRegistration.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace NuGetGallery
{
Expand All @@ -12,6 +13,7 @@ public PackageRegistration()

public int Key { get; set; }

[StringLength(128), Required]
public string Id { get; set; }
public int DownloadCount { get; set; }
public virtual ICollection<User> Owners { get; set; }
Expand Down

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

68 changes: 68 additions & 0 deletions Website/Migrations/201208222206329_ColumnLengthOfPackageTable.cs
@@ -0,0 +1,68 @@
namespace NuGetGallery.Migrations
{
using System.Data.Entity.Migrations;

public partial class ColumnLengthOfPackageTable : DbMigration
{
public override void Up()
{
// There's an existing index that prevents altering these columns. We'll drop the index and recreate it.
DropIndex(table: "Packages", name: "IX_Packages_PackageRegistrationKey");

AlterColumn("PackageRegistrations", "Id", c => c.String(nullable: false, maxLength: 128));
AlterColumn("Packages", "HashAlgorithm", c => c.String(maxLength: 10));
AlterColumn("Packages", "Hash", c => c.String(nullable: false, maxLength: 256));
AlterColumn("Packages", "Title", c => c.String(maxLength: 256));
AlterColumn("Packages", "Version", c => c.String(nullable: false, maxLength: 64));
AlterColumn("PackageDependencies", "Id", c => c.String(maxLength: 128));
AlterColumn("PackageDependencies", "VersionSpec", c => c.String(maxLength: 256));
AlterColumn("PackageDependencies", "TargetFramework", c => c.String(maxLength: 256));
AlterColumn("PackageFrameworks", "TargetFramework", c => c.String(maxLength: 256));

// CreateIndex does not support INCLUDE
Sql(@"CREATE NONCLUSTERED INDEX [IX_Packages_PackageRegistrationKey] ON [dbo].[Packages]
(
[PackageRegistrationKey] ASC
)
INCLUDE ( [Key],
[Copyright],
[Created],
[Description],
[DownloadCount],
[ExternalPackageUrl],
[HashAlgorithm],
[Hash],
[IconUrl],
[IsLatest],
[LastUpdated],
[LicenseUrl],
[Published],
[PackageFileSize],
[ProjectUrl],
[RequiresLicenseAcceptance],
[Summary],
[Tags],
[Title],
[Version],
[FlattenedAuthors],
[FlattenedDependencies],
[IsLatestStable],
[Listed],
[IsPrerelease],
[ReleaseNotes])");
}

public override void Down()
{
AlterColumn("PackageFrameworks", "TargetFramework", c => c.String());
AlterColumn("PackageDependencies", "TargetFramework", c => c.String());
AlterColumn("PackageDependencies", "VersionSpec", c => c.String());
AlterColumn("PackageDependencies", "Id", c => c.String());
AlterColumn("Packages", "Version", c => c.String());
AlterColumn("Packages", "Title", c => c.String());
AlterColumn("Packages", "Hash", c => c.String());
AlterColumn("Packages", "HashAlgorithm", c => c.String());
AlterColumn("PackageRegistrations", "Id", c => c.String());
}
}
}
22 changes: 20 additions & 2 deletions Website/Services/PackageService.cs
Expand Up @@ -348,13 +348,31 @@ static void ValidateNuGetPackage(IPackage nugetPackage)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Summary", "4000");
if (nugetPackage.Tags != null && nugetPackage.Tags.ToString().Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Tags", "4000");
if (nugetPackage.Title != null && nugetPackage.Title.Length > 4000)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Title", "4000");
if (nugetPackage.Title != null && nugetPackage.Title.Length > 256)
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Title", "256");

if (nugetPackage.Version != null && nugetPackage.Version.ToString().Length > 64)
{
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Version", "64");
}

if (nugetPackage.Language != null && nugetPackage.Language.Length > 20)
{
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Language", "20");
}

foreach (var dependency in nugetPackage.DependencySets.SelectMany(s => s.Dependencies))
{
if (dependency.Id != null && dependency.Id.Length > 128)
{
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Dependency.Id", "128");
}

if (dependency.VersionSpec != null && dependency.VersionSpec.ToString().Length > 256)
{
throw new EntityException(Strings.NuGetPackagePropertyTooLong, "Dependency.VersionSpec", "256");
}
}
}

private static void UpdateIsLatest(PackageRegistration packageRegistration)
Expand Down
4 changes: 4 additions & 0 deletions Website/Website.csproj
Expand Up @@ -358,6 +358,10 @@
<Compile Include="Migrations\201208171904586_Language.Designer.cs">
<DependentUpon>201208171904586_Language.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201208222206329_ColumnLengthOfPackageTable.cs" />
<Compile Include="Migrations\201208222206329_ColumnLengthOfPackageTable.Designer.cs">
<DependentUpon>201208222206329_ColumnLengthOfPackageTable.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\MigrationsConfiguration.cs" />
<Compile Include="PackageCurators\IAutomaticPackageCurator.cs" />
<Compile Include="PackageCurators\AutomaticPackageCurator.cs" />
Expand Down

0 comments on commit e1f2302

Please sign in to comment.