From fb7f7e187c28efcaaccf83fcd03465292c0cba1a Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Mon, 17 Dec 2018 23:59:35 +0800 Subject: [PATCH] dotnet ef migrations add AddBaseTable --- IoTSharp.Hub/Data/ApplicationDbContext.cs | 3 +- .../20181217155621_AddBaseTable.Designer.cs | 436 ++++++++++++++++++ .../Migrations/20181217155621_AddBaseTable.cs | 268 +++++++++++ .../ApplicationDbContextModelSnapshot.cs | 223 ++++++++- IoTSharp.Hub/Extensions/IoTSharpExtension.cs | 16 +- IoTSharp.Hub/Startup.cs | 3 +- IoTSharp.Hub/appsettings.Development.json | 6 +- IoTSharp.sln | 6 - healthchecksdb | Bin 0 -> 45056 bytes 9 files changed, 936 insertions(+), 25 deletions(-) create mode 100644 IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.Designer.cs create mode 100644 IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.cs create mode 100644 healthchecksdb diff --git a/IoTSharp.Hub/Data/ApplicationDbContext.cs b/IoTSharp.Hub/Data/ApplicationDbContext.cs index 4cec7dfd..4e7a3012 100644 --- a/IoTSharp.Hub/Data/ApplicationDbContext.cs +++ b/IoTSharp.Hub/Data/ApplicationDbContext.cs @@ -30,7 +30,8 @@ namespace IoTSharp.Hub.Data protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity() + base.OnModelCreating(modelBuilder); + modelBuilder.Entity() .HasOne(p => p.Tenant) .WithMany(b => b.Customers); diff --git a/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.Designer.cs b/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.Designer.cs new file mode 100644 index 00000000..eb2da5d8 --- /dev/null +++ b/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.Designer.cs @@ -0,0 +1,436 @@ +// +using System; +using IoTSharp.Hub.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace IoTSharp.Hub.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20181217155621_AddBaseTable")] + partial class AddBaseTable + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("IoTSharp.Hub.Data.ClientSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("ClientSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("City"); + + b.Property("Country"); + + b.Property("Email"); + + b.Property("Name"); + + b.Property("Phone"); + + b.Property("Province"); + + b.Property("Street"); + + b.Property("TenantId"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.ToTable("Customer"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Device", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CustomerId"); + + b.Property("Name"); + + b.Property("TenantId"); + + b.Property("Type"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("Device"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b => + { + b.Property("UseId") + .ValueGeneratedOnAdd(); + + b.Property("CustomerId"); + + b.Property("TenantId"); + + b.HasKey("UseId"); + + b.ToTable("Relationship"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.ServerSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("ServerSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.SharedSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("SharedSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("City"); + + b.Property("Country"); + + b.Property("EMail"); + + b.Property("Name"); + + b.Property("Phone"); + + b.Property("Province"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("Tenant"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("ProviderKey") + .HasMaxLength(128); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider") + .HasMaxLength(128); + + b.Property("Name") + .HasMaxLength(128); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b => + { + b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant") + .WithMany("Customers") + .HasForeignKey("TenantId"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Device", b => + { + b.HasOne("IoTSharp.Hub.Data.Customer", "Customer") + .WithMany("Devices") + .HasForeignKey("CustomerId"); + + b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant") + .WithMany("Devices") + .HasForeignKey("TenantId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.cs b/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.cs new file mode 100644 index 00000000..1543e4a8 --- /dev/null +++ b/IoTSharp.Hub/Data/Migrations/20181217155621_AddBaseTable.cs @@ -0,0 +1,268 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace IoTSharp.Hub.Data.Migrations +{ + public partial class AddBaseTable : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "UserNameIndex", + table: "AspNetUsers"); + + migrationBuilder.DropIndex( + name: "RoleNameIndex", + table: "AspNetRoles"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "AspNetUserClaims", + nullable: false, + oldClrType: typeof(int)) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "AspNetRoleClaims", + nullable: false, + oldClrType: typeof(int)) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); + + migrationBuilder.CreateTable( + name: "ClientSideAttribute", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + Type = table.Column(nullable: false), + Value_Boolean = table.Column(nullable: false), + Value_String = table.Column(nullable: true), + Value_Long = table.Column(nullable: false), + Value_Double = table.Column(nullable: false), + Value_Json = table.Column(type: "jsonb", nullable: true), + Value_XML = table.Column(type: "xml", nullable: true), + Value_Binary = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ClientSideAttribute", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Relationship", + columns: table => new + { + UseId = table.Column(nullable: false), + CustomerId = table.Column(nullable: false), + TenantId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Relationship", x => x.UseId); + }); + + migrationBuilder.CreateTable( + name: "ServerSideAttribute", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + Type = table.Column(nullable: false), + Value_Boolean = table.Column(nullable: false), + Value_String = table.Column(nullable: true), + Value_Long = table.Column(nullable: false), + Value_Double = table.Column(nullable: false), + Value_Json = table.Column(type: "jsonb", nullable: true), + Value_XML = table.Column(type: "xml", nullable: true), + Value_Binary = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ServerSideAttribute", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SharedSideAttribute", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + Type = table.Column(nullable: false), + Value_Boolean = table.Column(nullable: false), + Value_String = table.Column(nullable: true), + Value_Long = table.Column(nullable: false), + Value_Double = table.Column(nullable: false), + Value_Json = table.Column(type: "jsonb", nullable: true), + Value_XML = table.Column(type: "xml", nullable: true), + Value_Binary = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_SharedSideAttribute", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tenant", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + EMail = table.Column(nullable: true), + Phone = table.Column(nullable: true), + Country = table.Column(nullable: true), + Province = table.Column(nullable: true), + City = table.Column(nullable: true), + Street = table.Column(nullable: true), + Address = table.Column(nullable: true), + ZipCode = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tenant", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Customer", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + Email = table.Column(nullable: true), + Phone = table.Column(nullable: true), + Country = table.Column(nullable: true), + Province = table.Column(nullable: true), + City = table.Column(nullable: true), + Street = table.Column(nullable: true), + Address = table.Column(nullable: true), + ZipCode = table.Column(nullable: false), + TenantId = table.Column(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: "Device", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + Type = table.Column(nullable: true), + TenantId = table.Column(nullable: true), + CustomerId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Device", x => x.Id); + table.ForeignKey( + name: "FK_Device_Customer_CustomerId", + column: x => x.CustomerId, + principalTable: "Customer", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Device_Tenant_TenantId", + column: x => x.TenantId, + principalTable: "Tenant", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Customer_TenantId", + table: "Customer", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Device_CustomerId", + table: "Device", + column: "CustomerId"); + + migrationBuilder.CreateIndex( + name: "IX_Device_TenantId", + table: "Device", + column: "TenantId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ClientSideAttribute"); + + migrationBuilder.DropTable( + name: "Device"); + + migrationBuilder.DropTable( + name: "Relationship"); + + migrationBuilder.DropTable( + name: "ServerSideAttribute"); + + migrationBuilder.DropTable( + name: "SharedSideAttribute"); + + migrationBuilder.DropTable( + name: "Customer"); + + migrationBuilder.DropTable( + name: "Tenant"); + + migrationBuilder.DropIndex( + name: "UserNameIndex", + table: "AspNetUsers"); + + migrationBuilder.DropIndex( + name: "RoleNameIndex", + table: "AspNetRoles"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "AspNetUserClaims", + nullable: false, + oldClrType: typeof(int)) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); + + migrationBuilder.AlterColumn( + name: "Id", + table: "AspNetRoleClaims", + nullable: false, + oldClrType: typeof(int)) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + } + } +} diff --git a/IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs index 2d6ada50..21407061 100644 --- a/IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using IoTSharp.Hub.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace IoTSharp.Hub.Data.Migrations { @@ -15,9 +15,195 @@ namespace IoTSharp.Hub.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.4-rtm-31024") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.2.0-rtm-35687") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("IoTSharp.Hub.Data.ClientSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("ClientSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("City"); + + b.Property("Country"); + + b.Property("Email"); + + b.Property("Name"); + + b.Property("Phone"); + + b.Property("Province"); + + b.Property("Street"); + + b.Property("TenantId"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.HasIndex("TenantId"); + + b.ToTable("Customer"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Device", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CustomerId"); + + b.Property("Name"); + + b.Property("TenantId"); + + b.Property("Type"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("TenantId"); + + b.ToTable("Device"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Relationship", b => + { + b.Property("UseId") + .ValueGeneratedOnAdd(); + + b.Property("CustomerId"); + + b.Property("TenantId"); + + b.HasKey("UseId"); + + b.ToTable("Relationship"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.ServerSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("ServerSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.SharedSideAttribute", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("Type"); + + b.Property("Value_Binary"); + + b.Property("Value_Boolean"); + + b.Property("Value_Double"); + + b.Property("Value_Json") + .HasColumnType("jsonb"); + + b.Property("Value_Long"); + + b.Property("Value_String"); + + b.Property("Value_XML") + .HasColumnType("xml"); + + b.HasKey("Id"); + + b.ToTable("SharedSideAttribute"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Address"); + + b.Property("City"); + + b.Property("Country"); + + b.Property("EMail"); + + b.Property("Name"); + + b.Property("Phone"); + + b.Property("Province"); + + b.Property("Street"); + + b.Property("ZipCode"); + + b.HasKey("Id"); + + b.ToTable("Tenant"); + }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { @@ -37,8 +223,7 @@ namespace IoTSharp.Hub.Data.Migrations b.HasIndex("NormalizedName") .IsUnique() - .HasName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasName("RoleNameIndex"); b.ToTable("AspNetRoles"); }); @@ -46,8 +231,7 @@ namespace IoTSharp.Hub.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .ValueGeneratedOnAdd(); b.Property("ClaimType"); @@ -108,8 +292,7 @@ namespace IoTSharp.Hub.Data.Migrations b.HasIndex("NormalizedUserName") .IsUnique() - .HasName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasName("UserNameIndex"); b.ToTable("AspNetUsers"); }); @@ -117,8 +300,7 @@ namespace IoTSharp.Hub.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .ValueGeneratedOnAdd(); b.Property("ClaimType"); @@ -184,6 +366,23 @@ namespace IoTSharp.Hub.Data.Migrations b.ToTable("AspNetUserTokens"); }); + modelBuilder.Entity("IoTSharp.Hub.Data.Customer", b => + { + b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant") + .WithMany("Customers") + .HasForeignKey("TenantId"); + }); + + modelBuilder.Entity("IoTSharp.Hub.Data.Device", b => + { + b.HasOne("IoTSharp.Hub.Data.Customer", "Customer") + .WithMany("Devices") + .HasForeignKey("CustomerId"); + + b.HasOne("IoTSharp.Hub.Data.Tenant", "Tenant") + .WithMany("Devices") + .HasForeignKey("TenantId"); + }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { diff --git a/IoTSharp.Hub/Extensions/IoTSharpExtension.cs b/IoTSharp.Hub/Extensions/IoTSharpExtension.cs index 7ac3c1fd..d5677706 100644 --- a/IoTSharp.Hub/Extensions/IoTSharpExtension.cs +++ b/IoTSharp.Hub/Extensions/IoTSharpExtension.cs @@ -25,30 +25,42 @@ namespace IoTSharp.Hub case "mssql": services.AddEntityFrameworkSqlServer(); services.AddDbContext(options => options.UseSqlServer(_ConnectionString), ServiceLifetime.Transient); +#if WithHealthChecks services.AddHealthChecks().AddSqlServer(_ConnectionString, name: "database").AddMQTTChatHealthChecks(); +#endif break; case "npgsql": services.AddEntityFrameworkNpgsql(); services.AddDbContext(options => options.UseNpgsql(_ConnectionString), ServiceLifetime.Transient); +#if WithHealthChecks services.AddHealthChecks().AddNpgSql(_ConnectionString, name: "database").AddMQTTChatHealthChecks(); +#endif break; case "memory": services.AddEntityFrameworkInMemoryDatabase(); services.AddDbContext(options => options.UseInMemoryDatabase(nameof(ApplicationDbContext)), ServiceLifetime.Transient); +#if WithHealthChecks services.AddHealthChecks().AddMQTTChatHealthChecks(); +#endif break; case "sqlite": default: services.AddEntityFrameworkSqlite(); services.AddDbContext(options => options.UseSqlite(_ConnectionString), ServiceLifetime.Transient); +#if WithHealthChecks services.AddHealthChecks().AddSqlite(_ConnectionString, name: "database").AddMQTTChatHealthChecks(); +#endif break; } - services.AddHealthChecksUI(); +#if WithHealthChecks + services.AddHealthChecksUI(); +#endif } + +#if WithHealthChecks internal static void UseIotSharpHealthChecks(this IApplicationBuilder app) { app.UseHealthChecksUI(); @@ -69,7 +81,7 @@ namespace IoTSharp.Hub }); }); } - +#endif private static string GetFullPathName(string filename) { FileInfo fi = new FileInfo(System.IO.Path.Combine( diff --git a/IoTSharp.Hub/Startup.cs b/IoTSharp.Hub/Startup.cs index abffa849..72229d18 100644 --- a/IoTSharp.Hub/Startup.cs +++ b/IoTSharp.Hub/Startup.cs @@ -106,8 +106,9 @@ namespace IoTSharp.Hub var externalPath = request.Headers.ContainsKey("X-External-Path") ? request.Headers["X-External-Path"].First() : ""; return externalPath + internalUiRoute; }); - +#if WithHealthChecks app.UseIotSharpHealthChecks(); +#endif } } } \ No newline at end of file diff --git a/IoTSharp.Hub/appsettings.Development.json b/IoTSharp.Hub/appsettings.Development.json index 52dec846..d4a2a012 100644 --- a/IoTSharp.Hub/appsettings.Development.json +++ b/IoTSharp.Hub/appsettings.Development.json @@ -6,10 +6,10 @@ "Microsoft": "Information" } }, - "DataBase": "sqlite", + "DataBase": "npgsql", "ConnectionStrings": { - "mssql": "Server=localhost;Database=MQTTChat;Trusted_Connection=True;MultipleActiveResultSets=true", - "npgsql": "Server=localhost;Database=MQTTChat;Username=postgres;Password=future;", + "mssql": "Server=localhost;Database=IoTSharp;Trusted_Connection=True;MultipleActiveResultSets=true", + "npgsql": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;", "sqlite": "Data Source=:memory:" }, "JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme", diff --git a/IoTSharp.sln b/IoTSharp.sln index d8e9d07c..81e00b77 100644 --- a/IoTSharp.sln +++ b/IoTSharp.sln @@ -12,8 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{4B89CAE2-66F7-4C95-B701-AE48810F2051}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,10 +22,6 @@ Global {260081B3-E2EA-4BA0-8322-E3894907585E}.Debug|Any CPU.Build.0 = Debug|Any CPU {260081B3-E2EA-4BA0-8322-E3894907585E}.Release|Any CPU.ActiveCfg = Release|Any CPU {260081B3-E2EA-4BA0-8322-E3894907585E}.Release|Any CPU.Build.0 = Release|Any CPU - {4B89CAE2-66F7-4C95-B701-AE48810F2051}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4B89CAE2-66F7-4C95-B701-AE48810F2051}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4B89CAE2-66F7-4C95-B701-AE48810F2051}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4B89CAE2-66F7-4C95-B701-AE48810F2051}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/healthchecksdb b/healthchecksdb new file mode 100644 index 0000000000000000000000000000000000000000..da5c71fd46f8bb9d46c4982e483cdacca87c54c1 GIT binary patch literal 45056 zcmeI*(Qn#D90zc_1RTg1+moef-CREvr6fSrQB{*NYL3P#F%-;{JXFX7Cs-qPYMVBF znnGaf6x4q{v-YN zlhVew$*;LmqC*d2g8&2|a5Du)&r=-#N@CB_hS}3k<^9gCt_|G2)YrQ|l2g4qbPdbg zH5}KnUx${-y@(ncQj?TbBFIXG>KS z>0T*1|MjVV6kAl&izD-EMa6ZluXDU4v2UNb+7AOgLMNgq8APC#AJ@n-;&e)&n@CY< zHdXS3GzF!u3QD_H6QsJ*Qk!LZTo4;iLx)K)ghZjyl=sTb1K}w-5Xx<}E-Umb_K2e1 z3wmg|nmcqp>}673H$_1u`?Twz`$<7qq;scBPc?Y$>J*&i!m zvHJz<%X2&#Z2vLCK{HG9t7ymif($N8eMNV=wsGQJk|r%ob1GJbwl-VzQHO^g?f*PD zMyCmmzkQoM9}kYIW(!rfGCY{{(XwB^CRgB}aS@t~Zw<%fXp>Y&UP-p(x+FXm`eBsrS zb-C`+gnb0d(LT%Zr4oBq_apCgNOjLR8ef{6$tS6>gSX}#LMu)=F52|of##;s<+tMn z4b9k0-a#9-)f;x*?{(Xmxx@z7Q94ZITM7PoiDmrHQbFpqp=gj{xR>zv)$v|{RiJXETw2%Z01jf-mpOc0uX=z1Rwwb2tWV=5P$##AaGp; zzKTi7h#v=xfB*lE$-KL+0ph$N009U<00Izz00bZa0SG_<0yj=zn~gIh%k*9MN2D93w&q zKmY;|fB*y_009U<00IzzfcO9Z@cn;`0|-C>0uX=z1Rwwb2tWV=5P-mH3t;`f+WAFv Y5P$##AOHafKmY;|fB*y_00B?nZz~~&0{{R3 literal 0 HcmV?d00001 -- GitLab