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

add to IoTSharp.Data.MySQL

上级 baaff3dc
......@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="AntDesign" Version="0.6.0" />
<PackageReference Include="AntDesign.Charts" Version="0.2.0-*" />
<PackageReference Include="AntDesign.Pro.Layout" Version="0.1.0-nightly-201127071242" />
<PackageReference Include="AntDesign.Pro.Layout" Version="0.1.0-nightly-210129055145" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.3" />
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.MySql.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="5.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.0-alpha.2" />
<PackageReference Include="EFCore.Sharding.MySql" Version="5.0.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>

using EFCore.Sharding;
using IoTSharp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Microsoft.Extensions.DependencyInjection
{
public static class IoTSharpDataBuilderExtensions
{
public static void ConfigureMySql(this IServiceCollection services, string connectionString,int poolSize , IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
{
services.AddDbContextPool<ApplicationDbContext>(builder =>
{
builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), s => s.MigrationsAssembly("IoTSharp.Data.MySQL"));
}
, poolSize );
checksBuilder.AddMySql(connectionString, "IoTSharp.Data.MySQL");
healthChecksUI.AddMySqlStorage(connectionString);
}
public static void UseMySqlToSharding(this IShardingBuilder builder, string connectionString, ExpandByDateMode expandBy)
{
builder.AddDataSource(connectionString, ReadWriteType.Read | ReadWriteType.Write, DatabaseType.MySql);
builder.SetDateSharding<TelemetryData>(nameof(TelemetryData.DateTime), expandBy, DateTime.Now);
}
}
}
// <auto-generated />
using System;
using IoTSharp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTSharp.Data.MySQL.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20210214185821_MySQLFirstSchema")]
partial class MySQLFirstSchema
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 64)
.HasAnnotation("ProductVersion", "5.0.3");
modelBuilder.Entity("IoTSharp.Data.AuditLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("ActionData")
.HasColumnType("jsonb");
b.Property<string>("ActionName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ActionResult")
.HasColumnType("jsonb");
b.Property<DateTime>("ActiveDateTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<Guid>("ObjectID")
.HasColumnType("char(36)");
b.Property<string>("ObjectName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("ObjectType")
.HasColumnType("int");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("AuditLog");
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("AuthToken")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("AuthorizedKeys");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Address")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("City")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Country")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Email")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Phone")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Province")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Street")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId");
b.ToTable("Customer");
});
modelBuilder.Entity("IoTSharp.Data.DataStorage", b =>
{
b.Property<int>("Catalog")
.HasColumnType("int");
b.Property<Guid>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("KeyName")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<int>("DataSide")
.HasColumnType("int");
b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<byte[]>("Value_Binary")
.HasColumnType("longblob");
b.Property<bool>("Value_Boolean")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<double>("Value_Double")
.HasColumnType("double");
b.Property<string>("Value_Json")
.HasColumnType("jsonb");
b.Property<long>("Value_Long")
.HasColumnType("bigint");
b.Property<string>("Value_String")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Value_XML")
.HasColumnType("xml");
b.HasKey("Catalog", "DeviceId", "KeyName");
b.HasIndex("Catalog");
b.HasIndex("Catalog", "DeviceId");
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("AuthorizedKeyId")
.HasColumnType("char(36)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<int>("DeviceType")
.HasColumnType("int");
b.Property<DateTime>("LastActive")
.HasColumnType("datetime(6)");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("Online")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("OwnerId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Timeout")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AuthorizedKeyId");
b.HasIndex("CustomerId");
b.HasIndex("OwnerId");
b.HasIndex("TenantId");
b.ToTable("Device");
b.HasDiscriminator<int>("DeviceType").HasValue(0);
});
modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("IdentityId")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("IdentityType")
.HasColumnType("int");
b.Property<string>("IdentityValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("DeviceId");
b.ToTable("DeviceIdentities");
});
modelBuilder.Entity("IoTSharp.Data.Relationship", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<string>("IdentityUserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("IdentityUserId");
b.HasIndex("TenantId");
b.ToTable("Relationship");
});
modelBuilder.Entity("IoTSharp.Data.TelemetryData", b =>
{
b.Property<Guid>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("KeyName")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<int>("DataSide")
.HasColumnType("int");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<byte[]>("Value_Binary")
.HasColumnType("longblob");
b.Property<bool>("Value_Boolean")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<double>("Value_Double")
.HasColumnType("double");
b.Property<string>("Value_Json")
.HasColumnType("jsonb");
b.Property<long>("Value_Long")
.HasColumnType("bigint");
b.Property<string>("Value_String")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Value_XML")
.HasColumnType("xml");
b.HasKey("DeviceId", "KeyName", "DateTime");
b.HasIndex("DeviceId");
b.HasIndex("KeyName");
b.HasIndex("DeviceId", "KeyName");
b.HasIndex("DeviceId", "KeyName", "DateTime");
b.ToTable("TelemetryData");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Address")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("City")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Country")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("EMail")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Phone")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Province")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Street")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ClaimValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<bool>("EmailConfirmed")
.HasColumnType("tinyint(1)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("tinyint(1)");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetime(6)");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("PasswordHash")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("PhoneNumber")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("tinyint(1)");
b.Property<string>("SecurityStamp")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ClaimValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ProviderKey")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ProviderDisplayName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("RoleId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("Value")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("IoTSharp.Data.AttributeLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Data.TelemetryLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.AuditLog", 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.AuthorizedKey", 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.Customer", b =>
{
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Customers")
.HasForeignKey("TenantId");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
{
b.HasOne("IoTSharp.Data.AuthorizedKey", null)
.WithMany("Devices")
.HasForeignKey("AuthorizedKeyId");
b.HasOne("IoTSharp.Data.Customer", "Customer")
.WithMany("Devices")
.HasForeignKey("CustomerId");
b.HasOne("IoTSharp.Data.Gateway", "Owner")
.WithMany("Children")
.HasForeignKey("OwnerId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Devices")
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Owner");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b =>
{
b.HasOne("IoTSharp.Data.Device", "Device")
.WithMany()
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTSharp.Data.Relationship", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
.WithMany()
.HasForeignKey("CustomerId");
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "IdentityUser")
.WithMany()
.HasForeignKey("IdentityUserId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("IdentityUser");
b.Navigation("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Navigation("Customers");
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.Navigation("Children");
});
#pragma warning restore 612, 618
}
}
}
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IoTSharp.Data.MySQL.Migrations
{
public partial class MySQLFirstSchema : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
Name = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
UserName = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "varchar(256) CHARACTER SET utf8mb4", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "tinyint(1)", nullable: false),
PasswordHash = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
SecurityStamp = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
PhoneNumber = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "tinyint(1)", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "datetime(6)", nullable: true),
LockoutEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
AccessFailedCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DataStorage",
columns: table => new
{
Catalog = table.Column<int>(type: "int", nullable: false),
DeviceId = table.Column<Guid>(type: "char(36)", nullable: false),
KeyName = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
DateTime = table.Column<DateTime>(type: "timestamp with time zone(6)", nullable: false),
DataSide = table.Column<int>(type: "int", nullable: false),
Type = table.Column<int>(type: "int", nullable: false),
Value_Boolean = table.Column<bool>(type: "tinyint(1)", nullable: false),
Value_String = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Value_Long = table.Column<long>(type: "bigint", nullable: false),
Value_DateTime = table.Column<DateTime>(type: "timestamp with time zone(6)", nullable: false),
Value_Double = table.Column<double>(type: "double", nullable: false),
Value_Json = table.Column<string>(type: "jsonb", nullable: true),
Value_XML = table.Column<string>(type: "xml", nullable: true),
Value_Binary = table.Column<byte[]>(type: "longblob", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DataStorage", x => new { x.Catalog, x.DeviceId, x.KeyName });
});
migrationBuilder.CreateTable(
name: "TelemetryData",
columns: table => new
{
DateTime = table.Column<DateTime>(type: "timestamp with time zone(6)", nullable: false),
DeviceId = table.Column<Guid>(type: "char(36)", nullable: false),
KeyName = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
DataSide = table.Column<int>(type: "int", nullable: false),
Type = table.Column<int>(type: "int", nullable: false),
Value_Boolean = table.Column<bool>(type: "tinyint(1)", nullable: false),
Value_String = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Value_Long = table.Column<long>(type: "bigint", nullable: false),
Value_DateTime = table.Column<DateTime>(type: "timestamp with time zone(6)", nullable: false),
Value_Double = table.Column<double>(type: "double", nullable: false),
Value_Json = table.Column<string>(type: "jsonb", nullable: true),
Value_XML = table.Column<string>(type: "xml", nullable: true),
Value_Binary = table.Column<byte[]>(type: "longblob", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TelemetryData", x => new { x.DeviceId, x.KeyName, x.DateTime });
});
migrationBuilder.CreateTable(
name: "Tenant",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
Name = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
EMail = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Phone = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Country = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Province = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
City = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Street = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Address = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ZipCode = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tenant", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
RoleId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
ClaimType = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ClaimValue = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
UserId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
ClaimType = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ClaimValue = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
ProviderKey = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
ProviderDisplayName = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
UserId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
RoleId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
LoginProvider = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
Name = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: false),
Value = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Customer",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
Name = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Email = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Phone = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Country = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Province = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
City = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Street = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
Address = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ZipCode = table.Column<int>(type: "int", nullable: false),
TenantId = table.Column<Guid>(type: "char(36)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Customer", x => x.Id);
table.ForeignKey(
name: "FK_Customer_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AuditLog",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
TenantId = table.Column<Guid>(type: "char(36)", nullable: true),
CustomerId = table.Column<Guid>(type: "char(36)", nullable: true),
UserId = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
UserName = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ObjectID = table.Column<Guid>(type: "char(36)", nullable: false),
ObjectName = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ObjectType = table.Column<int>(type: "int", nullable: false),
ActionName = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
ActionData = table.Column<string>(type: "jsonb", nullable: true),
ActionResult = table.Column<string>(type: "jsonb", nullable: true),
ActiveDateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AuditLog", x => x.Id);
table.ForeignKey(
name: "FK_AuditLog_Customer_CustomerId",
column: x => x.CustomerId,
principalTable: "Customer",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_AuditLog_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AuthorizedKeys",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
Name = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
AuthToken = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
TenantId = table.Column<Guid>(type: "char(36)", nullable: true),
CustomerId = table.Column<Guid>(type: "char(36)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AuthorizedKeys", x => x.Id);
table.ForeignKey(
name: "FK_AuthorizedKeys_Customer_CustomerId",
column: x => x.CustomerId,
principalTable: "Customer",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_AuthorizedKeys_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Relationship",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
IdentityUserId = table.Column<string>(type: "varchar(255) CHARACTER SET utf8mb4", nullable: true),
TenantId = table.Column<Guid>(type: "char(36)", nullable: true),
CustomerId = table.Column<Guid>(type: "char(36)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Relationship", x => x.Id);
table.ForeignKey(
name: "FK_Relationship_AspNetUsers_IdentityUserId",
column: x => x.IdentityUserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Relationship_Customer_CustomerId",
column: x => x.CustomerId,
principalTable: "Customer",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Relationship_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Device",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
Name = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
DeviceType = table.Column<int>(type: "int", nullable: false),
Online = table.Column<bool>(type: "tinyint(1)", nullable: false),
LastActive = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Timeout = table.Column<int>(type: "int", nullable: false),
OwnerId = table.Column<Guid>(type: "char(36)", nullable: true),
TenantId = table.Column<Guid>(type: "char(36)", nullable: true),
CustomerId = table.Column<Guid>(type: "char(36)", nullable: true),
AuthorizedKeyId = table.Column<Guid>(type: "char(36)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Device", x => x.Id);
table.ForeignKey(
name: "FK_Device_AuthorizedKeys_AuthorizedKeyId",
column: x => x.AuthorizedKeyId,
principalTable: "AuthorizedKeys",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Device_Customer_CustomerId",
column: x => x.CustomerId,
principalTable: "Customer",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Device_Device_OwnerId",
column: x => x.OwnerId,
principalTable: "Device",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Device_Tenant_TenantId",
column: x => x.TenantId,
principalTable: "Tenant",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DeviceIdentities",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
IdentityType = table.Column<int>(type: "int", nullable: false),
IdentityId = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: false),
IdentityValue = table.Column<string>(type: "longtext CHARACTER SET utf8mb4", nullable: true),
DeviceId = table.Column<Guid>(type: "char(36)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceIdentities", x => x.Id);
table.ForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
column: x => x.DeviceId,
principalTable: "Device",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_RoleId",
table: "AspNetUserRoles",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AuditLog_CustomerId",
table: "AuditLog",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_AuditLog_TenantId",
table: "AuditLog",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_AuthorizedKeys_CustomerId",
table: "AuthorizedKeys",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_AuthorizedKeys_TenantId",
table: "AuthorizedKeys",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_Customer_TenantId",
table: "Customer",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_DataStorage_Catalog",
table: "DataStorage",
column: "Catalog");
migrationBuilder.CreateIndex(
name: "IX_DataStorage_Catalog_DeviceId",
table: "DataStorage",
columns: new[] { "Catalog", "DeviceId" });
migrationBuilder.CreateIndex(
name: "IX_Device_AuthorizedKeyId",
table: "Device",
column: "AuthorizedKeyId");
migrationBuilder.CreateIndex(
name: "IX_Device_CustomerId",
table: "Device",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_Device_OwnerId",
table: "Device",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_Device_TenantId",
table: "Device",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_DeviceIdentities_DeviceId",
table: "DeviceIdentities",
column: "DeviceId");
migrationBuilder.CreateIndex(
name: "IX_Relationship_CustomerId",
table: "Relationship",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_Relationship_IdentityUserId",
table: "Relationship",
column: "IdentityUserId");
migrationBuilder.CreateIndex(
name: "IX_Relationship_TenantId",
table: "Relationship",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_TelemetryData_DeviceId",
table: "TelemetryData",
column: "DeviceId");
migrationBuilder.CreateIndex(
name: "IX_TelemetryData_DeviceId_KeyName",
table: "TelemetryData",
columns: new[] { "DeviceId", "KeyName" });
migrationBuilder.CreateIndex(
name: "IX_TelemetryData_DeviceId_KeyName_DateTime",
table: "TelemetryData",
columns: new[] { "DeviceId", "KeyName", "DateTime" });
migrationBuilder.CreateIndex(
name: "IX_TelemetryData_KeyName",
table: "TelemetryData",
column: "KeyName");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserRoles");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "AuditLog");
migrationBuilder.DropTable(
name: "DataStorage");
migrationBuilder.DropTable(
name: "DeviceIdentities");
migrationBuilder.DropTable(
name: "Relationship");
migrationBuilder.DropTable(
name: "TelemetryData");
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropTable(
name: "Device");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "AuthorizedKeys");
migrationBuilder.DropTable(
name: "Customer");
migrationBuilder.DropTable(
name: "Tenant");
}
}
}
// <auto-generated />
using System;
using IoTSharp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTSharp.Data.MySQL.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 64)
.HasAnnotation("ProductVersion", "5.0.3");
modelBuilder.Entity("IoTSharp.Data.AuditLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("ActionData")
.HasColumnType("jsonb");
b.Property<string>("ActionName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ActionResult")
.HasColumnType("jsonb");
b.Property<DateTime>("ActiveDateTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<Guid>("ObjectID")
.HasColumnType("char(36)");
b.Property<string>("ObjectName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("ObjectType")
.HasColumnType("int");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("AuditLog");
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("AuthToken")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("TenantId");
b.ToTable("AuthorizedKeys");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Address")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("City")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Country")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Email")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Phone")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Province")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Street")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId");
b.ToTable("Customer");
});
modelBuilder.Entity("IoTSharp.Data.DataStorage", b =>
{
b.Property<int>("Catalog")
.HasColumnType("int");
b.Property<Guid>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("KeyName")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<int>("DataSide")
.HasColumnType("int");
b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<byte[]>("Value_Binary")
.HasColumnType("longblob");
b.Property<bool>("Value_Boolean")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<double>("Value_Double")
.HasColumnType("double");
b.Property<string>("Value_Json")
.HasColumnType("jsonb");
b.Property<long>("Value_Long")
.HasColumnType("bigint");
b.Property<string>("Value_String")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Value_XML")
.HasColumnType("xml");
b.HasKey("Catalog", "DeviceId", "KeyName");
b.HasIndex("Catalog");
b.HasIndex("Catalog", "DeviceId");
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("AuthorizedKeyId")
.HasColumnType("char(36)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<int>("DeviceType")
.HasColumnType("int");
b.Property<DateTime>("LastActive")
.HasColumnType("datetime(6)");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("Online")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("OwnerId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Timeout")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AuthorizedKeyId");
b.HasIndex("CustomerId");
b.HasIndex("OwnerId");
b.HasIndex("TenantId");
b.ToTable("Device");
b.HasDiscriminator<int>("DeviceType").HasValue(0);
});
modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("IdentityId")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("IdentityType")
.HasColumnType("int");
b.Property<string>("IdentityValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("DeviceId");
b.ToTable("DeviceIdentities");
});
modelBuilder.Entity("IoTSharp.Data.Relationship", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("CustomerId")
.HasColumnType("char(36)");
b.Property<string>("IdentityUserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("IdentityUserId");
b.HasIndex("TenantId");
b.ToTable("Relationship");
});
modelBuilder.Entity("IoTSharp.Data.TelemetryData", b =>
{
b.Property<Guid>("DeviceId")
.HasColumnType("char(36)");
b.Property<string>("KeyName")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<int>("DataSide")
.HasColumnType("int");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<byte[]>("Value_Binary")
.HasColumnType("longblob");
b.Property<bool>("Value_Boolean")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("Value_DateTime")
.HasColumnType("timestamp with time zone(6)");
b.Property<double>("Value_Double")
.HasColumnType("double");
b.Property<string>("Value_Json")
.HasColumnType("jsonb");
b.Property<long>("Value_Long")
.HasColumnType("bigint");
b.Property<string>("Value_String")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Value_XML")
.HasColumnType("xml");
b.HasKey("DeviceId", "KeyName", "DateTime");
b.HasIndex("DeviceId");
b.HasIndex("KeyName");
b.HasIndex("DeviceId", "KeyName");
b.HasIndex("DeviceId", "KeyName", "DateTime");
b.ToTable("TelemetryData");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Address")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("City")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Country")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("EMail")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Phone")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Province")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Street")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ClaimValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<bool>("EmailConfirmed")
.HasColumnType("tinyint(1)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("tinyint(1)");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetime(6)");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.Property<string>("PasswordHash")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("PhoneNumber")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("tinyint(1)");
b.Property<string>("SecurityStamp")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("varchar(256) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("ClaimValue")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ProviderKey")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("ProviderDisplayName")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("RoleId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("Name")
.HasColumnType("varchar(255) CHARACTER SET utf8mb4");
b.Property<string>("Value")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens");
});
modelBuilder.Entity("IoTSharp.Data.AttributeLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Data.TelemetryLatest", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.AuditLog", 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.AuthorizedKey", 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.Customer", b =>
{
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Customers")
.HasForeignKey("TenantId");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
{
b.HasOne("IoTSharp.Data.AuthorizedKey", null)
.WithMany("Devices")
.HasForeignKey("AuthorizedKeyId");
b.HasOne("IoTSharp.Data.Customer", "Customer")
.WithMany("Devices")
.HasForeignKey("CustomerId");
b.HasOne("IoTSharp.Data.Gateway", "Owner")
.WithMany("Children")
.HasForeignKey("OwnerId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Devices")
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Owner");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b =>
{
b.HasOne("IoTSharp.Data.Device", "Device")
.WithMany()
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTSharp.Data.Relationship", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
.WithMany()
.HasForeignKey("CustomerId");
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "IdentityUser")
.WithMany()
.HasForeignKey("IdentityUserId");
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("IdentityUser");
b.Navigation("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Navigation("Customers");
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.Navigation("Children");
});
#pragma warning restore 612, 618
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.PostgreSQL.Storage" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="5.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="5.0.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>

using EFCore.Sharding;
using IoTSharp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Microsoft.Extensions.DependencyInjection
{
public static class IoTSharpDataBuilderExtensions
{
public static void ConfigureNpgsql(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
{
services.AddDbContextPool<ApplicationDbContext>(builder =>
{
builder.UseNpgsql(connectionString, s => s.MigrationsAssembly("IoTSharp.Data.PostgreSQL"));
}
, poolSize);
checksBuilder.AddNpgSql(connectionString);
healthChecksUI.AddPostgreSqlStorage(connectionString);
}
public static void UseNpgsqlToSharding(this IShardingBuilder builder, string connectionString, ExpandByDateMode expandBy)
{
builder.AddDataSource(connectionString, ReadWriteType.Read | ReadWriteType.Write, DatabaseType.PostgreSql);
builder.SetDateSharding<TelemetryData>(nameof(TelemetryData.DateTime), expandBy, DateTime.Now);
}
}
}
......@@ -9,6 +9,8 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="EFCore.Sharding" Version="5.0.0.6" />
</ItemGroup>
</Project>
......@@ -43,9 +43,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Sdk.Http", "IoTSha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Sdk.MQTT", "IoTSharp.SDKs\IoTSharp.Sdk.MQTT\IoTSharp.Sdk.MQTT.csproj", "{A2A1191C-32ED-482B-AACE-4091EE518CEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.PostgreSQL", "IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj", "{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.PostgreSQL", "IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj", "{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data", "IoTSharp.Data\IoTSharp.Data.csproj", "{522B2676-EB0E-4191-ACBC-EDC86DD2351D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data", "IoTSharp.Data\IoTSharp.Data.csproj", "{522B2676-EB0E-4191-ACBC-EDC86DD2351D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.MySQL", "IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj", "{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -276,6 +278,26 @@ Global
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x64.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x86.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x86.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|ARM.ActiveCfg = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|ARM.Build.0 = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|ARM64.Build.0 = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|x64.ActiveCfg = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|x64.Build.0 = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|x86.ActiveCfg = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Debug|x86.Build.0 = Debug|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|Any CPU.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|ARM.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|ARM.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|ARM64.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|ARM64.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x64.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x64.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x86.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
using CoAP;
using CoAP.Server;
using DotNetCore.CAP.Dashboard.NodeDiscovery;
using EFCore.Sharding;
using IoTSharp.Data;
using MaiKeBing.CAP;
using MaiKeBing.HostedService.ZeroMQ;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
......
......@@ -40,18 +40,18 @@
<PackageReference Include="AspNetCore.HealthChecks.Kafka" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.MongoDb" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Network" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Redis" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.System" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.PostgreSQL.Storage" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.SQLite.Storage" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Network" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.1" />
<PackageReference Include="CAP.Extensions" Version="1.0.31" />
<PackageReference Include="DotNetCore.CAP" Version="3.1.2" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.1.2" />
......@@ -64,8 +64,7 @@
<PackageReference Include="EasyCaching.InMemory" Version="1.2.0" />
<PackageReference Include="EasyCaching.LiteDB" Version="1.2.0" />
<PackageReference Include="EasyCaching.Redis" Version="1.2.1" />
<PackageReference Include="EFCore.Sharding" Version="5.0.0.6" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="5.0.0.6" />
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
......@@ -91,6 +90,7 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="MQTTnet" Version="3.0.14" />
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.14" />
<PackageReference Include="MQTTnet.AspNetCoreEx" Version="3.0.14" />
<PackageReference Include="MQTTnet.Extensions.Rpc" Version="3.0.14" />
<PackageReference Include="NetMQ" Version="4.0.1.6" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
......@@ -114,7 +114,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="MQTTnet.AspNetCoreEx" Version="3.0.13" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.0.14" />
</ItemGroup>
<ItemGroup>
......@@ -139,6 +138,7 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj" />
<ProjectReference Include="..\IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj" />
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
......
......@@ -72,18 +72,35 @@ namespace IoTSharp
{
Configuration.Bind(setting);
}));
services.AddDbContextPool<ApplicationDbContext>(options =>
var healthChecksUI = services.AddHealthChecksUI(setup =>
{
switch (settings.DataBase)
{
case DataBaseType.PostgreSql:
default:
options.UseNpgsql(Configuration.GetConnectionString("IoTSharp"), s => s.MigrationsAssembly("IoTSharp.Data.PostgreSQL"));
break;
}
setup.SetHeaderText("IoTSharp HealthChecks");
//Maximum history entries by endpoint
setup.MaximumHistoryEntriesPerEndpoint(50);
setup.AddIoTSharpHealthCheckEndpoint();
});
var healthChecks = services.AddHealthChecks()
.AddDiskStorageHealthCheck(dso =>
{
System.IO.DriveInfo.GetDrives()
.Where(d => d.DriveType != System.IO.DriveType.CDRom && d.DriveType != System.IO.DriveType.Ram)
.Select(f => f.Name).Distinct().ToList()
.ForEach(f => dso.AddDrive(f, 1024));
}, name: "Disk Storage");
switch (settings.DataBase)
{
case DataBaseType.MySql:
services.ConfigureMySql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI);
break;
case DataBaseType.PostgreSql:
default:
services.ConfigureNpgsql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI);
break;
}
, poolSize: settings.DbContextPoolSize);
services.AddIdentity<IdentityUser, IdentityRole>()
.AddRoles<IdentityRole>()
.AddRoleManager<RoleManager<IdentityRole>>()
......@@ -128,24 +145,8 @@ namespace IoTSharp
services.AddMqttClient(settings.MqttClient);
services.AddSingleton<RetainedMessageHandler>();
var healthChecks = services.AddHealthChecks()
.AddNpgSql(Configuration.GetConnectionString("IoTSharp"), name: "PostgreSQL")
.AddDiskStorageHealthCheck(dso =>
{
System.IO.DriveInfo.GetDrives()
.Where(d=>d.DriveType != System.IO.DriveType.CDRom && d.DriveType!= System.IO.DriveType.Ram)
.Select(f => f.Name).Distinct().ToList()
.ForEach(f => dso.AddDrive(f, 1024));
}, name: "Disk Storage");
services.AddHealthChecksUI(setup =>
{
setup.SetHeaderText("IoTSharp HealthChecks");
//Maximum history entries by endpoint
setup.MaximumHistoryEntriesPerEndpoint(50);
setup.AddIoTSharpHealthCheckEndpoint();
}).AddPostgreSqlStorage(Configuration.GetConnectionString("IoTSharp"));
services.AddSilkierQuartz(opt =>
{
......@@ -194,8 +195,17 @@ namespace IoTSharp
case TelemetryStorage.Sharding:
services.AddEFCoreSharding(config =>
{
config.AddDataSource(Configuration.GetConnectionString("TelemetryStorage"), ReadWriteType.Read | ReadWriteType.Write, settings.Sharding.DatabaseType);
config.SetDateSharding<TelemetryData>(nameof(TelemetryData.DateTime), settings.Sharding.ExpandByDateMode, DateTime.Now);
switch (settings.DataBase)
{
case DataBaseType.MySql:
config.UseMySqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode);
break;
case DataBaseType.PostgreSql:
default:
config.UseNpgsqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode);
break;
}
});
services.AddSingleton<IStorage, ShardingStorage>();
break;
......
......@@ -6,8 +6,10 @@
"Microsoft": "Information"
}
},
"DataBase": "MySql",
"ConnectionStrings": {
"IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;",
//pgsql "IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;",
"IoTSharp": "server=localhost;user=root;password=kissme;database=IoTSharp",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
......@@ -19,7 +21,7 @@
"JwtAudience": "IoTSharp.Net",
"EventBusStore": "InMemory",
"EventBusMQ": "InMemory",
"TelemetryStorage": "Taos"
"TelemetryStorage": "Sharding"
//"Discovery": {
// "DiscoveryServerHostName": "iotsharp",
// "DiscoveryServerPort": 8500,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册