diff --git a/src/HelloShop.IdentityService/Constants/DbConstants.cs b/src/HelloShop.IdentityService/Constants/DbConstants.cs index d640922..c81a85d 100644 --- a/src/HelloShop.IdentityService/Constants/DbConstants.cs +++ b/src/HelloShop.IdentityService/Constants/DbConstants.cs @@ -6,5 +6,7 @@ namespace HelloShop.IdentityService.Constants public class DbConstants { public const string ConnectionStringName = "IdentityDatabase"; + + public const string MigrationsHistoryTableName = "migrations_history"; } } diff --git a/src/HelloShop.IdentityService/HelloShop.IdentityService.csproj b/src/HelloShop.IdentityService/HelloShop.IdentityService.csproj index 997f47f..866e2d3 100644 --- a/src/HelloShop.IdentityService/HelloShop.IdentityService.csproj +++ b/src/HelloShop.IdentityService/HelloShop.IdentityService.csproj @@ -8,6 +8,7 @@ + diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs index 66fed53..8c47045 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/PermissionGrantedEntityTypeConfiguration.cs @@ -10,8 +10,6 @@ public class PermissionGrantedEntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder builder) { - builder.ToTable("PermissionGranted"); - builder.Property(x => x.Id); builder.Property(x => x.PermissionName).HasMaxLength(64); builder.Property(x => x.ResourceType).HasMaxLength(16); diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs index 595c729..dd0019e 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleClaimEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder> builder) { - builder.ToTable("RoleClaims"); + builder.ToTable("role_claim"); builder.Property(rc => rc.ClaimType).HasMaxLength(128); } diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs index f7802f1..a8e0867 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Roles"); + builder.ToTable("role"); builder.Property(r => r.Id).HasColumnOrder(1); builder.Property(r => r.Name).HasMaxLength(16).HasColumnOrder(2); diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs index 97107f7..d012721 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserClaimEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder> builder) { - builder.ToTable("UserClaims"); + builder.ToTable("user_claim"); builder.Property(uc => uc.ClaimType).HasMaxLength(128); } diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs index 6693c88..a311ec1 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Users"); + builder.ToTable("user"); builder.Property(u => u.Id).HasColumnOrder(1); builder.Property(u => u.UserName).HasMaxLength(16).HasColumnOrder(2); diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs index 0d6f408..cff628d 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserLoginEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder> builder) { - builder.ToTable("UserLogins"); + builder.ToTable("user_login"); builder.Property(ul => ul.LoginProvider).HasMaxLength(16); builder.Property(ul => ul.ProviderDisplayName).HasMaxLength(16); diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs index 91f9101..1bb3d00 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserRoleEntityTypeConfiguration.cs @@ -10,7 +10,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder> builder) { - builder.ToTable("UserRoles"); + builder.ToTable("user_role"); } } } diff --git a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs index 5576364..35eb976 100644 --- a/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs +++ b/src/HelloShop.IdentityService/Infrastructure/EntityConfigurations/UserTokenEntityTypeConfiguration.cs @@ -11,7 +11,7 @@ namespace HelloShop.IdentityService.Infrastructure.EntityConfigurations { public void Configure(EntityTypeBuilder> builder) { - builder.ToTable("UserTokens"); + builder.ToTable("user_token"); builder.Property(ut => ut.Name).HasMaxLength(16); builder.Property(ut => ut.LoginProvider).HasMaxLength(16); diff --git a/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs index a7b4fbc..d8e6023 100644 --- a/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs +++ b/src/HelloShop.IdentityService/Infrastructure/IdentityServiceDbContext.cs @@ -13,8 +13,13 @@ namespace HelloShop.IdentityService.Infrastructure protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder.UseSnakeCaseNamingConvention(); + } } } diff --git a/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.cs deleted file mode 100644 index 777f742..0000000 --- a/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.cs +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright (c) HelloShop Corporation. All rights reserved. -// See the license file in the project root for more information. - -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace HelloShop.IdentityService.EntityFrameworks.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Roles", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - NormalizedName = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - ConcurrencyStamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), - CreationTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Roles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserName = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - NormalizedUserName = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - Email = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), - NormalizedEmail = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "character varying(512)", maxLength: 512, nullable: true), - SecurityStamp = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), - ConcurrencyStamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), - PhoneNumber = table.Column(type: "character varying(16)", maxLength: 16, 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), - CreationTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "PermissionGranted", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "integer", nullable: false), - PermissionName = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), - ResourceType = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - ResourceId = table.Column(type: "character varying(32)", maxLength: 32, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PermissionGranted", x => x.Id); - table.ForeignKey( - name: "FK_PermissionGranted_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "RoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "integer", nullable: false), - ClaimType = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_RoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_RoleClaims_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - ClaimType = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserClaims", x => x.Id); - table.ForeignKey( - name: "FK_UserClaims_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), - UserId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_UserLogins_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserRoles", - columns: table => new - { - UserId = table.Column(type: "integer", nullable: false), - RoleId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_UserRoles_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRoles_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserTokens", - columns: table => new - { - UserId = table.Column(type: "integer", nullable: false), - LoginProvider = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - Name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - Value = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_UserTokens_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_PermissionGranted_RoleId_PermissionName_ResourceType_Resour~", - table: "PermissionGranted", - columns: new[] { "RoleId", "PermissionName", "ResourceType", "ResourceId" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_RoleClaims_RoleId", - table: "RoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "Roles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_UserClaims_UserId", - table: "UserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserLogins_UserId", - table: "UserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRoles_RoleId", - table: "UserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "Users", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "Users", - column: "NormalizedUserName", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "PermissionGranted"); - - migrationBuilder.DropTable( - name: "RoleClaims"); - - migrationBuilder.DropTable( - name: "UserClaims"); - - migrationBuilder.DropTable( - name: "UserLogins"); - - migrationBuilder.DropTable( - name: "UserRoles"); - - migrationBuilder.DropTable( - name: "UserTokens"); - - migrationBuilder.DropTable( - name: "Roles"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} diff --git a/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.Designer.cs similarity index 63% rename from src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs rename to src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.Designer.cs index 1802852..c88c935 100644 --- a/src/HelloShop.IdentityService/Infrastructure/Migrations/20240403122821_InitialCreate.Designer.cs +++ b/src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.Designer.cs @@ -9,10 +9,10 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace HelloShop.IdentityService.EntityFrameworks.Migrations +namespace HelloShop.IdentityService.Infrastructure.Migrations { [DbContext(typeof(IdentityServiceDbContext))] - [Migration("20240403122821_InitialCreate")] + [Migration("20241123020852_InitialCreate")] partial class InitialCreate { /// @@ -20,7 +20,7 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -29,32 +29,39 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("PermissionName") .IsRequired() .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("character varying(64)") + .HasColumnName("permission_name"); b.Property("ResourceId") .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasColumnType("character varying(32)") + .HasColumnName("resource_id"); b.Property("ResourceType") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("resource_type"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_permission_granted"); b.HasIndex("RoleId", "PermissionName", "ResourceType", "ResourceId") - .IsUnique(); + .IsUnique() + .HasDatabaseName("ix_permission_granted_role_id_permission_name_resource_type_re"); - b.ToTable("PermissionGranted", (string)null); + b.ToTable("permission_granted", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.Role", b => @@ -62,6 +69,7 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("integer") + .HasColumnName("id") .HasColumnOrder(1); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); @@ -70,29 +78,34 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .IsConcurrencyToken() .HasMaxLength(64) .HasColumnType("character varying(64)") + .HasColumnName("concurrency_stamp") .HasColumnOrder(4); b.Property("CreationTime") .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time") .HasColumnOrder(5); b.Property("Name") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("name") .HasColumnOrder(2); b.Property("NormalizedName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("normalized_name") .HasColumnOrder(3); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_role"); b.HasIndex("NormalizedName") .IsUnique() .HasDatabaseName("RoleNameIndex"); - b.ToTable("Roles", (string)null); + b.ToTable("role", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.User", b => @@ -100,80 +113,97 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("integer") + .HasColumnName("id") .HasColumnOrder(1); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("AccessFailedCount") .HasColumnType("integer") + .HasColumnName("access_failed_count") .HasColumnOrder(15); b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasMaxLength(64) .HasColumnType("character varying(64)") + .HasColumnName("concurrency_stamp") .HasColumnOrder(9); b.Property("CreationTime") .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time") .HasColumnOrder(16); b.Property("Email") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("email") .HasColumnOrder(4); b.Property("EmailConfirmed") .HasColumnType("boolean") + .HasColumnName("email_confirmed") .HasColumnOrder(6); b.Property("LockoutEnabled") .HasColumnType("boolean") + .HasColumnName("lockout_enabled") .HasColumnOrder(14); b.Property("LockoutEnd") .HasColumnType("timestamp with time zone") + .HasColumnName("lockout_end") .HasColumnOrder(13); b.Property("NormalizedEmail") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("normalized_email") .HasColumnOrder(5); b.Property("NormalizedUserName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("normalized_user_name") .HasColumnOrder(3); b.Property("PasswordHash") .HasMaxLength(512) .HasColumnType("character varying(512)") + .HasColumnName("password_hash") .HasColumnOrder(7); b.Property("PhoneNumber") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("phone_number") .HasColumnOrder(10); b.Property("PhoneNumberConfirmed") .HasColumnType("boolean") + .HasColumnName("phone_number_confirmed") .HasColumnOrder(11); b.Property("SecurityStamp") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("security_stamp") .HasColumnOrder(8); b.Property("TwoFactorEnabled") .HasColumnType("boolean") + .HasColumnName("two_factor_enabled") .HasColumnOrder(12); b.Property("UserName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("user_name") .HasColumnOrder(2); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_user"); b.HasIndex("NormalizedEmail") .HasDatabaseName("EmailIndex"); @@ -182,116 +212,143 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .IsUnique() .HasDatabaseName("UserNameIndex"); - b.ToTable("Users", (string)null); + b.ToTable("user", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") .HasMaxLength(128) - .HasColumnType("character varying(128)"); + .HasColumnType("character varying(128)") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_role_claim"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_role_claim_role_id"); - b.ToTable("RoleClaims", (string)null); + b.ToTable("role_claim", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") .HasMaxLength(128) - .HasColumnType("character varying(128)"); + .HasColumnType("character varying(128)") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_user_claim"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_user_claim_user_id"); - b.ToTable("UserClaims", (string)null); + b.ToTable("user_claim", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("login_provider"); b.Property("ProviderKey") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("provider_key"); b.Property("ProviderDisplayName") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("provider_display_name"); b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); - b.HasKey("LoginProvider", "ProviderKey"); + b.HasKey("LoginProvider", "ProviderKey") + .HasName("pk_user_login"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_user_login_user_id"); - b.ToTable("UserLogins", (string)null); + b.ToTable("user_login", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("UserId", "RoleId"); + b.HasKey("UserId", "RoleId") + .HasName("pk_user_role"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_user_role_role_id"); - b.ToTable("UserRoles", (string)null); + b.ToTable("user_role", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); b.Property("LoginProvider") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("login_provider"); b.Property("Name") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("name"); b.Property("Value") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("value"); - b.HasKey("UserId", "LoginProvider", "Name"); + b.HasKey("UserId", "LoginProvider", "Name") + .HasName("pk_user_token"); - b.ToTable("UserTokens", (string)null); + b.ToTable("user_token", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.PermissionGranted", b => @@ -300,7 +357,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_permission_granted_asp_net_roles_role_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -309,7 +367,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_role_claim_asp_net_roles_role_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => @@ -318,7 +377,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_claim_asp_net_users_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => @@ -327,7 +387,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_login_user_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -336,13 +397,15 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_role_role_role_id"); b.HasOne("HelloShop.IdentityService.Entities.User", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_role_user_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -351,7 +414,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_token_user_user_id"); }); #pragma warning restore 612, 618 } diff --git a/src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.cs new file mode 100644 index 0000000..e4cb9c0 --- /dev/null +++ b/src/HelloShop.IdentityService/Infrastructure/Migrations/20241123020852_InitialCreate.cs @@ -0,0 +1,258 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.IdentityService.Infrastructure.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + normalized_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + concurrency_stamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), + creation_time = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_role", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + user_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + normalized_user_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + email = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), + normalized_email = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), + email_confirmed = table.Column(type: "boolean", nullable: false), + password_hash = table.Column(type: "character varying(512)", maxLength: 512, nullable: true), + security_stamp = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), + concurrency_stamp = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), + phone_number = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + phone_number_confirmed = table.Column(type: "boolean", nullable: false), + two_factor_enabled = table.Column(type: "boolean", nullable: false), + lockout_end = table.Column(type: "timestamp with time zone", nullable: true), + lockout_enabled = table.Column(type: "boolean", nullable: false), + access_failed_count = table.Column(type: "integer", nullable: false), + creation_time = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_user", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "permission_granted", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + role_id = table.Column(type: "integer", nullable: false), + permission_name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), + resource_type = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + resource_id = table.Column(type: "character varying(32)", maxLength: 32, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_permission_granted", x => x.id); + table.ForeignKey( + name: "fk_permission_granted_asp_net_roles_role_id", + column: x => x.role_id, + principalTable: "role", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "role_claim", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + role_id = table.Column(type: "integer", nullable: false), + claim_type = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), + claim_value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_role_claim", x => x.id); + table.ForeignKey( + name: "fk_role_claim_asp_net_roles_role_id", + column: x => x.role_id, + principalTable: "role", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_claim", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + user_id = table.Column(type: "integer", nullable: false), + claim_type = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), + claim_value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_user_claim", x => x.id); + table.ForeignKey( + name: "fk_user_claim_asp_net_users_user_id", + column: x => x.user_id, + principalTable: "user", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_login", + columns: table => new + { + login_provider = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + provider_key = table.Column(type: "text", nullable: false), + provider_display_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + user_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_user_login", x => new { x.login_provider, x.provider_key }); + table.ForeignKey( + name: "fk_user_login_user_user_id", + column: x => x.user_id, + principalTable: "user", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + user_id = table.Column(type: "integer", nullable: false), + role_id = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_user_role", x => new { x.user_id, x.role_id }); + table.ForeignKey( + name: "fk_user_role_role_role_id", + column: x => x.role_id, + principalTable: "role", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_user_role_user_user_id", + column: x => x.user_id, + principalTable: "user", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_token", + columns: table => new + { + user_id = table.Column(type: "integer", nullable: false), + login_provider = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_user_token", x => new { x.user_id, x.login_provider, x.name }); + table.ForeignKey( + name: "fk_user_token_user_user_id", + column: x => x.user_id, + principalTable: "user", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_permission_granted_role_id_permission_name_resource_type_re", + table: "permission_granted", + columns: new[] { "role_id", "permission_name", "resource_type", "resource_id" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "role", + column: "normalized_name", + unique: true); + + migrationBuilder.CreateIndex( + name: "ix_role_claim_role_id", + table: "role_claim", + column: "role_id"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "user", + column: "normalized_email"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "user", + column: "normalized_user_name", + unique: true); + + migrationBuilder.CreateIndex( + name: "ix_user_claim_user_id", + table: "user_claim", + column: "user_id"); + + migrationBuilder.CreateIndex( + name: "ix_user_login_user_id", + table: "user_login", + column: "user_id"); + + migrationBuilder.CreateIndex( + name: "ix_user_role_role_id", + table: "user_role", + column: "role_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "permission_granted"); + + migrationBuilder.DropTable( + name: "role_claim"); + + migrationBuilder.DropTable( + name: "user_claim"); + + migrationBuilder.DropTable( + name: "user_login"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "user_token"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs b/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs index f4e4dc2..0d846b0 100644 --- a/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs +++ b/src/HelloShop.IdentityService/Infrastructure/Migrations/IdentityServiceDbContextModelSnapshot.cs @@ -8,7 +8,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace HelloShop.IdentityService.EntityFrameworks.Migrations +namespace HelloShop.IdentityService.Infrastructure.Migrations { [DbContext(typeof(IdentityServiceDbContext))] partial class IdentityServiceDbContextModelSnapshot : ModelSnapshot @@ -17,7 +17,7 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.2") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -26,32 +26,39 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("PermissionName") .IsRequired() .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("character varying(64)") + .HasColumnName("permission_name"); b.Property("ResourceId") .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasColumnType("character varying(32)") + .HasColumnName("resource_id"); b.Property("ResourceType") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("resource_type"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_permission_granted"); b.HasIndex("RoleId", "PermissionName", "ResourceType", "ResourceId") - .IsUnique(); + .IsUnique() + .HasDatabaseName("ix_permission_granted_role_id_permission_name_resource_type_re"); - b.ToTable("PermissionGranted", (string)null); + b.ToTable("permission_granted", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.Role", b => @@ -59,6 +66,7 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("integer") + .HasColumnName("id") .HasColumnOrder(1); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); @@ -67,29 +75,34 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .IsConcurrencyToken() .HasMaxLength(64) .HasColumnType("character varying(64)") + .HasColumnName("concurrency_stamp") .HasColumnOrder(4); b.Property("CreationTime") .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time") .HasColumnOrder(5); b.Property("Name") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("name") .HasColumnOrder(2); b.Property("NormalizedName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("normalized_name") .HasColumnOrder(3); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_role"); b.HasIndex("NormalizedName") .IsUnique() .HasDatabaseName("RoleNameIndex"); - b.ToTable("Roles", (string)null); + b.ToTable("role", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.User", b => @@ -97,80 +110,97 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("integer") + .HasColumnName("id") .HasColumnOrder(1); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("AccessFailedCount") .HasColumnType("integer") + .HasColumnName("access_failed_count") .HasColumnOrder(15); b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasMaxLength(64) .HasColumnType("character varying(64)") + .HasColumnName("concurrency_stamp") .HasColumnOrder(9); b.Property("CreationTime") .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time") .HasColumnOrder(16); b.Property("Email") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("email") .HasColumnOrder(4); b.Property("EmailConfirmed") .HasColumnType("boolean") + .HasColumnName("email_confirmed") .HasColumnOrder(6); b.Property("LockoutEnabled") .HasColumnType("boolean") + .HasColumnName("lockout_enabled") .HasColumnOrder(14); b.Property("LockoutEnd") .HasColumnType("timestamp with time zone") + .HasColumnName("lockout_end") .HasColumnOrder(13); b.Property("NormalizedEmail") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("normalized_email") .HasColumnOrder(5); b.Property("NormalizedUserName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("normalized_user_name") .HasColumnOrder(3); b.Property("PasswordHash") .HasMaxLength(512) .HasColumnType("character varying(512)") + .HasColumnName("password_hash") .HasColumnOrder(7); b.Property("PhoneNumber") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("phone_number") .HasColumnOrder(10); b.Property("PhoneNumberConfirmed") .HasColumnType("boolean") + .HasColumnName("phone_number_confirmed") .HasColumnOrder(11); b.Property("SecurityStamp") .HasMaxLength(32) .HasColumnType("character varying(32)") + .HasColumnName("security_stamp") .HasColumnOrder(8); b.Property("TwoFactorEnabled") .HasColumnType("boolean") + .HasColumnName("two_factor_enabled") .HasColumnOrder(12); b.Property("UserName") .HasMaxLength(16) .HasColumnType("character varying(16)") + .HasColumnName("user_name") .HasColumnOrder(2); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_user"); b.HasIndex("NormalizedEmail") .HasDatabaseName("EmailIndex"); @@ -179,116 +209,143 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .IsUnique() .HasDatabaseName("UserNameIndex"); - b.ToTable("Users", (string)null); + b.ToTable("user", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") .HasMaxLength(128) - .HasColumnType("character varying(128)"); + .HasColumnType("character varying(128)") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_role_claim"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_role_claim_role_id"); - b.ToTable("RoleClaims", (string)null); + b.ToTable("role_claim", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") .HasMaxLength(128) - .HasColumnType("character varying(128)"); + .HasColumnType("character varying(128)") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_user_claim"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_user_claim_user_id"); - b.ToTable("UserClaims", (string)null); + b.ToTable("user_claim", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("login_provider"); b.Property("ProviderKey") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("provider_key"); b.Property("ProviderDisplayName") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("provider_display_name"); b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); - b.HasKey("LoginProvider", "ProviderKey"); + b.HasKey("LoginProvider", "ProviderKey") + .HasName("pk_user_login"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_user_login_user_id"); - b.ToTable("UserLogins", (string)null); + b.ToTable("user_login", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); b.Property("RoleId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("role_id"); - b.HasKey("UserId", "RoleId"); + b.HasKey("UserId", "RoleId") + .HasName("pk_user_role"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_user_role_role_id"); - b.ToTable("UserRoles", (string)null); + b.ToTable("user_role", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("user_id"); b.Property("LoginProvider") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("login_provider"); b.Property("Name") .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("name"); b.Property("Value") - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("value"); - b.HasKey("UserId", "LoginProvider", "Name"); + b.HasKey("UserId", "LoginProvider", "Name") + .HasName("pk_user_token"); - b.ToTable("UserTokens", (string)null); + b.ToTable("user_token", (string)null); }); modelBuilder.Entity("HelloShop.IdentityService.Entities.PermissionGranted", b => @@ -297,7 +354,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_permission_granted_asp_net_roles_role_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -306,7 +364,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_role_claim_asp_net_roles_role_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => @@ -315,7 +374,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_claim_asp_net_users_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => @@ -324,7 +384,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_login_user_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -333,13 +394,15 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_role_role_role_id"); b.HasOne("HelloShop.IdentityService.Entities.User", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_role_user_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -348,7 +411,8 @@ namespace HelloShop.IdentityService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_user_token_user_user_id"); }); #pragma warning restore 612, 618 } diff --git a/src/HelloShop.IdentityService/Program.cs b/src/HelloShop.IdentityService/Program.cs index 2891143..b0f000e 100644 --- a/src/HelloShop.IdentityService/Program.cs +++ b/src/HelloShop.IdentityService/Program.cs @@ -23,7 +23,7 @@ builder.Services.AddControllers(); builder.Services.AddDbContext(options => { - options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.ConnectionStringName)); + options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.ConnectionStringName),x=>x.MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName)); }); builder.Services.AddIdentity(options => diff --git a/src/HelloShop.IdentityService/appsettings.json b/src/HelloShop.IdentityService/appsettings.json index 553fd17..c972fa3 100644 --- a/src/HelloShop.IdentityService/appsettings.json +++ b/src/HelloShop.IdentityService/appsettings.json @@ -6,7 +6,7 @@ } }, "ConnectionStrings": { - "IdentityDatabase": "Host=localhost;Port=5432;Database=IdentityService;Username=postgres;Password=postgres" + "IdentityDatabase": "Host=localhost;Port=5432;Database=identity;Username=postgres;Password=postgres" }, "AllowedHosts": "*" } diff --git a/src/HelloShop.OrderingService/Constants/DbConstants.cs b/src/HelloShop.OrderingService/Constants/DbConstants.cs index 1b28bc3..73f802b 100644 --- a/src/HelloShop.OrderingService/Constants/DbConstants.cs +++ b/src/HelloShop.OrderingService/Constants/DbConstants.cs @@ -8,5 +8,7 @@ namespace HelloShop.OrderingService.Constants public const string MasterConnectionStringName = "OrderingDatabaseMaster"; public const string SlaveConnectionStringName = "OrderingDatabaseSlave"; + + public const string MigrationsHistoryTableName = "migrations_history"; } } diff --git a/src/HelloShop.OrderingService/Extensions/Extensions.cs b/src/HelloShop.OrderingService/Extensions/Extensions.cs index ca32352..a5c178b 100644 --- a/src/HelloShop.OrderingService/Extensions/Extensions.cs +++ b/src/HelloShop.OrderingService/Extensions/Extensions.cs @@ -36,7 +36,8 @@ namespace HelloShop.OrderingService.Extensions builder.Services.AddDbContext(options => { - options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName)); + options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName), x => x.MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName)); + options.UseSnakeCaseNamingConvention(); }); builder.Services.AddScoped(); diff --git a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj index 210ccca..34f5553 100644 --- a/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj +++ b/src/HelloShop.OrderingService/HelloShop.OrderingService.csproj @@ -8,6 +8,7 @@ + diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs index 3f80e5b..52b841c 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/BuyerEntityTypeConfiguration.cs @@ -11,7 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Buyer"); builder.Property(x => x.Name).HasMaxLength(16).IsRequired(); builder.HasMany(b => b.PaymentMethods).WithOne().HasForeignKey(x => x.BuyerId).OnDelete(DeleteBehavior.Cascade); } diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs index ca696b1..4ad9f8f 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Buyers/PaymentMethodEntityTypeConfiguration.cs @@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("PaymentMethods"); - builder.Property(x => x.Alias).HasMaxLength(16); builder.Property(x => x.CardNumber).HasMaxLength(16); builder.Property(x => x.CardHolderName).HasMaxLength(16); diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs index 4e17d4d..a34e235 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/EventLogs/DistributedEventLogEntityTypeConfiguration.cs @@ -15,8 +15,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.EventLog public void Configure(EntityTypeBuilder builder) { - builder.ToTable("DistributedEventLogs"); - builder.HasKey(x => x.EventId); builder.Property(x => x.EventTypeName).HasMaxLength(32); builder.Property(x => x.Status).HasConversion(); diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Idempotency/ClientRequestEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Idempotency/ClientRequestEntityTypeConfiguration.cs index f87c1cc..db0cda4 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Idempotency/ClientRequestEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Idempotency/ClientRequestEntityTypeConfiguration.cs @@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Idempote { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("ClientRequests"); - builder.HasKey(t => t.Id); builder.Property(t => t.Name).HasMaxLength(64); diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs index 90f707a..b6e38cb 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderEntityTypeConfiguration.cs @@ -12,8 +12,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Orders"); - builder.Property(x => x.Description).HasMaxLength(64); builder.Property(x => x.OrderStatus).HasConversion(); diff --git a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs index 4c2afe7..e7c0f46 100644 --- a/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs +++ b/src/HelloShop.OrderingService/Infrastructure/EntityConfigurations/Orders/OrderItemEntityTypeConfiguration.cs @@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("OrderItems"); - builder.Property(x => x.ProductName).HasMaxLength(16); builder.Property(x => x.PictureUrl).HasMaxLength(256); } diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs deleted file mode 100644 index 45433aa..0000000 --- a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) HelloShop Corporation. All rights reserved. -// See the license file in the project root for more information. - -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace HelloShop.OrderingService.Infrastructure.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Buyer", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Buyer", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "PaymentMethods", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - BuyerId = table.Column(type: "integer", nullable: false), - Alias = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - CardNumber = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - CardHolderName = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - SecurityNumber = table.Column(type: "character varying(6)", maxLength: 6, nullable: true), - Expiration = table.Column(type: "timestamp with time zone", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PaymentMethods", x => x.Id); - table.ForeignKey( - name: "FK_PaymentMethods_Buyer_BuyerId", - column: x => x.BuyerId, - principalTable: "Buyer", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - OrderDate = table.Column(type: "timestamp with time zone", nullable: false), - Country = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), - State = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - City = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - Street = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), - ZipCode = table.Column(type: "character varying(6)", maxLength: 6, nullable: false), - OrderStatus = table.Column(type: "text", nullable: false), - BuyerId = table.Column(type: "integer", nullable: false), - PaymentMethodId = table.Column(type: "integer", nullable: true), - Description = table.Column(type: "character varying(64)", maxLength: 64, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Buyer_BuyerId", - column: x => x.BuyerId, - principalTable: "Buyer", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_PaymentMethods_PaymentMethodId", - column: x => x.PaymentMethodId, - principalTable: "PaymentMethods", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "OrderItems", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - OrderId = table.Column(type: "integer", nullable: false), - ProductId = table.Column(type: "integer", nullable: false), - ProductName = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), - PictureUrl = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), - UnitPrice = table.Column(type: "numeric", nullable: false), - Units = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderItems", x => x.Id); - table.ForeignKey( - name: "FK_OrderItems_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_OrderId", - table: "OrderItems", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_BuyerId", - table: "Orders", - column: "BuyerId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_PaymentMethodId", - table: "Orders", - column: "PaymentMethodId"); - - migrationBuilder.CreateIndex( - name: "IX_PaymentMethods_BuyerId", - table: "PaymentMethods", - column: "BuyerId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "OrderItems"); - - migrationBuilder.DropTable( - name: "Orders"); - - migrationBuilder.DropTable( - name: "PaymentMethods"); - - migrationBuilder.DropTable( - name: "Buyer"); - } - } -} diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.Designer.cs similarity index 52% rename from src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs rename to src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.Designer.cs index 268cbb1..9b1f81c 100644 --- a/src/HelloShop.OrderingService/Infrastructure/Migrations/20240829142135_InitialCreate.Designer.cs +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace HelloShop.OrderingService.Infrastructure.Migrations { [DbContext(typeof(OrderingServiceDbContext))] - [Migration("20240829142135_InitialCreate")] + [Migration("20241123020913_InitialCreate")] partial class InitialCreate { /// @@ -20,7 +20,7 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -29,129 +29,223 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Name") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_buyer"); - b.ToTable("Buyer", (string)null); + b.ToTable("buyer", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Alias") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("alias"); b.Property("BuyerId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("buyer_id"); b.Property("CardHolderName") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("card_holder_name"); b.Property("CardNumber") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("card_number"); b.Property("Expiration") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("expiration"); b.Property("SecurityNumber") .HasMaxLength(6) - .HasColumnType("character varying(6)"); + .HasColumnType("character varying(6)") + .HasColumnName("security_number"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_payment_method"); - b.HasIndex("BuyerId"); + b.HasIndex("BuyerId") + .HasDatabaseName("ix_payment_method_buyer_id"); - b.ToTable("PaymentMethods", (string)null); + b.ToTable("payment_method", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.EventLogs.DistributedEventLog", b => + { + b.Property("EventId") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("event_id"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time"); + + b.Property("DistributedEvent") + .IsRequired() + .HasColumnType("text") + .HasColumnName("distributed_event"); + + b.Property("EventTypeName") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)") + .HasColumnName("event_type_name"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text") + .HasColumnName("status"); + + b.Property("TimesSent") + .HasColumnType("integer") + .HasColumnName("times_sent"); + + b.Property("TransactionId") + .HasColumnType("uuid") + .HasColumnName("transaction_id"); + + b.HasKey("EventId") + .HasName("pk_distributed_event_log"); + + b.ToTable("distributed_event_log", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Idempotency.ClientRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)") + .HasColumnName("name"); + + b.Property("Time") + .HasColumnType("timestamp with time zone") + .HasColumnName("time"); + + b.HasKey("Id") + .HasName("pk_client_request"); + + b.ToTable("client_request", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("buyer_id"); b.Property("Description") .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("character varying(64)") + .HasColumnName("description"); b.Property("OrderDate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("order_date"); b.Property("OrderStatus") .IsRequired() - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("order_status"); b.Property("PaymentMethodId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("payment_method_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_order"); - b.HasIndex("BuyerId"); + b.HasIndex("BuyerId") + .HasDatabaseName("ix_order_buyer_id"); - b.HasIndex("PaymentMethodId"); + b.HasIndex("PaymentMethodId") + .HasDatabaseName("ix_order_payment_method_id"); - b.ToTable("Orders", (string)null); + b.ToTable("order", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("OrderId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("order_id"); b.Property("PictureUrl") .IsRequired() .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("picture_url"); b.Property("ProductId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("product_id"); b.Property("ProductName") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("product_name"); b.Property("UnitPrice") - .HasColumnType("numeric"); + .HasColumnType("numeric") + .HasColumnName("unit_price"); b.Property("Units") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("units"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_order_item"); - b.HasIndex("OrderId"); + b.HasIndex("OrderId") + .HasDatabaseName("ix_order_item_order_id"); - b.ToTable("OrderItems", (string)null); + b.ToTable("order_item", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => @@ -160,7 +254,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany("PaymentMethods") .HasForeignKey("BuyerId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_payment_method_buyer_buyer_id"); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => @@ -169,17 +264,20 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany() .HasForeignKey("BuyerId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_order_buyer_buyer_id"); b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null) .WithMany() .HasForeignKey("PaymentMethodId") - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("fk_order_payment_method_payment_method_id"); b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 => { b1.Property("OrderId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); b1.Property("City") .IsRequired() @@ -213,10 +311,11 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations b1.HasKey("OrderId"); - b1.ToTable("Orders"); + b1.ToTable("order"); b1.WithOwner() - .HasForeignKey("OrderId"); + .HasForeignKey("OrderId") + .HasConstraintName("fk_order_order_id"); }); b.Navigation("Address") @@ -229,7 +328,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany("OrderItems") .HasForeignKey("OrderId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_order_item_order_order_id"); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.cs new file mode 100644 index 0000000..9fc75dd --- /dev/null +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/20241123020913_InitialCreate.cs @@ -0,0 +1,183 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.OrderingService.Infrastructure.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "buyer", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_buyer", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "client_request", + columns: table => new + { + id = table.Column(type: "uuid", nullable: false), + name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), + time = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_client_request", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "distributed_event_log", + columns: table => new + { + event_id = table.Column(type: "uuid", nullable: false), + event_type_name = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), + distributed_event = table.Column(type: "text", nullable: false), + status = table.Column(type: "text", nullable: false), + times_sent = table.Column(type: "integer", nullable: false), + creation_time = table.Column(type: "timestamp with time zone", nullable: false), + transaction_id = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_distributed_event_log", x => x.event_id); + }); + + migrationBuilder.CreateTable( + name: "payment_method", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + buyer_id = table.Column(type: "integer", nullable: false), + alias = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + card_number = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + card_holder_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + security_number = table.Column(type: "character varying(6)", maxLength: 6, nullable: true), + expiration = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_payment_method", x => x.id); + table.ForeignKey( + name: "fk_payment_method_buyer_buyer_id", + column: x => x.buyer_id, + principalTable: "buyer", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "order", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + order_date = table.Column(type: "timestamp with time zone", nullable: false), + Country = table.Column(type: "character varying(8)", maxLength: 8, nullable: false), + State = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + City = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + Street = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), + ZipCode = table.Column(type: "character varying(6)", maxLength: 6, nullable: false), + order_status = table.Column(type: "text", nullable: false), + buyer_id = table.Column(type: "integer", nullable: false), + payment_method_id = table.Column(type: "integer", nullable: true), + description = table.Column(type: "character varying(64)", maxLength: 64, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_order", x => x.id); + table.ForeignKey( + name: "fk_order_buyer_buyer_id", + column: x => x.buyer_id, + principalTable: "buyer", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_order_payment_method_payment_method_id", + column: x => x.payment_method_id, + principalTable: "payment_method", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "order_item", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + order_id = table.Column(type: "integer", nullable: false), + product_id = table.Column(type: "integer", nullable: false), + product_name = table.Column(type: "character varying(16)", maxLength: 16, nullable: false), + picture_url = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), + unit_price = table.Column(type: "numeric", nullable: false), + units = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_order_item", x => x.id); + table.ForeignKey( + name: "fk_order_item_order_order_id", + column: x => x.order_id, + principalTable: "order", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_order_buyer_id", + table: "order", + column: "buyer_id"); + + migrationBuilder.CreateIndex( + name: "ix_order_payment_method_id", + table: "order", + column: "payment_method_id"); + + migrationBuilder.CreateIndex( + name: "ix_order_item_order_id", + table: "order_item", + column: "order_id"); + + migrationBuilder.CreateIndex( + name: "ix_payment_method_buyer_id", + table: "payment_method", + column: "buyer_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "client_request"); + + migrationBuilder.DropTable( + name: "distributed_event_log"); + + migrationBuilder.DropTable( + name: "order_item"); + + migrationBuilder.DropTable( + name: "order"); + + migrationBuilder.DropTable( + name: "payment_method"); + + migrationBuilder.DropTable( + name: "buyer"); + } + } +} diff --git a/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs b/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs index 1aaa316..c3721e3 100644 --- a/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/src/HelloShop.OrderingService/Infrastructure/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -26,129 +26,223 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Name") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_buyer"); - b.ToTable("Buyer", (string)null); + b.ToTable("buyer", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Alias") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("alias"); b.Property("BuyerId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("buyer_id"); b.Property("CardHolderName") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("card_holder_name"); b.Property("CardNumber") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("card_number"); b.Property("Expiration") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("expiration"); b.Property("SecurityNumber") .HasMaxLength(6) - .HasColumnType("character varying(6)"); + .HasColumnType("character varying(6)") + .HasColumnName("security_number"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_payment_method"); - b.HasIndex("BuyerId"); + b.HasIndex("BuyerId") + .HasDatabaseName("ix_payment_method_buyer_id"); - b.ToTable("PaymentMethods", (string)null); + b.ToTable("payment_method", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.EventLogs.DistributedEventLog", b => + { + b.Property("EventId") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("event_id"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time"); + + b.Property("DistributedEvent") + .IsRequired() + .HasColumnType("text") + .HasColumnName("distributed_event"); + + b.Property("EventTypeName") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)") + .HasColumnName("event_type_name"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text") + .HasColumnName("status"); + + b.Property("TimesSent") + .HasColumnType("integer") + .HasColumnName("times_sent"); + + b.Property("TransactionId") + .HasColumnType("uuid") + .HasColumnName("transaction_id"); + + b.HasKey("EventId") + .HasName("pk_distributed_event_log"); + + b.ToTable("distributed_event_log", (string)null); + }); + + modelBuilder.Entity("HelloShop.OrderingService.Entities.Idempotency.ClientRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("id"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)") + .HasColumnName("name"); + + b.Property("Time") + .HasColumnType("timestamp with time zone") + .HasColumnName("time"); + + b.HasKey("Id") + .HasName("pk_client_request"); + + b.ToTable("client_request", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("BuyerId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("buyer_id"); b.Property("Description") .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("character varying(64)") + .HasColumnName("description"); b.Property("OrderDate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("order_date"); b.Property("OrderStatus") .IsRequired() - .HasColumnType("text"); + .HasColumnType("text") + .HasColumnName("order_status"); b.Property("PaymentMethodId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("payment_method_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_order"); - b.HasIndex("BuyerId"); + b.HasIndex("BuyerId") + .HasDatabaseName("ix_order_buyer_id"); - b.HasIndex("PaymentMethodId"); + b.HasIndex("PaymentMethodId") + .HasDatabaseName("ix_order_payment_method_id"); - b.ToTable("Orders", (string)null); + b.ToTable("order", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("OrderId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("order_id"); b.Property("PictureUrl") .IsRequired() .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("picture_url"); b.Property("ProductId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("product_id"); b.Property("ProductName") .IsRequired() .HasMaxLength(16) - .HasColumnType("character varying(16)"); + .HasColumnType("character varying(16)") + .HasColumnName("product_name"); b.Property("UnitPrice") - .HasColumnType("numeric"); + .HasColumnType("numeric") + .HasColumnName("unit_price"); b.Property("Units") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("units"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_order_item"); - b.HasIndex("OrderId"); + b.HasIndex("OrderId") + .HasDatabaseName("ix_order_item_order_id"); - b.ToTable("OrderItems", (string)null); + b.ToTable("order_item", (string)null); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b => @@ -157,7 +251,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany("PaymentMethods") .HasForeignKey("BuyerId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_payment_method_buyer_buyer_id"); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b => @@ -166,17 +261,20 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany() .HasForeignKey("BuyerId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_order_buyer_buyer_id"); b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null) .WithMany() .HasForeignKey("PaymentMethodId") - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.Restrict) + .HasConstraintName("fk_order_payment_method_payment_method_id"); b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 => { b1.Property("OrderId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); b1.Property("City") .IsRequired() @@ -210,10 +308,11 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations b1.HasKey("OrderId"); - b1.ToTable("Orders"); + b1.ToTable("order"); b1.WithOwner() - .HasForeignKey("OrderId"); + .HasForeignKey("OrderId") + .HasConstraintName("fk_order_order_id"); }); b.Navigation("Address") @@ -226,7 +325,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations .WithMany("OrderItems") .HasForeignKey("OrderId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_order_item_order_order_id"); }); modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b => diff --git a/src/HelloShop.OrderingService/appsettings.json b/src/HelloShop.OrderingService/appsettings.json index 2e367cf..69890c1 100644 --- a/src/HelloShop.OrderingService/appsettings.json +++ b/src/HelloShop.OrderingService/appsettings.json @@ -7,7 +7,7 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres", - "OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres" + "OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres", + "OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres" } } diff --git a/src/HelloShop.ProductService/Constants/DbConstants.cs b/src/HelloShop.ProductService/Constants/DbConstants.cs index 165bfdc..d57f27f 100644 --- a/src/HelloShop.ProductService/Constants/DbConstants.cs +++ b/src/HelloShop.ProductService/Constants/DbConstants.cs @@ -6,4 +6,6 @@ namespace HelloShop.ProductService.Constants; public static class DbConstants { public const string ConnectionStringName = "ProductDatabase"; + + public const string MigrationsHistoryTableName = "migrations_history"; } diff --git a/src/HelloShop.ProductService/HelloShop.ProductService.csproj b/src/HelloShop.ProductService/HelloShop.ProductService.csproj index 125b29b..80cc256 100644 --- a/src/HelloShop.ProductService/HelloShop.ProductService.csproj +++ b/src/HelloShop.ProductService/HelloShop.ProductService.csproj @@ -8,6 +8,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs index 314e379..a4520b6 100644 --- a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs +++ b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/BrandEntityTypeConfiguration.cs @@ -11,7 +11,6 @@ public class BrandEntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Brands"); builder.Property(x => x.Name).HasMaxLength(32); } } \ No newline at end of file diff --git a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs index eee4494..cf3dfc8 100644 --- a/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs +++ b/src/HelloShop.ProductService/Infrastructure/EntityConfigurations/Products/ProductEntityTypeConfiguration.cs @@ -11,12 +11,8 @@ public class ProductEntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Products"); - builder.Property(x => x.Name).HasMaxLength(64); - builder.Property(x => x.ImageUrl).HasMaxLength(256); - builder.HasOne(x => x.Brand).WithMany(); } } diff --git a/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.cs deleted file mode 100644 index f7abca2..0000000 --- a/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) HelloShop Corporation. All rights reserved. -// See the license file in the project root for more information. - -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace HelloShop.ProductService.EntityFrameworks.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Brands", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(32)", maxLength: 32, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Brands", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Products", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), - Description = table.Column(type: "text", nullable: true), - Price = table.Column(type: "numeric", nullable: false), - BrandId = table.Column(type: "integer", nullable: false), - ImageUrl = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - CreationTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Products", x => x.Id); - table.ForeignKey( - name: "FK_Products_Brands_BrandId", - column: x => x.BrandId, - principalTable: "Brands", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Products_BrandId", - table: "Products", - column: "BrandId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Products"); - - migrationBuilder.DropTable( - name: "Brands"); - } - } -} diff --git a/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.Designer.cs similarity index 58% rename from src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs rename to src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.Designer.cs index ad3d2af..2ad9426 100644 --- a/src/HelloShop.ProductService/Infrastructure/Migrations/20240419145737_InitialCreate.Designer.cs +++ b/src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.Designer.cs @@ -9,10 +9,10 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace HelloShop.ProductService.EntityFrameworks.Migrations +namespace HelloShop.ProductService.Infrastructure.Migrations { [DbContext(typeof(ProductServiceDbContext))] - [Migration("20240419145737_InitialCreate")] + [Migration("20241123020927_InitialCreate")] partial class InitialCreate { /// @@ -20,7 +20,7 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -29,54 +29,72 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Name") .IsRequired() .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasColumnType("character varying(32)") + .HasColumnName("name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_brand"); - b.ToTable("Brands", (string)null); + b.ToTable("brand", (string)null); }); modelBuilder.Entity("HelloShop.ProductService.Entities.Products.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("AvailableStock") + .HasColumnType("integer") + .HasColumnName("available_stock"); + b.Property("BrandId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("brand_id"); b.Property("CreationTime") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time"); b.Property("Description") - .HasColumnType("text"); + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); b.Property("ImageUrl") + .IsRequired() .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("image_url"); b.Property("Name") .IsRequired() - .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasMaxLength(64) + .HasColumnType("character varying(64)") + .HasColumnName("name"); b.Property("Price") - .HasColumnType("numeric"); + .HasColumnType("numeric") + .HasColumnName("price"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_product"); - b.HasIndex("BrandId"); + b.HasIndex("BrandId") + .HasDatabaseName("ix_product_brand_id"); - b.ToTable("Products", (string)null); + b.ToTable("product", (string)null); }); modelBuilder.Entity("HelloShop.ProductService.Entities.Products.Product", b => @@ -85,7 +103,8 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("BrandId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_product_brand_brand_id"); b.Navigation("Brand"); }); diff --git a/src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.cs new file mode 100644 index 0000000..2d1faef --- /dev/null +++ b/src/HelloShop.ProductService/Infrastructure/Migrations/20241123020927_InitialCreate.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HelloShop.ProductService.Infrastructure.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "brand", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(32)", maxLength: 32, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_brand", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "product", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), + description = table.Column(type: "text", nullable: false), + price = table.Column(type: "numeric", nullable: false), + brand_id = table.Column(type: "integer", nullable: false), + image_url = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), + available_stock = table.Column(type: "integer", nullable: false), + creation_time = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_product", x => x.id); + table.ForeignKey( + name: "fk_product_brand_brand_id", + column: x => x.brand_id, + principalTable: "brand", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_product_brand_id", + table: "product", + column: "brand_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "product"); + + migrationBuilder.DropTable( + name: "brand"); + } + } +} diff --git a/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs b/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs index 7889042..3ce966b 100644 --- a/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs +++ b/src/HelloShop.ProductService/Infrastructure/Migrations/ProductServiceDbContextModelSnapshot.cs @@ -8,7 +8,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace HelloShop.ProductService.EntityFrameworks.Migrations +namespace HelloShop.ProductService.Infrastructure.Migrations { [DbContext(typeof(ProductServiceDbContext))] partial class ProductServiceDbContextModelSnapshot : ModelSnapshot @@ -17,7 +17,7 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("ProductVersion", "8.0.10") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -26,54 +26,72 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Name") .IsRequired() .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasColumnType("character varying(32)") + .HasColumnName("name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_brand"); - b.ToTable("Brands", (string)null); + b.ToTable("brand", (string)null); }); modelBuilder.Entity("HelloShop.ProductService.Entities.Products.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("id"); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("AvailableStock") + .HasColumnType("integer") + .HasColumnName("available_stock"); + b.Property("BrandId") - .HasColumnType("integer"); + .HasColumnType("integer") + .HasColumnName("brand_id"); b.Property("CreationTime") - .HasColumnType("timestamp with time zone"); + .HasColumnType("timestamp with time zone") + .HasColumnName("creation_time"); b.Property("Description") - .HasColumnType("text"); + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); b.Property("ImageUrl") + .IsRequired() .HasMaxLength(256) - .HasColumnType("character varying(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("image_url"); b.Property("Name") .IsRequired() - .HasMaxLength(32) - .HasColumnType("character varying(32)"); + .HasMaxLength(64) + .HasColumnType("character varying(64)") + .HasColumnName("name"); b.Property("Price") - .HasColumnType("numeric"); + .HasColumnType("numeric") + .HasColumnName("price"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_product"); - b.HasIndex("BrandId"); + b.HasIndex("BrandId") + .HasDatabaseName("ix_product_brand_id"); - b.ToTable("Products", (string)null); + b.ToTable("product", (string)null); }); modelBuilder.Entity("HelloShop.ProductService.Entities.Products.Product", b => @@ -82,7 +100,8 @@ namespace HelloShop.ProductService.EntityFrameworks.Migrations .WithMany() .HasForeignKey("BrandId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_product_brand_brand_id"); b.Navigation("Brand"); }); diff --git a/src/HelloShop.ProductService/Program.cs b/src/HelloShop.ProductService/Program.cs index 3aeeaf7..6afaf75 100644 --- a/src/HelloShop.ProductService/Program.cs +++ b/src/HelloShop.ProductService/Program.cs @@ -20,7 +20,8 @@ builder.Services.AddControllers(); // Add extensions services to the container. builder.Services.AddDbContext(options => { - options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.ConnectionStringName)); + options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.ConnectionStringName), x => x.MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName)); + options.UseSnakeCaseNamingConvention(); }); builder.Services.AddHttpClient().AddHttpContextAccessor().AddDistributedMemoryCache(); builder.Services.AddDataSeedingProviders(); diff --git a/src/HelloShop.ProductService/appsettings.json b/src/HelloShop.ProductService/appsettings.json index 1c3fe29..11a1190 100644 --- a/src/HelloShop.ProductService/appsettings.json +++ b/src/HelloShop.ProductService/appsettings.json @@ -7,6 +7,6 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "ProductDatabase": "Host=localhost;Port=5432;Database=ProductService;Username=postgres;Password=postgres" + "ProductDatabase": "Host=localhost;Port=5432;Database=product;Username=postgres;Password=postgres" } }