From cbc9502bed295e9c6aedd10b075faa4302712afd Mon Sep 17 00:00:00 2001 From: Abbas Alsbihawi <43404498+AbbasAlsbihawi@users.noreply.github.com> Date: Tue, 13 Aug 2024 00:21:19 +0300 Subject: [PATCH] upgrade project from v7 to v8 and connect with postgresql db --- Project.API/Program.cs | 13 +- Project.API/Project.API.csproj | 9 +- Project.API/appsettings.json | 2 +- Project.Core/Project.Core.csproj | 2 +- ...230703085651_Initial_Migration.Designer.cs | 318 ------------------ .../Migrations/20230712112009_Seed Data.cs | 87 ----- ...12211751_CreateIdentitySchema.Designer.cs} | 112 +++--- ...=> 20240812211751_CreateIdentitySchema.cs} | 122 ++++--- .../ApplicationDbContextModelSnapshot.cs | 108 +++--- .../Project.Infrastructure.csproj | 11 +- Project.UnitTest/Project.UnitTest.csproj | 12 +- README.md | 4 + 12 files changed, 210 insertions(+), 590 deletions(-) delete mode 100644 Project.Infrastructure/Migrations/20230703085651_Initial_Migration.Designer.cs delete mode 100644 Project.Infrastructure/Migrations/20230712112009_Seed Data.cs rename Project.Infrastructure/Migrations/{20230712112009_Seed Data.Designer.cs => 20240812211751_CreateIdentitySchema.Designer.cs} (78%) rename Project.Infrastructure/Migrations/{20230703085651_Initial_Migration.cs => 20240812211751_CreateIdentitySchema.cs} (61%) diff --git a/Project.API/Program.cs b/Project.API/Program.cs index e9a099a..ffcb99f 100644 --- a/Project.API/Program.cs +++ b/Project.API/Program.cs @@ -1,13 +1,18 @@ using Microsoft.EntityFrameworkCore; using Project.API.Middlewares; using Project.Infrastructure.Data; -using Project.API.Extensions; +using Project.API.Extensions; var builder = WebApplication.CreateBuilder(args); +// connect db SqlServer ? +// builder.Services.AddDbContext( +// options => options.UseSqlServer(builder.Configuration +// .GetConnectionString("PrimaryDbConnection"))); +// connect db postgresql ? +builder.Services.AddDbContext(options => + options.UseNpgsql( + builder.Configuration.GetConnectionString("PrimaryDbConnection"))); -builder.Services.AddDbContext( - options => options.UseSqlServer(builder.Configuration - .GetConnectionString("PrimaryDbConnection"))); //Register Services builder.Services.RegisterService(); diff --git a/Project.API/Project.API.csproj b/Project.API/Project.API.csproj index f4c694c..fd7d9b7 100644 --- a/Project.API/Project.API.csproj +++ b/Project.API/Project.API.csproj @@ -1,18 +1,19 @@ - net7.0 + net8.0 enable enable - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/Project.API/appsettings.json b/Project.API/appsettings.json index 222b3a0..58f7db5 100644 --- a/Project.API/appsettings.json +++ b/Project.API/appsettings.json @@ -6,7 +6,7 @@ } }, "ConnectionStrings": { - "PrimaryDbConnection": "server=YourServer; database=YourDatabase; Trusted_Connection=True;TrustServerCertificate=True" + "PrimaryDbConnection": "Host=localhost;Database=YourDatabase;Username=YourUsername;Password=YourPassword" }, "AllowedHosts": "*" } diff --git a/Project.Core/Project.Core.csproj b/Project.Core/Project.Core.csproj index 56fb663..688f6f7 100644 --- a/Project.Core/Project.Core.csproj +++ b/Project.Core/Project.Core.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/Project.Infrastructure/Migrations/20230703085651_Initial_Migration.Designer.cs b/Project.Infrastructure/Migrations/20230703085651_Initial_Migration.Designer.cs deleted file mode 100644 index fa60932..0000000 --- a/Project.Infrastructure/Migrations/20230703085651_Initial_Migration.Designer.cs +++ /dev/null @@ -1,318 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Project.Infrastructure.Data; - -#nullable disable - -namespace Project.Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20230703085651_Initial_Migration")] - partial class Initial_Migration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - 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("Roles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - 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", (string)null); - }); - - 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("Users", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - 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", (string)null); - }); - - 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", (string)null); - }); - - 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", (string)null); - }); - - 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", (string)null); - }); - - modelBuilder.Entity("Project.Core.Entities.General.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Code") - .IsRequired() - .HasMaxLength(8) - .HasColumnType("nvarchar(8)"); - - b.Property("Description") - .HasMaxLength(350) - .HasColumnType("nvarchar(350)"); - - b.Property("EntryDate") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Price") - .HasColumnType("real"); - - b.Property("UpdateDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.ToTable("Products"); - }); - - 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/Project.Infrastructure/Migrations/20230712112009_Seed Data.cs b/Project.Infrastructure/Migrations/20230712112009_Seed Data.cs deleted file mode 100644 index e95761e..0000000 --- a/Project.Infrastructure/Migrations/20230712112009_Seed Data.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Project.Infrastructure.Migrations -{ - /// - public partial class SeedData : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.InsertData( - table: "Products", - columns: new[] { "Id", "Code", "Description", "EntryDate", "IsActive", "Name", "Price", "UpdateDate" }, - values: new object[,] - { - { 1, "P001", null, null, true, "Product 1", 9.99f, null }, - { 2, "P002", null, null, true, "Product 2", 12f, null }, - { 3, "P003", null, null, true, "Product 3", 13f, null }, - { 4, "P004", null, null, true, "Product 4", 14f, null }, - { 5, "P005", null, null, true, "Product 5", 15f, null }, - { 6, "P006", null, null, true, "Product 6", 16f, null }, - { 7, "P007", null, null, true, "Product 7", 17f, null }, - { 8, "P008", null, null, true, "Product 8", 18f, null }, - { 9, "P009", null, null, true, "Product 9", 19f, null }, - { 10, "P010", null, null, true, "Product 10", 19.99f, null } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 1); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 2); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 3); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 4); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 5); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 6); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 7); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 8); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 9); - - migrationBuilder.DeleteData( - table: "Products", - keyColumn: "Id", - keyValue: 10); - } - } -} diff --git a/Project.Infrastructure/Migrations/20230712112009_Seed Data.Designer.cs b/Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.Designer.cs similarity index 78% rename from Project.Infrastructure/Migrations/20230712112009_Seed Data.Designer.cs rename to Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.Designer.cs index 2319604..6ef317e 100644 --- a/Project.Infrastructure/Migrations/20230712112009_Seed Data.Designer.cs +++ b/Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.Designer.cs @@ -2,9 +2,9 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Project.Infrastructure.Data; #nullable disable @@ -12,42 +12,41 @@ namespace Project.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20230712112009_Seed Data")] - partial class SeedData + [Migration("20240812211751_CreateIdentitySchema")] + partial class CreateIdentitySchema { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasDatabaseName("RoleNameIndex"); b.ToTable("Roles", (string)null); }); @@ -56,19 +55,19 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("RoleId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -80,54 +79,54 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("AccessFailedCount") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("EmailConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); + .HasColumnType("timestamp with time zone"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("TwoFactorEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -136,8 +135,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("NormalizedUserName") .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasDatabaseName("UserNameIndex"); b.ToTable("Users", (string)null); }); @@ -146,19 +144,19 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -170,17 +168,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("LoginProvider", "ProviderKey"); @@ -192,10 +190,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("RoleId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("UserId", "RoleId"); @@ -207,16 +205,16 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("UserId", "LoginProvider", "Name"); @@ -227,35 +225,35 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Code") .IsRequired() .HasMaxLength(8) - .HasColumnType("nvarchar(8)"); + .HasColumnType("character varying(8)"); b.Property("Description") .HasMaxLength(350) - .HasColumnType("nvarchar(350)"); + .HasColumnType("character varying(350)"); b.Property("EntryDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("IsActive") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("Name") .IsRequired() .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); + .HasColumnType("character varying(100)"); b.Property("Price") .HasColumnType("real"); b.Property("UpdateDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.HasKey("Id"); diff --git a/Project.Infrastructure/Migrations/20230703085651_Initial_Migration.cs b/Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.cs similarity index 61% rename from Project.Infrastructure/Migrations/20230703085651_Initial_Migration.cs rename to Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.cs index b0c4dca..e8d9113 100644 --- a/Project.Infrastructure/Migrations/20230703085651_Initial_Migration.cs +++ b/Project.Infrastructure/Migrations/20240812211751_CreateIdentitySchema.cs @@ -1,12 +1,15 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + namespace Project.Infrastructure.Migrations { /// - public partial class Initial_Migration : Migration + public partial class CreateIdentitySchema : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -15,15 +18,15 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Products", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Code = table.Column(type: "nvarchar(8)", maxLength: 8, nullable: false), - Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Code = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Price = table.Column(type: "real", nullable: false), - Description = table.Column(type: "nvarchar(350)", maxLength: 350, nullable: true), - IsActive = table.Column(type: "bit", nullable: false), - EntryDate = table.Column(type: "datetime2", nullable: true), - UpdateDate = table.Column(type: "datetime2", nullable: true) + Description = table.Column(type: "character varying(350)", maxLength: 350, nullable: true), + IsActive = table.Column(type: "boolean", nullable: false), + EntryDate = table.Column(type: "timestamp with time zone", nullable: true), + UpdateDate = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { @@ -34,10 +37,10 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Roles", 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) + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -48,21 +51,21 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Users", 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) + Id = table.Column(type: "text", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -73,11 +76,11 @@ protected override void Up(MigrationBuilder migrationBuilder) 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) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -94,11 +97,11 @@ protected override void Up(MigrationBuilder migrationBuilder) 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) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -115,10 +118,10 @@ protected override void Up(MigrationBuilder migrationBuilder) 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) + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -135,8 +138,8 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "AspNetUserRoles", columns: table => new { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - RoleId = table.Column(type: "nvarchar(450)", nullable: false) + UserId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -159,10 +162,10 @@ protected override void Up(MigrationBuilder migrationBuilder) 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) + UserId = table.Column(type: "text", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -175,6 +178,23 @@ protected override void Up(MigrationBuilder migrationBuilder) onDelete: ReferentialAction.Cascade); }); + migrationBuilder.InsertData( + table: "Products", + columns: new[] { "Id", "Code", "Description", "EntryDate", "IsActive", "Name", "Price", "UpdateDate" }, + values: new object[,] + { + { 1, "P001", null, null, true, "Product 1", 9.99f, null }, + { 2, "P002", null, null, true, "Product 2", 12f, null }, + { 3, "P003", null, null, true, "Product 3", 13f, null }, + { 4, "P004", null, null, true, "Product 4", 14f, null }, + { 5, "P005", null, null, true, "Product 5", 15f, null }, + { 6, "P006", null, null, true, "Product 6", 16f, null }, + { 7, "P007", null, null, true, "Product 7", 17f, null }, + { 8, "P008", null, null, true, "Product 8", 18f, null }, + { 9, "P009", null, null, true, "Product 9", 19f, null }, + { 10, "P010", null, null, true, "Product 10", 19.99f, null } + }); + migrationBuilder.CreateIndex( name: "IX_AspNetRoleClaims_RoleId", table: "AspNetRoleClaims", @@ -199,8 +219,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "RoleNameIndex", table: "Roles", column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); + unique: true); migrationBuilder.CreateIndex( name: "EmailIndex", @@ -211,8 +230,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "UserNameIndex", table: "Users", column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); + unique: true); } /// diff --git a/Project.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/Project.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index 9aa4934..bdaa1d2 100644 --- a/Project.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Project.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -2,8 +2,8 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Project.Infrastructure.Data; #nullable disable @@ -17,34 +17,33 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasDatabaseName("RoleNameIndex"); b.ToTable("Roles", (string)null); }); @@ -53,19 +52,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("RoleId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -77,54 +76,54 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("AccessFailedCount") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("EmailConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); + .HasColumnType("timestamp with time zone"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("TwoFactorEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)"); b.HasKey("Id"); @@ -133,8 +132,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("NormalizedUserName") .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasDatabaseName("UserNameIndex"); b.ToTable("Users", (string)null); }); @@ -143,19 +141,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -167,17 +165,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("UserId") .IsRequired() - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("LoginProvider", "ProviderKey"); @@ -189,10 +187,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("RoleId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.HasKey("UserId", "RoleId"); @@ -204,16 +202,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("Name") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text"); b.Property("Value") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("UserId", "LoginProvider", "Name"); @@ -224,35 +222,35 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Code") .IsRequired() .HasMaxLength(8) - .HasColumnType("nvarchar(8)"); + .HasColumnType("character varying(8)"); b.Property("Description") .HasMaxLength(350) - .HasColumnType("nvarchar(350)"); + .HasColumnType("character varying(350)"); b.Property("EntryDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("IsActive") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("Name") .IsRequired() .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); + .HasColumnType("character varying(100)"); b.Property("Price") .HasColumnType("real"); b.Property("UpdateDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.HasKey("Id"); diff --git a/Project.Infrastructure/Project.Infrastructure.csproj b/Project.Infrastructure/Project.Infrastructure.csproj index 4dbd805..89471df 100644 --- a/Project.Infrastructure/Project.Infrastructure.csproj +++ b/Project.Infrastructure/Project.Infrastructure.csproj @@ -1,19 +1,20 @@ - net7.0 + net8.0 enable enable - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Project.UnitTest/Project.UnitTest.csproj b/Project.UnitTest/Project.UnitTest.csproj index da71c01..abc12c7 100644 --- a/Project.UnitTest/Project.UnitTest.csproj +++ b/Project.UnitTest/Project.UnitTest.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -10,11 +10,11 @@ - - - - - + + + + + diff --git a/README.md b/README.md index 27d06d0..0ff9579 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,10 @@ To use this project template, follow the steps below: 4. Build the solution to restore NuGet packages and compile the code. 5. Configure the necessary database connection settings in the `appsettings.json` file of the Infrastructure project. 6. Open the Package Manager Console, select `Project.Infrastructure` project, and run the `Update-Database` command to create the database. +dotnet ef migrations add CreateIdentitySchema --project ../Project.Infrastructure --startup-project ../Project.API + +dotnet ef database update --project ../Project.Infrastructure --startup-project ../Project.API + 7. Run the application by starting the `Project.API` project. ## Project Features