Fix USB IDs and indexes in databases.

This commit is contained in:
2018-12-24 21:13:02 +00:00
parent 383794bace
commit 5a0714e795
13 changed files with 1673 additions and 24 deletions

View File

@@ -221,6 +221,10 @@
<Compile Include="Migrations\201812240552109_StoreUsbIdsInDatabase.Designer.cs">
<DependentUpon>201812240552109_StoreUsbIdsInDatabase.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\201812241719441_FixUsbIdsAndIndexes.cs" />
<Compile Include="Migrations\201812241719441_FixUsbIdsAndIndexes.Designer.cs">
<DependentUpon>201812241719441_FixUsbIdsAndIndexes.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\Command.cs" />
<Compile Include="Models\Context.cs" />
@@ -325,6 +329,9 @@
<EmbeddedResource Include="Migrations\201812240552109_StoreUsbIdsInDatabase.resx">
<DependentUpon>201812240552109_StoreUsbIdsInDatabase.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\201812241719441_FixUsbIdsAndIndexes.resx">
<DependentUpon>201812241719441_FixUsbIdsAndIndexes.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@@ -0,0 +1,29 @@
// <auto-generated />
namespace DiscImageChef.Server.Migrations
{
using System.CodeDom.Compiler;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Resources;
[GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")]
public sealed partial class FixUsbIdsAndIndexes : IMigrationMetadata
{
private readonly ResourceManager Resources = new ResourceManager(typeof(FixUsbIdsAndIndexes));
string IMigrationMetadata.Id
{
get { return "201812241719441_FixUsbIdsAndIndexes"; }
}
string IMigrationMetadata.Source
{
get { return null; }
}
string IMigrationMetadata.Target
{
get { return Resources.GetString("Target"); }
}
}
}

View File

@@ -0,0 +1,25 @@
using System.Data.Entity.Migrations;
namespace DiscImageChef.Server.Migrations
{
public partial class FixUsbIdsAndIndexes : DbMigration
{
public override void Up()
{
AddColumn("dbo.UsbVendors", "VendorId", c => c.Int(false));
CreateIndex("dbo.UsbProducts", "ProductId");
CreateIndex("dbo.UsbProducts", "ModifiedWhen");
CreateIndex("dbo.UsbVendors", "VendorId", true);
CreateIndex("dbo.UsbVendors", "ModifiedWhen");
}
public override void Down()
{
DropIndex("dbo.UsbVendors", new[] {"ModifiedWhen"});
DropIndex("dbo.UsbVendors", new[] {"VendorId"});
DropIndex("dbo.UsbProducts", new[] {"ModifiedWhen"});
DropIndex("dbo.UsbProducts", new[] {"ProductId"});
DropColumn("dbo.UsbVendors", "VendorId");
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DiscImageChef.Server.Models
{
@@ -7,22 +8,24 @@ namespace DiscImageChef.Server.Models
{
public UsbProduct() { }
public UsbProduct(ushort vendorId, ushort id, string product)
public UsbProduct(UsbVendor vendor, ushort id, string product)
{
ProductId = id;
Product = product;
AddedWhen = ModifiedWhen = DateTime.UtcNow;
Vendor = vendor;
}
[Key]
public int Id { get; set; }
public int ProductId { get; set; }
public string Product { get; set; }
public DateTime AddedWhen { get; set; }
public int Id { get; set; }
[Index]
public int ProductId { get; set; }
public string Product { get; set; }
public DateTime AddedWhen { get; set; }
[Index]
public DateTime ModifiedWhen { get; set; }
public int VendorId { get; set; }
public virtual UsbVendor Vendor { get; set; }
[Index]
public int VendorId { get; set; }
public virtual UsbVendor Vendor { get; set; }
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DiscImageChef.Server.Models
{
@@ -10,15 +11,18 @@ namespace DiscImageChef.Server.Models
public UsbVendor(ushort id, string vendor)
{
Id = id;
VendorId = id;
Vendor = vendor;
AddedWhen = ModifiedWhen = DateTime.UtcNow;
}
[Key]
public int Id { get; set; }
public string Vendor { get; set; }
public DateTime AddedWhen { get; set; }
public int Id { get; set; }
[Index(IsUnique = true)]
public int VendorId { get; set; }
public string Vendor { get; set; }
public DateTime AddedWhen { get; set; }
[Index]
public DateTime ModifiedWhen { get; set; }
public virtual ICollection<UsbProduct> Products { get; set; }