diff --git a/src/REstate.Engine.Repositories.EntityFrameworkCore/REstateDbContext.cs b/src/REstate.Engine.Repositories.EntityFrameworkCore/REstateDbContext.cs index 178ef7e..b6d413e 100644 --- a/src/REstate.Engine.Repositories.EntityFrameworkCore/REstateDbContext.cs +++ b/src/REstate.Engine.Repositories.EntityFrameworkCore/REstateDbContext.cs @@ -85,6 +85,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(450) .IsRequired(); + modelBuilder.Entity() + .HasIndex(entry => entry.Key); + modelBuilder.Entity() .HasKey(entry => new { diff --git a/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.Designer.cs b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.Designer.cs new file mode 100644 index 0000000..7339d30 --- /dev/null +++ b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.Designer.cs @@ -0,0 +1,118 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using REstate.Engine.Repositories.EntityFrameworkCore; + +namespace REstate.EntityFrameworkCore.Migrations.SqlServer.Migrations +{ + [DbContext(typeof(REstateDbContext))] + [Migration("20190111035035_IndexMetadataEntriesKey")] + partial class IndexMetadataEntriesKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.1.4-rtm-31024") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.Machine", b => + { + b.Property("MachineId") + .ValueGeneratedOnAdd() + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("CommitNumber") + .IsConcurrencyToken(); + + b.Property("SchematicBytes"); + + b.Property("SchematicName") + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("StateJson") + .IsRequired() + .IsUnicode(false); + + b.Property("UpdatedTime"); + + b.HasKey("MachineId"); + + b.ToTable("Machines"); + }); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.MetadataEntry", b => + { + b.Property("MachineId") + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("Key") + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("Value"); + + b.HasKey("MachineId", "Key"); + + b.HasIndex("Key"); + + b.ToTable("MetadataEntries"); + }); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.Schematic", b => + { + b.Property("SchematicName") + .ValueGeneratedOnAdd() + .IsUnicode(false); + + b.Property("SchematicBytes"); + + b.HasKey("SchematicName"); + + b.ToTable("Schematics"); + }); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.StateBagEntry", b => + { + b.Property("MachineId") + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("Key") + .HasMaxLength(450) + .IsUnicode(false); + + b.Property("Value"); + + b.HasKey("MachineId", "Key"); + + b.ToTable("StateBagEntries"); + }); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.MetadataEntry", b => + { + b.HasOne("REstate.Engine.Repositories.EntityFrameworkCore.Machine") + .WithMany("MetadataEntries") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("REstate.Engine.Repositories.EntityFrameworkCore.StateBagEntry", b => + { + b.HasOne("REstate.Engine.Repositories.EntityFrameworkCore.Machine") + .WithMany("StateBagEntries") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.cs b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.cs new file mode 100644 index 0000000..9409d8e --- /dev/null +++ b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/20190111035035_IndexMetadataEntriesKey.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace REstate.EntityFrameworkCore.Migrations.SqlServer.Migrations +{ + public partial class IndexMetadataEntriesKey : Migration + { + private const string SqlServer = "Microsoft.EntityFrameworkCore.SqlServer"; + + protected override void Up(MigrationBuilder migrationBuilder) + { + if (migrationBuilder.ActiveProvider == SqlServer) + { + migrationBuilder.Sql(@"CREATE NONCLUSTERED INDEX IX_MetadataEntries_Key +ON [dbo].[MetadataEntries] ([Key]) +INCLUDE ([Value])"); + } + else + { + migrationBuilder.CreateIndex( + name: "IX_MetadataEntries_Key", + table: "MetadataEntries", + column: "Key"); + } + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_MetadataEntries_Key", + table: "MetadataEntries"); + } + } +} diff --git a/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/REstateDbContextModelSnapshot.cs b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/REstateDbContextModelSnapshot.cs index f491a95..b4ead75 100644 --- a/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/REstateDbContextModelSnapshot.cs +++ b/src/REstate.EntityFrameworkCore.Migrations.SqlServer/Migrations/REstateDbContextModelSnapshot.cs @@ -60,6 +60,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("MachineId", "Key"); + b.HasIndex("Key"); + b.ToTable("MetadataEntries"); });