Permalink
Browse files

Adding db migrations to fix column lengths for package tables

  • Loading branch information...
1 parent 5e75072 commit e1f2302194588d391baa7c8c4413f104ef57ca50 @pranavkm pranavkm committed Aug 22, 2012
@@ -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; }
@@ -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; }
}
}
@@ -1,4 +1,5 @@
-
+using System.ComponentModel.DataAnnotations;
+
namespace NuGetGallery
{
public class PackageDependency : IEntity
@@ -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; }
}
}
@@ -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
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
namespace NuGetGallery
{
@@ -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; }

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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());
+ }
+ }
+}
@@ -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)
View
@@ -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" />

0 comments on commit e1f2302

Please sign in to comment.