From 50fe69662debd84e382ca947a0436acc9abe984d Mon Sep 17 00:00:00 2001 From: Tokk Date: Fri, 12 Jun 2020 20:00:14 +0200 Subject: [PATCH] =?UTF-8?q?unterst=C3=BCzung=20f=C3=BCr=20MySql;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...000000000_CreateIdentitySchema.Designer.cs | 277 ------------------ .../20200604185621_BusinessEntities.cs | 146 --------- ...0612175900_InitialSchemaMySql.Designer.cs} | 125 ++++---- .../20200612175900_InitialSchemaMySql.cs} | 146 ++++++++- .../ApplicationDbContextModelSnapshot.cs | 121 ++++---- .../MultipleChoiceTrainer.csproj | 22 +- MultipleChoiceTrainer/Startup.cs | 19 +- 7 files changed, 281 insertions(+), 575 deletions(-) delete mode 100644 MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs delete mode 100644 MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.cs rename MultipleChoiceTrainer/{Data/Migrations/20200604185621_BusinessEntities.Designer.cs => Migrations/20200612175900_InitialSchemaMySql.Designer.cs} (73%) rename MultipleChoiceTrainer/{Data/Migrations/00000000000000_CreateIdentitySchema.cs => Migrations/20200612175900_InitialSchemaMySql.cs} (60%) rename MultipleChoiceTrainer/{Data => }/Migrations/ApplicationDbContextModelSnapshot.cs (74%) diff --git a/MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs deleted file mode 100644 index 44e7727..0000000 --- a/MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs +++ /dev/null @@ -1,277 +0,0 @@ -// -using System; -using MultipleChoiceTrainer.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace MultipleChoiceTrainer.Data.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("00000000000000_CreateIdentitySchema")] - partial class CreateIdentitySchema - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); - - b.Property("NormalizedName") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasName("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") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); - - b.Property("NormalizedUserName") - .HasColumnType("nvarchar(256)") - .HasMaxLength(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") - .HasColumnType("nvarchar(256)") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("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(128)") - .HasMaxLength(128); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); - - 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(128)") - .HasMaxLength(128); - - b.Property("Name") - .HasColumnType("nvarchar(128)") - .HasMaxLength(128); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - 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(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.cs b/MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.cs deleted file mode 100644 index ff4dc04..0000000 --- a/MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace MultipleChoiceTrainer.Data.Migrations -{ - public partial class BusinessEntities : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Categories", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true), - Description = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Categories", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Sections", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(nullable: true), - Description = table.Column(nullable: true), - CategoryId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Sections", x => x.Id); - table.ForeignKey( - name: "FK_Sections_Categories_CategoryId", - column: x => x.CategoryId, - principalTable: "Categories", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Questions", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Text = table.Column(nullable: true), - SectionId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Questions", x => x.Id); - table.ForeignKey( - name: "FK_Questions_Sections_SectionId", - column: x => x.SectionId, - principalTable: "Sections", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Answers", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Date = table.Column(nullable: false), - QuestionId = table.Column(nullable: false), - Successfull = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Answers", x => x.Id); - table.ForeignKey( - name: "FK_Answers_Questions_QuestionId", - column: x => x.QuestionId, - principalTable: "Questions", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Choices", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - QuestionId = table.Column(nullable: false), - Text = table.Column(nullable: true), - IsTrue = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Choices", x => x.Id); - table.ForeignKey( - name: "FK_Choices_Questions_QuestionId", - column: x => x.QuestionId, - principalTable: "Questions", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Answers_QuestionId", - table: "Answers", - column: "QuestionId"); - - migrationBuilder.CreateIndex( - name: "IX_Choices_QuestionId", - table: "Choices", - column: "QuestionId"); - - migrationBuilder.CreateIndex( - name: "IX_Questions_SectionId", - table: "Questions", - column: "SectionId"); - - migrationBuilder.CreateIndex( - name: "IX_Sections_CategoryId", - table: "Sections", - column: "CategoryId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Answers"); - - migrationBuilder.DropTable( - name: "Choices"); - - migrationBuilder.DropTable( - name: "Questions"); - - migrationBuilder.DropTable( - name: "Sections"); - - migrationBuilder.DropTable( - name: "Categories"); - } - } -} diff --git a/MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.Designer.cs b/MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.Designer.cs similarity index 73% rename from MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.Designer.cs rename to MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.Designer.cs index d1b78ab..f0dc229 100644 --- a/MultipleChoiceTrainer/Data/Migrations/20200604185621_BusinessEntities.Designer.cs +++ b/MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.Designer.cs @@ -2,48 +2,45 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using MultipleChoiceTrainer.Data; -namespace MultipleChoiceTrainer.Data.Migrations +namespace MultipleChoiceTrainer.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20200604185621_BusinessEntities")] - partial class BusinessEntities + [Migration("20200612175900_InitialSchemaMySql")] + partial class InitialSchemaMySql { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("NormalizedName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() - .HasName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasName("RoleNameIndex"); b.ToTable("AspNetRoles"); }); @@ -52,18 +49,17 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("RoleId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -75,53 +71,53 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("AccessFailedCount") .HasColumnType("int"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Email") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("EmailConfirmed") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); + .HasColumnType("datetime(6)"); b.Property("NormalizedEmail") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("NormalizedUserName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("TwoFactorEnabled") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("UserName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.HasKey("Id"); @@ -131,8 +127,7 @@ namespace MultipleChoiceTrainer.Data.Migrations b.HasIndex("NormalizedUserName") .IsUnique() - .HasName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasName("UserNameIndex"); b.ToTable("AspNetUsers"); }); @@ -141,18 +136,17 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -164,19 +158,19 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("ProviderKey") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("LoginProvider", "ProviderKey"); @@ -188,10 +182,10 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("RoleId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("UserId", "RoleId"); @@ -203,18 +197,18 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("Name") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("Value") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("UserId", "LoginProvider", "Name"); @@ -225,17 +219,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("Date") - .HasColumnType("datetime2"); + .HasColumnType("datetime(6)"); b.Property("QuestionId") .HasColumnType("int"); b.Property("Successfull") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.HasKey("Id"); @@ -248,14 +241,13 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -266,17 +258,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("IsTrue") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("QuestionId") .HasColumnType("int"); b.Property("Text") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -289,14 +280,13 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("SectionId") .HasColumnType("int"); b.Property("Text") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -309,17 +299,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("CategoryId") .HasColumnType("int"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); diff --git a/MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.cs b/MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.cs similarity index 60% rename from MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.cs rename to MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.cs index 88cf83a..d63d4d9 100644 --- a/MultipleChoiceTrainer/Data/Migrations/00000000000000_CreateIdentitySchema.cs +++ b/MultipleChoiceTrainer/Migrations/20200612175900_InitialSchemaMySql.cs @@ -2,9 +2,9 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -namespace MultipleChoiceTrainer.Data.Migrations +namespace MultipleChoiceTrainer.Migrations { - public partial class CreateIdentitySchema : Migration + public partial class InitialSchemaMySql : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -47,12 +47,26 @@ namespace MultipleChoiceTrainer.Data.Migrations table.PrimaryKey("PK_AspNetUsers", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Categories", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true), + Description = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Categories", x => x.Id); + }); + migrationBuilder.CreateTable( name: "AspNetRoleClaims", columns: table => new { Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), RoleId = table.Column(nullable: false), ClaimType = table.Column(nullable: true), ClaimValue = table.Column(nullable: true) @@ -73,7 +87,7 @@ namespace MultipleChoiceTrainer.Data.Migrations columns: table => new { Id = table.Column(nullable: false) - .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(nullable: false), ClaimType = table.Column(nullable: true), ClaimValue = table.Column(nullable: true) @@ -153,6 +167,94 @@ namespace MultipleChoiceTrainer.Data.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Sections", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column(nullable: true), + Description = table.Column(nullable: true), + CategoryId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sections", x => x.Id); + table.ForeignKey( + name: "FK_Sections_Categories_CategoryId", + column: x => x.CategoryId, + principalTable: "Categories", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Questions", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Text = table.Column(nullable: true), + SectionId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Questions", x => x.Id); + table.ForeignKey( + name: "FK_Questions_Sections_SectionId", + column: x => x.SectionId, + principalTable: "Sections", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Answers", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Date = table.Column(nullable: false), + QuestionId = table.Column(nullable: false), + Successfull = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Answers", x => x.Id); + table.ForeignKey( + name: "FK_Answers_Questions_QuestionId", + column: x => x.QuestionId, + principalTable: "Questions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Choices", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + QuestionId = table.Column(nullable: false), + Text = table.Column(nullable: true), + IsTrue = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Choices", x => x.Id); + table.ForeignKey( + name: "FK_Choices_Questions_QuestionId", + column: x => x.QuestionId, + principalTable: "Questions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Answers_QuestionId", + table: "Answers", + column: "QuestionId"); + migrationBuilder.CreateIndex( name: "IX_AspNetRoleClaims_RoleId", table: "AspNetRoleClaims", @@ -162,8 +264,7 @@ namespace MultipleChoiceTrainer.Data.Migrations name: "RoleNameIndex", table: "AspNetRoles", column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); + unique: true); migrationBuilder.CreateIndex( name: "IX_AspNetUserClaims_UserId", @@ -189,12 +290,29 @@ namespace MultipleChoiceTrainer.Data.Migrations name: "UserNameIndex", table: "AspNetUsers", column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Choices_QuestionId", + table: "Choices", + column: "QuestionId"); + + migrationBuilder.CreateIndex( + name: "IX_Questions_SectionId", + table: "Questions", + column: "SectionId"); + + migrationBuilder.CreateIndex( + name: "IX_Sections_CategoryId", + table: "Sections", + column: "CategoryId"); } protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "Answers"); + migrationBuilder.DropTable( name: "AspNetRoleClaims"); @@ -210,11 +328,23 @@ namespace MultipleChoiceTrainer.Data.Migrations migrationBuilder.DropTable( name: "AspNetUserTokens"); + migrationBuilder.DropTable( + name: "Choices"); + migrationBuilder.DropTable( name: "AspNetRoles"); migrationBuilder.DropTable( name: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "Questions"); + + migrationBuilder.DropTable( + name: "Sections"); + + migrationBuilder.DropTable( + name: "Categories"); } } } diff --git a/MultipleChoiceTrainer/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/MultipleChoiceTrainer/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 74% rename from MultipleChoiceTrainer/Data/Migrations/ApplicationDbContextModelSnapshot.cs rename to MultipleChoiceTrainer/Migrations/ApplicationDbContextModelSnapshot.cs index 6d6dc8d..806b196 100644 --- a/MultipleChoiceTrainer/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/MultipleChoiceTrainer/Migrations/ApplicationDbContextModelSnapshot.cs @@ -2,11 +2,10 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using MultipleChoiceTrainer.Data; -namespace MultipleChoiceTrainer.Data.Migrations +namespace MultipleChoiceTrainer.Migrations { [DbContext(typeof(ApplicationDbContext))] partial class ApplicationDbContextModelSnapshot : ModelSnapshot @@ -15,33 +14,31 @@ namespace MultipleChoiceTrainer.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "3.1.5") + .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("NormalizedName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() - .HasName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasName("RoleNameIndex"); b.ToTable("AspNetRoles"); }); @@ -50,18 +47,17 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("RoleId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -73,53 +69,53 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("AccessFailedCount") .HasColumnType("int"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Email") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("EmailConfirmed") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); + .HasColumnType("datetime(6)"); b.Property("NormalizedEmail") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("NormalizedUserName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("TwoFactorEnabled") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("UserName") - .HasColumnType("nvarchar(256)") + .HasColumnType("varchar(256) CHARACTER SET utf8mb4") .HasMaxLength(256); b.HasKey("Id"); @@ -129,8 +125,7 @@ namespace MultipleChoiceTrainer.Data.Migrations b.HasIndex("NormalizedUserName") .IsUnique() - .HasName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasName("UserNameIndex"); b.ToTable("AspNetUsers"); }); @@ -139,18 +134,17 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -162,19 +156,19 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("ProviderKey") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("LoginProvider", "ProviderKey"); @@ -186,10 +180,10 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("RoleId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.HasKey("UserId", "RoleId"); @@ -201,18 +195,18 @@ namespace MultipleChoiceTrainer.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("LoginProvider") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("Name") - .HasColumnType("nvarchar(128)") + .HasColumnType("varchar(128) CHARACTER SET utf8mb4") .HasMaxLength(128); b.Property("Value") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("UserId", "LoginProvider", "Name"); @@ -223,17 +217,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("Date") - .HasColumnType("datetime2"); + .HasColumnType("datetime(6)"); b.Property("QuestionId") .HasColumnType("int"); b.Property("Successfull") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.HasKey("Id"); @@ -246,14 +239,13 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -264,17 +256,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("IsTrue") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("QuestionId") .HasColumnType("int"); b.Property("Text") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -287,14 +278,13 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("SectionId") .HasColumnType("int"); b.Property("Text") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); @@ -307,17 +297,16 @@ namespace MultipleChoiceTrainer.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b.Property("CategoryId") .HasColumnType("int"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext CHARACTER SET utf8mb4"); b.HasKey("Id"); diff --git a/MultipleChoiceTrainer/MultipleChoiceTrainer.csproj b/MultipleChoiceTrainer/MultipleChoiceTrainer.csproj index f478dff..b17333f 100644 --- a/MultipleChoiceTrainer/MultipleChoiceTrainer.csproj +++ b/MultipleChoiceTrainer/MultipleChoiceTrainer.csproj @@ -6,14 +6,22 @@ - - - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/MultipleChoiceTrainer/Startup.cs b/MultipleChoiceTrainer/Startup.cs index fbc6b8c..c5eae24 100644 --- a/MultipleChoiceTrainer/Startup.cs +++ b/MultipleChoiceTrainer/Startup.cs @@ -27,15 +27,28 @@ namespace MultipleChoiceTrainer // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddDbContext(options => - options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"))); + AddDbContext(services); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); services.AddControllersWithViews(); services.AddRazorPages(); } + private void AddDbContext(IServiceCollection services) + { + var connectionString = Configuration.GetConnectionString("DefaultConnection"); + + if(connectionString.StartsWith("mysql://")) + { + var conStr = connectionString.Substring("mysql://".Length); + services.AddDbContext(options => options.UseMySql(conStr)); + } + else + { + services.AddDbContext(options => options.UseSqlServer(connectionString)); + } + } + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {