提交 a23ad6b9 编写于 作者: 麦壳饼's avatar 麦壳饼

调整了 sqlite和pgsql 关于产品 索引问题。

上级 be8f9c6b
......@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace IoTSharp.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20220913055638_Produce")]
[Migration("20220914112335_Produce")]
partial class Produce
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
......@@ -1990,7 +1990,10 @@ namespace IoTSharp.Migrations
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasIndex("DeviceId");
b.Property<Guid?>("OwnerId")
.HasColumnType("uuid");
b.HasIndex("OwnerId");
b.HasDiscriminator().HasValue(5);
});
......@@ -2475,9 +2478,7 @@ namespace IoTSharp.Migrations
{
b.HasOne("IoTSharp.Data.Produce", "Owner")
.WithMany("DefaultAttributes")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
......
......@@ -15,6 +15,12 @@ namespace IoTSharp.Migrations
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "OwnerId",
table: "DataStorage",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "Produce",
columns: table => new
......@@ -48,9 +54,9 @@ namespace IoTSharp.Migrations
column: "ProduceId");
migrationBuilder.CreateIndex(
name: "IX_DataStorage_DeviceId",
name: "IX_DataStorage_OwnerId",
table: "DataStorage",
column: "DeviceId");
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_Produce_CustomerId",
......@@ -63,12 +69,11 @@ namespace IoTSharp.Migrations
column: "TenantId");
migrationBuilder.AddForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
name: "FK_DataStorage_Produce_OwnerId",
table: "DataStorage",
column: "DeviceId",
column: "OwnerId",
principalTable: "Produce",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Device_Produce_ProduceId",
......@@ -81,7 +86,7 @@ namespace IoTSharp.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
name: "FK_DataStorage_Produce_OwnerId",
table: "DataStorage");
migrationBuilder.DropForeignKey(
......@@ -96,12 +101,16 @@ namespace IoTSharp.Migrations
table: "Device");
migrationBuilder.DropIndex(
name: "IX_DataStorage_DeviceId",
name: "IX_DataStorage_OwnerId",
table: "DataStorage");
migrationBuilder.DropColumn(
name: "ProduceId",
table: "Device");
migrationBuilder.DropColumn(
name: "OwnerId",
table: "DataStorage");
}
}
}
......@@ -1988,7 +1988,10 @@ namespace IoTSharp.Migrations
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasIndex("DeviceId");
b.Property<Guid?>("OwnerId")
.HasColumnType("uuid");
b.HasIndex("OwnerId");
b.HasDiscriminator().HasValue(5);
});
......@@ -2473,9 +2476,7 @@ namespace IoTSharp.Migrations
{
b.HasOne("IoTSharp.Data.Produce", "Owner")
.WithMany("DefaultAttributes")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
......
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IoTSharp.Data.SqlServer.Migrations
{
public partial class Produce : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ProduceId",
table: "Device",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.CreateTable(
name: "Produce",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
DefaultTimeout = table.Column<int>(type: "int", nullable: false),
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
CustomerId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DefaultIdentityType = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Produce", x => x.Id);
table.ForeignKey(
name: "FK_Produce_Customer_CustomerId",
column: x => x.CustomerId,
principalTable: "Customer",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Produce_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Device_ProduceId",
table: "Device",
column: "ProduceId");
migrationBuilder.CreateIndex(
name: "IX_DataStorage_DeviceId",
table: "DataStorage",
column: "DeviceId");
migrationBuilder.CreateIndex(
name: "IX_Produce_CustomerId",
table: "Produce",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_Produce_TenantId",
table: "Produce",
column: "TenantId");
migrationBuilder.AddForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
table: "DataStorage",
column: "DeviceId",
principalTable: "Produce",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Device_Produce_ProduceId",
table: "Device",
column: "ProduceId",
principalTable: "Produce",
principalColumn: "Id");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
table: "DataStorage");
migrationBuilder.DropForeignKey(
name: "FK_Device_Produce_ProduceId",
table: "Device");
migrationBuilder.DropTable(
name: "Produce");
migrationBuilder.DropIndex(
name: "IX_Device_ProduceId",
table: "Device");
migrationBuilder.DropIndex(
name: "IX_DataStorage_DeviceId",
table: "DataStorage");
migrationBuilder.DropColumn(
name: "ProduceId",
table: "Device");
}
}
}
......@@ -17,7 +17,7 @@ namespace IoTSharp.Data.SqlServer.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.8")
.HasAnnotation("ProductVersion", "6.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
......@@ -606,9 +606,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.Property<Guid?>("OwnerId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("ProduceId")
.HasColumnType("uniqueidentifier");
b.Property<int>("Status")
.HasColumnType("int");
......@@ -628,8 +625,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.HasIndex("OwnerId");
b.HasIndex("ProduceId");
b.HasIndex("TenantId");
b.ToTable("Device");
......@@ -1448,39 +1443,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.ToTable("FlowRules");
});
modelBuilder.Entity("IoTSharp.Data.Produce", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CustomerId")
.HasColumnType("uniqueidentifier");
b.Property<int>("DefaultIdentityType")
.HasColumnType("int");
b.Property<int>("DefaultTimeout")
.HasColumnType("int");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("Produce");
});
modelBuilder.Entity("IoTSharp.Data.RefreshToken", b =>
{
b.Property<Guid>("Id")
......@@ -1986,15 +1948,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.ProduceData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasIndex("DeviceId");
b.HasDiscriminator().HasValue(5);
});
modelBuilder.Entity("IoTSharp.Data.TelemetryLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
......@@ -2117,10 +2070,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
.WithMany("Children")
.HasForeignKey("OwnerId");
b.HasOne("IoTSharp.Data.Produce", null)
.WithMany("Devices")
.HasForeignKey("ProduceId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Devices")
.HasForeignKey("TenantId");
......@@ -2330,21 +2279,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.Produce", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
.WithMany()
.HasForeignKey("CustomerId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.RefreshToken", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
......@@ -2471,17 +2405,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
.IsRequired();
});
modelBuilder.Entity("IoTSharp.Data.ProduceData", b =>
{
b.HasOne("IoTSharp.Data.Produce", "Owner")
.WithMany("DefaultAttributes")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Owner");
});
modelBuilder.Entity("IoTSharp.Data.Asset", b =>
{
b.Navigation("OwnedAssets");
......@@ -2507,13 +2430,6 @@ namespace IoTSharp.Data.SqlServer.Migrations
b.Navigation("DeviceModelCommands");
});
modelBuilder.Entity("IoTSharp.Data.Produce", b =>
{
b.Navigation("DefaultAttributes");
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Navigation("Customers");
......
......@@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTSharp.Data.Sqlite.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20220913060035_Produce")]
[Migration("20220914122629_Produce")]
partial class Produce
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
......@@ -2193,7 +2193,10 @@ namespace IoTSharp.Data.Sqlite.Migrations
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasIndex("DeviceId");
b.Property<Guid?>("OwnerId")
.HasColumnType("TEXT");
b.HasIndex("OwnerId");
b.HasDiscriminator().HasValue(5);
});
......@@ -2678,9 +2681,7 @@ namespace IoTSharp.Data.Sqlite.Migrations
{
b.HasOne("IoTSharp.Data.Produce", "Owner")
.WithMany("DefaultAttributes")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
......
......@@ -15,6 +15,12 @@ namespace IoTSharp.Data.Sqlite.Migrations
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "OwnerId",
table: "DataStorage",
type: "TEXT",
nullable: true);
migrationBuilder.CreateTable(
name: "Produce",
columns: table => new
......@@ -48,9 +54,9 @@ namespace IoTSharp.Data.Sqlite.Migrations
column: "ProduceId");
migrationBuilder.CreateIndex(
name: "IX_DataStorage_DeviceId",
name: "IX_DataStorage_OwnerId",
table: "DataStorage",
column: "DeviceId");
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_Produce_CustomerId",
......@@ -63,12 +69,11 @@ namespace IoTSharp.Data.Sqlite.Migrations
column: "TenantId");
migrationBuilder.AddForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
name: "FK_DataStorage_Produce_OwnerId",
table: "DataStorage",
column: "DeviceId",
column: "OwnerId",
principalTable: "Produce",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Device_Produce_ProduceId",
......@@ -81,7 +86,7 @@ namespace IoTSharp.Data.Sqlite.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DataStorage_Produce_DeviceId",
name: "FK_DataStorage_Produce_OwnerId",
table: "DataStorage");
migrationBuilder.DropForeignKey(
......@@ -96,12 +101,16 @@ namespace IoTSharp.Data.Sqlite.Migrations
table: "Device");
migrationBuilder.DropIndex(
name: "IX_DataStorage_DeviceId",
name: "IX_DataStorage_OwnerId",
table: "DataStorage");
migrationBuilder.DropColumn(
name: "ProduceId",
table: "Device");
migrationBuilder.DropColumn(
name: "OwnerId",
table: "DataStorage");
}
}
}
......@@ -2191,7 +2191,10 @@ namespace IoTSharp.Data.Sqlite.Migrations
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasIndex("DeviceId");
b.Property<Guid?>("OwnerId")
.HasColumnType("TEXT");
b.HasIndex("OwnerId");
b.HasDiscriminator().HasValue(5);
});
......@@ -2676,9 +2679,7 @@ namespace IoTSharp.Data.Sqlite.Migrations
{
b.HasOne("IoTSharp.Data.Produce", "Owner")
.WithMany("DefaultAttributes")
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("OwnerId");
b.Navigation("Owner");
});
......
......@@ -36,8 +36,7 @@ namespace IoTSharp.Data
modelBuilder.Entity<Device>().HasOne(c => c.DeviceIdentity).WithOne(c => c.Device).HasForeignKey<DeviceIdentity>(c => c.DeviceId);
modelBuilder.Entity<Device>().HasDiscriminator<DeviceType>(nameof(Data.Device.DeviceType)).HasValue<Gateway>(DeviceType.Gateway).HasValue<Device>(DeviceType.Device);
modelBuilder.Entity<Gateway>().HasDiscriminator<DeviceType>(nameof(Data.Device.DeviceType));
modelBuilder.Entity<Produce>().HasMany(c=>c.DefaultAttributes).WithOne(c=>c.Owner).HasForeignKey(c=>c.DeviceId);
;
var builder_options = this.GetService<IDataBaseModelBuilderOptions>();
builder_options.Infrastructure = this;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册