From 9350745eb04a2765f793394b30e1ce5dc24ac86d Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Mon, 15 Feb 2021 19:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9sqlserver=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IoTSharp.Data.SqlServer.csproj | 19 + .../IoTSharpDataBuilderExtensions.cs | 36 + ...215110232_SQLServerFirstSchema.Designer.cs | 775 ++++++++++++++++++ .../20210215110232_SQLServerFirstSchema.cs | 593 ++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 773 +++++++++++++++++ .../MsSqlModelBuilderOptions.cs | 72 ++ IoTSharp.sln | 24 +- IoTSharp/IoTSharp.csproj | 1 + IoTSharp/Startup.cs | 6 + IoTSharp/appsettings.Development.json | 2 - IoTSharp/appsettings.MySql.json | 23 + IoTSharp/appsettings.PostgreSql.json | 24 + IoTSharp/appsettings.SQLServer.json | 23 + tools/ef_mg_add.cmd | 6 +- 14 files changed, 2372 insertions(+), 5 deletions(-) create mode 100644 IoTSharp.Data.SqlServer/IoTSharp.Data.SqlServer.csproj create mode 100644 IoTSharp.Data.SqlServer/IoTSharpDataBuilderExtensions.cs create mode 100644 IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.Designer.cs create mode 100644 IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.cs create mode 100644 IoTSharp.Data.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 IoTSharp.Data.SqlServer/MsSqlModelBuilderOptions.cs create mode 100644 IoTSharp/appsettings.MySql.json create mode 100644 IoTSharp/appsettings.PostgreSql.json create mode 100644 IoTSharp/appsettings.SQLServer.json diff --git a/IoTSharp.Data.SqlServer/IoTSharp.Data.SqlServer.csproj b/IoTSharp.Data.SqlServer/IoTSharp.Data.SqlServer.csproj new file mode 100644 index 00000000..cbe1e87a --- /dev/null +++ b/IoTSharp.Data.SqlServer/IoTSharp.Data.SqlServer.csproj @@ -0,0 +1,19 @@ + + + + net5.0 + + + + + + + + + + + + + + + diff --git a/IoTSharp.Data.SqlServer/IoTSharpDataBuilderExtensions.cs b/IoTSharp.Data.SqlServer/IoTSharpDataBuilderExtensions.cs new file mode 100644 index 00000000..456dee16 --- /dev/null +++ b/IoTSharp.Data.SqlServer/IoTSharpDataBuilderExtensions.cs @@ -0,0 +1,36 @@ + +using EFCore.Sharding; +using IoTSharp.Data; +using IoTSharp.Data.SqlServer; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using System; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class IoTSharpDataBuilderExtensions + { + + + public static void ConfigureSqlServer(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI) + { + services.AddEntityFrameworkSqlServer(); + services.AddSingleton( c=> new MsSqlModelBuilderOptions()); + services.AddDbContextPool(builder => + { + builder.UseSqlServer(connectionString, s => s.MigrationsAssembly("IoTSharp.Data.SqlServer")); + builder.UseInternalServiceProvider(services.BuildServiceProvider()); + } + , poolSize); + checksBuilder.AddSqlServer(connectionString); + healthChecksUI.AddSqlServerStorage(connectionString); + + } + + public static void UseSqlServerToSharding(this IShardingBuilder builder, string connectionString, ExpandByDateMode expandBy) + { + builder.AddDataSource(connectionString, ReadWriteType.Read | ReadWriteType.Write, DatabaseType.SqlServer); + builder.SetDateSharding(nameof(TelemetryData.DateTime), expandBy, DateTime.Now); + } + } +} diff --git a/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.Designer.cs b/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.Designer.cs new file mode 100644 index 00000000..9b4b5bd1 --- /dev/null +++ b/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.Designer.cs @@ -0,0 +1,775 @@ +// +using System; +using IoTSharp.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace IoTSharp.Data.SqlServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210215110232_SQLServerFirstSchema")] + partial class SQLServerFirstSchema + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.3") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("IoTSharp.Data.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ActionData") + .HasColumnType("nvarchar(max)"); + + b.Property("ActionName") + .HasColumnType("nvarchar(max)"); + + b.Property("ActionResult") + .HasColumnType("nvarchar(max)"); + + b.Property("ActiveDateTime") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ObjectID") + .HasColumnType("uniqueidentifier"); + + b.Property("ObjectName") + .HasColumnType("nvarchar(max)"); + + b.Property("ObjectType") + .HasColumnType("int"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("AuditLog"); + }); + + modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AuthToken") + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("AuthorizedKeys"); + }); + + modelBuilder.Entity("IoTSharp.Data.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .HasColumnType("nvarchar(max)"); + + b.Property("Province") + .HasColumnType("nvarchar(max)"); + + b.Property("Street") + .HasColumnType("nvarchar(max)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.ToTable("Customer"); + }); + + modelBuilder.Entity("IoTSharp.Data.DataStorage", b => + { + b.Property("Catalog") + .HasColumnType("int"); + + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("KeyName") + .HasColumnType("nvarchar(450)"); + + b.Property("DataSide") + .HasColumnType("int"); + + b.Property("DateTime") + .HasColumnType("datetime2"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("Value_Binary") + .HasColumnType("varbinary(max)"); + + b.Property("Value_Boolean") + .HasColumnType("bit"); + + b.Property("Value_DateTime") + .HasColumnType("datetime2"); + + b.Property("Value_Double") + .HasColumnType("float"); + + b.Property("Value_Json") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_Long") + .HasColumnType("bigint"); + + b.Property("Value_String") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_XML") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Catalog", "DeviceId", "KeyName"); + + b.HasIndex("Catalog"); + + b.HasIndex("Catalog", "DeviceId"); + + b.ToTable("DataStorage"); + + b.HasDiscriminator("Catalog").HasValue(0); + }); + + modelBuilder.Entity("IoTSharp.Data.Device", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorizedKeyId") + .HasColumnType("uniqueidentifier"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("DeviceType") + .HasColumnType("int"); + + b.Property("LastActive") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Online") + .HasColumnType("bit"); + + b.Property("OwnerId") + .HasColumnType("uniqueidentifier"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("Timeout") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AuthorizedKeyId"); + + b.HasIndex("CustomerId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("TenantId"); + + b.ToTable("Device"); + + b.HasDiscriminator("DeviceType").HasValue(0); + }); + + modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("IdentityId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdentityType") + .HasColumnType("int"); + + b.Property("IdentityValue") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.ToTable("DeviceIdentities"); + }); + + modelBuilder.Entity("IoTSharp.Data.Relationship", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("IdentityUserId") + .HasColumnType("nvarchar(450)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("IdentityUserId"); + + b.HasIndex("TenantId"); + + b.ToTable("Relationship"); + }); + + modelBuilder.Entity("IoTSharp.Data.TelemetryData", b => + { + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("KeyName") + .HasColumnType("nvarchar(450)"); + + b.Property("DateTime") + .HasColumnType("datetime2"); + + b.Property("DataSide") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("Value_Binary") + .HasColumnType("varbinary(max)"); + + b.Property("Value_Boolean") + .HasColumnType("bit"); + + b.Property("Value_DateTime") + .HasColumnType("datetime2"); + + b.Property("Value_Double") + .HasColumnType("float"); + + b.Property("Value_Json") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_Long") + .HasColumnType("bigint"); + + b.Property("Value_String") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_XML") + .HasColumnType("nvarchar(max)"); + + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("EMail") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .HasColumnType("nvarchar(max)"); + + b.Property("Province") + .HasColumnType("nvarchar(max)"); + + b.Property("Street") + .HasColumnType("nvarchar(max)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Tenant"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + 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", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", 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", 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 + } + } +} diff --git a/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.cs b/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.cs new file mode 100644 index 00000000..9374f6f7 --- /dev/null +++ b/IoTSharp.Data.SqlServer/Migrations/20210215110232_SQLServerFirstSchema.cs @@ -0,0 +1,593 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace IoTSharp.Data.SqlServer.Migrations +{ + public partial class SQLServerFirstSchema : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + LockoutEnabled = table.Column(type: "bit", nullable: false), + AccessFailedCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "DataStorage", + columns: table => new + { + Catalog = table.Column(type: "int", nullable: false), + DeviceId = table.Column(type: "uniqueidentifier", nullable: false), + KeyName = table.Column(type: "nvarchar(450)", nullable: false), + DateTime = table.Column(type: "datetime2", nullable: false), + DataSide = table.Column(type: "int", nullable: false), + Type = table.Column(type: "int", nullable: false), + Value_Boolean = table.Column(type: "bit", nullable: false), + Value_String = table.Column(type: "nvarchar(max)", nullable: true), + Value_Long = table.Column(type: "bigint", nullable: false), + Value_DateTime = table.Column(type: "datetime2", nullable: false), + Value_Double = table.Column(type: "float", nullable: false), + Value_Json = table.Column(type: "nvarchar(max)", nullable: true), + Value_XML = table.Column(type: "nvarchar(max)", nullable: true), + Value_Binary = table.Column(type: "varbinary(max)", 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(type: "datetime2", nullable: false), + DeviceId = table.Column(type: "uniqueidentifier", nullable: false), + KeyName = table.Column(type: "nvarchar(450)", nullable: false), + DataSide = table.Column(type: "int", nullable: false), + Type = table.Column(type: "int", nullable: false), + Value_Boolean = table.Column(type: "bit", nullable: false), + Value_String = table.Column(type: "nvarchar(max)", nullable: true), + Value_Long = table.Column(type: "bigint", nullable: false), + Value_DateTime = table.Column(type: "datetime2", nullable: false), + Value_Double = table.Column(type: "float", nullable: false), + Value_Json = table.Column(type: "nvarchar(max)", nullable: true), + Value_XML = table.Column(type: "nvarchar(max)", nullable: true), + Value_Binary = table.Column(type: "varbinary(max)", 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(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + EMail = table.Column(type: "nvarchar(max)", nullable: true), + Phone = table.Column(type: "nvarchar(max)", nullable: true), + Country = table.Column(type: "nvarchar(max)", nullable: true), + Province = table.Column(type: "nvarchar(max)", nullable: true), + City = table.Column(type: "nvarchar(max)", nullable: true), + Street = table.Column(type: "nvarchar(max)", nullable: true), + Address = table.Column(type: "nvarchar(max)", nullable: true), + ZipCode = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tenant", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", 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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", 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(type: "nvarchar(450)", nullable: false), + ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(type: "nvarchar(450)", 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(type: "nvarchar(450)", nullable: false), + RoleId = table.Column(type: "nvarchar(450)", 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(type: "nvarchar(450)", nullable: false), + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(450)", nullable: false), + Value = table.Column(type: "nvarchar(max)", 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(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + Email = table.Column(type: "nvarchar(max)", nullable: true), + Phone = table.Column(type: "nvarchar(max)", nullable: true), + Country = table.Column(type: "nvarchar(max)", nullable: true), + Province = table.Column(type: "nvarchar(max)", nullable: true), + City = table.Column(type: "nvarchar(max)", nullable: true), + Street = table.Column(type: "nvarchar(max)", nullable: true), + Address = table.Column(type: "nvarchar(max)", nullable: true), + ZipCode = table.Column(type: "int", nullable: false), + TenantId = table.Column(type: "uniqueidentifier", 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(type: "uniqueidentifier", nullable: false), + TenantId = table.Column(type: "uniqueidentifier", nullable: true), + CustomerId = table.Column(type: "uniqueidentifier", nullable: true), + UserId = table.Column(type: "nvarchar(max)", nullable: true), + UserName = table.Column(type: "nvarchar(max)", nullable: true), + ObjectID = table.Column(type: "uniqueidentifier", nullable: false), + ObjectName = table.Column(type: "nvarchar(max)", nullable: true), + ObjectType = table.Column(type: "int", nullable: false), + ActionName = table.Column(type: "nvarchar(max)", nullable: true), + ActionData = table.Column(type: "nvarchar(max)", nullable: true), + ActionResult = table.Column(type: "nvarchar(max)", nullable: true), + ActiveDateTime = table.Column(type: "datetime2", 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(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + AuthToken = table.Column(type: "nvarchar(max)", nullable: true), + TenantId = table.Column(type: "uniqueidentifier", nullable: true), + CustomerId = table.Column(type: "uniqueidentifier", 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(type: "uniqueidentifier", nullable: false), + IdentityUserId = table.Column(type: "nvarchar(450)", nullable: true), + TenantId = table.Column(type: "uniqueidentifier", nullable: true), + CustomerId = table.Column(type: "uniqueidentifier", 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(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + DeviceType = table.Column(type: "int", nullable: false), + Online = table.Column(type: "bit", nullable: false), + LastActive = table.Column(type: "datetime2", nullable: false), + Timeout = table.Column(type: "int", nullable: false), + OwnerId = table.Column(type: "uniqueidentifier", nullable: true), + TenantId = table.Column(type: "uniqueidentifier", nullable: true), + CustomerId = table.Column(type: "uniqueidentifier", nullable: true), + AuthorizedKeyId = table.Column(type: "uniqueidentifier", 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(type: "uniqueidentifier", nullable: false), + IdentityType = table.Column(type: "int", nullable: false), + IdentityId = table.Column(type: "nvarchar(max)", nullable: false), + IdentityValue = table.Column(type: "nvarchar(max)", nullable: true), + DeviceId = table.Column(type: "uniqueidentifier", 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, + filter: "[NormalizedName] IS NOT NULL"); + + 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, + filter: "[NormalizedUserName] IS NOT NULL"); + + 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"); + } + } +} diff --git a/IoTSharp.Data.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs b/IoTSharp.Data.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..ae99a5b3 --- /dev/null +++ b/IoTSharp.Data.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,773 @@ +// +using System; +using IoTSharp.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace IoTSharp.Data.SqlServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.3") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("IoTSharp.Data.AuditLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ActionData") + .HasColumnType("nvarchar(max)"); + + b.Property("ActionName") + .HasColumnType("nvarchar(max)"); + + b.Property("ActionResult") + .HasColumnType("nvarchar(max)"); + + b.Property("ActiveDateTime") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("ObjectID") + .HasColumnType("uniqueidentifier"); + + b.Property("ObjectName") + .HasColumnType("nvarchar(max)"); + + b.Property("ObjectType") + .HasColumnType("int"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("AuditLog"); + }); + + modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AuthToken") + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("AuthorizedKeys"); + }); + + modelBuilder.Entity("IoTSharp.Data.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .HasColumnType("nvarchar(max)"); + + b.Property("Province") + .HasColumnType("nvarchar(max)"); + + b.Property("Street") + .HasColumnType("nvarchar(max)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.ToTable("Customer"); + }); + + modelBuilder.Entity("IoTSharp.Data.DataStorage", b => + { + b.Property("Catalog") + .HasColumnType("int"); + + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("KeyName") + .HasColumnType("nvarchar(450)"); + + b.Property("DataSide") + .HasColumnType("int"); + + b.Property("DateTime") + .HasColumnType("datetime2"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("Value_Binary") + .HasColumnType("varbinary(max)"); + + b.Property("Value_Boolean") + .HasColumnType("bit"); + + b.Property("Value_DateTime") + .HasColumnType("datetime2"); + + b.Property("Value_Double") + .HasColumnType("float"); + + b.Property("Value_Json") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_Long") + .HasColumnType("bigint"); + + b.Property("Value_String") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_XML") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Catalog", "DeviceId", "KeyName"); + + b.HasIndex("Catalog"); + + b.HasIndex("Catalog", "DeviceId"); + + b.ToTable("DataStorage"); + + b.HasDiscriminator("Catalog").HasValue(0); + }); + + modelBuilder.Entity("IoTSharp.Data.Device", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorizedKeyId") + .HasColumnType("uniqueidentifier"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("DeviceType") + .HasColumnType("int"); + + b.Property("LastActive") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Online") + .HasColumnType("bit"); + + b.Property("OwnerId") + .HasColumnType("uniqueidentifier"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("Timeout") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AuthorizedKeyId"); + + b.HasIndex("CustomerId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("TenantId"); + + b.ToTable("Device"); + + b.HasDiscriminator("DeviceType").HasValue(0); + }); + + modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("IdentityId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdentityType") + .HasColumnType("int"); + + b.Property("IdentityValue") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.ToTable("DeviceIdentities"); + }); + + modelBuilder.Entity("IoTSharp.Data.Relationship", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CustomerId") + .HasColumnType("uniqueidentifier"); + + b.Property("IdentityUserId") + .HasColumnType("nvarchar(450)"); + + b.Property("TenantId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("IdentityUserId"); + + b.HasIndex("TenantId"); + + b.ToTable("Relationship"); + }); + + modelBuilder.Entity("IoTSharp.Data.TelemetryData", b => + { + b.Property("DeviceId") + .HasColumnType("uniqueidentifier"); + + b.Property("KeyName") + .HasColumnType("nvarchar(450)"); + + b.Property("DateTime") + .HasColumnType("datetime2"); + + b.Property("DataSide") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("Value_Binary") + .HasColumnType("varbinary(max)"); + + b.Property("Value_Boolean") + .HasColumnType("bit"); + + b.Property("Value_DateTime") + .HasColumnType("datetime2"); + + b.Property("Value_Double") + .HasColumnType("float"); + + b.Property("Value_Json") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_Long") + .HasColumnType("bigint"); + + b.Property("Value_String") + .HasColumnType("nvarchar(max)"); + + b.Property("Value_XML") + .HasColumnType("nvarchar(max)"); + + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .HasColumnType("nvarchar(max)"); + + b.Property("EMail") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .HasColumnType("nvarchar(max)"); + + b.Property("Province") + .HasColumnType("nvarchar(max)"); + + b.Property("Street") + .HasColumnType("nvarchar(max)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Tenant"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + 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", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", 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", 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 + } + } +} diff --git a/IoTSharp.Data.SqlServer/MsSqlModelBuilderOptions.cs b/IoTSharp.Data.SqlServer/MsSqlModelBuilderOptions.cs new file mode 100644 index 00000000..40ec5744 --- /dev/null +++ b/IoTSharp.Data.SqlServer/MsSqlModelBuilderOptions.cs @@ -0,0 +1,72 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using System; + +namespace IoTSharp.Data.SqlServer +{ + public class MsSqlModelBuilderOptions : IDataBaseModelBuilderOptions + { + public MsSqlModelBuilderOptions() + { + } + + public IInfrastructure Infrastructure { get; set; } + + public void OnModelCreating(ModelBuilder modelBuilder) + { + //modelBuilder.Entity() + //.Property(b => b.DateTime) + //.HasColumnType("timestamp with time zone"); + //modelBuilder.Entity() + //.Property(b => b.Value_DateTime) + //.HasColumnType("timestamp with time zone"); + + //modelBuilder.Entity() + //.Property(b => b.DateTime) + //.HasColumnType("timestamp with time zone"); + + //modelBuilder.Entity() + //.Property(b => b.Value_DateTime) + //.HasColumnType("timestamp with time zone"); + + //modelBuilder.Entity() + //.Property(b => b.DateTime) + //.HasColumnType("timestamp with time zone"); + //modelBuilder.Entity() + //.Property(b => b.Value_DateTime) + //.HasColumnType("timestamp with time zone"); + + //modelBuilder.Entity() + //.Property(b => b.Value_Json) + //.HasColumnType("jsonb"); + + //modelBuilder.Entity() + //.Property(b => b.Value_XML) + //.HasColumnType("xml"); + + //modelBuilder.Entity() + //.Property(b => b.Value_Json) + //.HasColumnType("jsonb"); + + //modelBuilder.Entity() + //.Property(b => b.Value_XML) + //.HasColumnType("xml"); + + //modelBuilder.Entity() + //.Property(b => b.Value_Json) + //.HasColumnType("jsonb"); + + //modelBuilder.Entity() + //.Property(b => b.Value_XML) + //.HasColumnType("xml"); + + //modelBuilder.Entity() + //.Property(b => b.ActionData) + //.HasColumnType("jsonb"); + + //modelBuilder.Entity() + //.Property(b => b.ActionResult) + //.HasColumnType("jsonb"); + } + } +} \ No newline at end of file diff --git a/IoTSharp.sln b/IoTSharp.sln index c46924a2..fd2b480a 100644 --- a/IoTSharp.sln +++ b/IoTSharp.sln @@ -47,7 +47,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.PostgreSQL", EndProject 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}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.MySQL", "IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj", "{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.SqlServer", "IoTSharp.Data.SqlServer\IoTSharp.Data.SqlServer.csproj", "{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -298,6 +300,26 @@ Global {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 + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM.ActiveCfg = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM.Build.0 = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM64.Build.0 = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x64.ActiveCfg = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x64.Build.0 = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x86.ActiveCfg = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x86.Build.0 = Debug|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|Any CPU.Build.0 = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM.ActiveCfg = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM.Build.0 = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM64.ActiveCfg = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM64.Build.0 = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x64.ActiveCfg = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x64.Build.0 = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x86.ActiveCfg = Release|Any CPU + {1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IoTSharp/IoTSharp.csproj b/IoTSharp/IoTSharp.csproj index 024d2828..0cc16376 100644 --- a/IoTSharp/IoTSharp.csproj +++ b/IoTSharp/IoTSharp.csproj @@ -140,6 +140,7 @@ + \ No newline at end of file diff --git a/IoTSharp/Startup.cs b/IoTSharp/Startup.cs index ea500706..0addaf4b 100644 --- a/IoTSharp/Startup.cs +++ b/IoTSharp/Startup.cs @@ -95,6 +95,9 @@ namespace IoTSharp case DataBaseType.MySql: services.ConfigureMySql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI); break; + case DataBaseType.SqlServer: + services.ConfigureSqlServer(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI); + break; case DataBaseType.PostgreSql: default: services.ConfigureNpgsql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI); @@ -200,6 +203,9 @@ namespace IoTSharp case DataBaseType.MySql: config.UseMySqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode); break; + case DataBaseType.SqlServer: + config.UseSqlServerToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode); + break; case DataBaseType.PostgreSql: default: config.UseNpgsqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode); diff --git a/IoTSharp/appsettings.Development.json b/IoTSharp/appsettings.Development.json index d9ce7af6..5e224c3c 100644 --- a/IoTSharp/appsettings.Development.json +++ b/IoTSharp/appsettings.Development.json @@ -8,12 +8,10 @@ }, "DataBase": "MySql", "ConnectionStrings": { - //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" - //"TelemetryStorage": "http://localhost:8086/?org=iotsharp&bucket=iotsharp-bucket&token=iotsharp-token&&latest=-72h" }, "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", "JwtExpireHours": 24, diff --git a/IoTSharp/appsettings.MySql.json b/IoTSharp/appsettings.MySql.json new file mode 100644 index 00000000..f01a5f6f --- /dev/null +++ b/IoTSharp/appsettings.MySql.json @@ -0,0 +1,23 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "DataBase": "MySql", + "ConnectionStrings": { + "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" + }, + "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", + "JwtExpireHours": 24, + "JwtIssuer": "IoTSharp.Net", + "JwtAudience": "IoTSharp.Net", + "EventBusStore": "InMemory", + "EventBusMQ": "InMemory", + "TelemetryStorage": "Sharding" +} \ No newline at end of file diff --git a/IoTSharp/appsettings.PostgreSql.json b/IoTSharp/appsettings.PostgreSql.json new file mode 100644 index 00000000..5662524a --- /dev/null +++ b/IoTSharp/appsettings.PostgreSql.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "DataBase": "PostgreSql", + "ConnectionStrings": { + "IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;", + "EventBusStore": "mongodb://root:kissme@mongodb:27017", + "TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030", + "EventBusMQ": "amqp://root:kissme@rabbitmq:5672" + }, + "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", + "JwtExpireHours": 24, + "JwtIssuer": "IoTSharp.Net", + "JwtAudience": "IoTSharp.Net", + "EventBusStore": "InMemory", + "EventBusMQ": "InMemory", + "TelemetryStorage": "Sharding" + +} \ No newline at end of file diff --git a/IoTSharp/appsettings.SQLServer.json b/IoTSharp/appsettings.SQLServer.json new file mode 100644 index 00000000..9e790bfc --- /dev/null +++ b/IoTSharp/appsettings.SQLServer.json @@ -0,0 +1,23 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + }, + "DataBase": "SQLServer", + "ConnectionStrings": { + "IoTSharp": "Data Source=.;Initial Catalog=IoTSharp;Persist Security Info=True;User ID=sa;Password=future", + "EventBusStore": "mongodb://root:kissme@mongodb:27017", + "TelemetryStorage": "Data Source=.;Initial Catalog=IoTSharp;Persist Security Info=True;User ID=sa;Password=future", + "EventBusMQ": "amqp://root:kissme@rabbitmq:5672" + }, + "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", + "JwtExpireHours": 24, + "JwtIssuer": "IoTSharp.Net", + "JwtAudience": "IoTSharp.Net", + "EventBusStore": "InMemory", + "EventBusMQ": "InMemory", + "TelemetryStorage": "Sharding" +} \ No newline at end of file diff --git a/tools/ef_mg_add.cmd b/tools/ef_mg_add.cmd index 1f561dbf..813405ca 100644 --- a/tools/ef_mg_add.cmd +++ b/tools/ef_mg_add.cmd @@ -1,2 +1,4 @@ - cd IoTSharp.Data.PostgreSQL -dotnet ef migrations add %1 --context IoTSharp.Data.ApplicationDbContext --startup-project ..\IoTSharp\IoTSharp.csproj \ No newline at end of file +echo Add a migration name is %2 to IoTSharp.Data.%1 +cd IoTSharp.Data.%1 +set ASPNETCORE_ENVIRONMENT=%1 +dotnet ef migrations add %2 --context IoTSharp.Data.ApplicationDbContext --startup-project ..\IoTSharp\IoTSharp.csproj --project ..\IoTSharp.Data.%1\IoTSharp.Data.%1.csproj \ No newline at end of file -- GitLab