diff --git a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.Designer.cs b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.Designer.cs new file mode 100644 index 0000000..0a09777 --- /dev/null +++ b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.Designer.cs @@ -0,0 +1,79 @@ +// +using System; +using EasyMicroservices.AuthenticationsMicroservice.Database.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EasyMicroservices.AuthenticationsMicroservice.Migrations +{ + [DbContext(typeof(AuthenticationsContext))] + [Migration("20230831142301_SyncDatabaseForProduction")] + partial class SyncDatabaseForProduction + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EasyMicroservices.AuthenticationsMicroservice.Database.Entities.UserEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDateTime") + .HasColumnType("datetime2"); + + b.Property("DeletedDateTime") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("ModificationDateTime") + .HasColumnType("datetime2"); + + b.Property("Password") + .HasColumnType("nvarchar(max)"); + + b.Property("UniqueIdentity") + .HasColumnType("nvarchar(450)") + .UseCollation("SQL_Latin1_General_CP1_CS_AS"); + + b.Property("UserName") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("CreationDateTime"); + + b.HasIndex("DeletedDateTime"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ModificationDateTime"); + + b.HasIndex("UniqueIdentity"); + + b.HasIndex("UserName") + .IsUnique() + .HasFilter("[UserName] IS NOT NULL"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.cs b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.cs new file mode 100644 index 0000000..889572e --- /dev/null +++ b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/20230831142301_SyncDatabaseForProduction.cs @@ -0,0 +1,73 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EasyMicroservices.AuthenticationsMicroservice.Migrations +{ + /// + public partial class SyncDatabaseForProduction : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(450)", nullable: true), + Password = table.Column(type: "nvarchar(max)", nullable: true), + UniqueIdentity = table.Column(type: "nvarchar(450)", nullable: true, collation: "SQL_Latin1_General_CP1_CS_AS"), + CreationDateTime = table.Column(type: "datetime2", nullable: false), + ModificationDateTime = table.Column(type: "datetime2", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedDateTime = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Users_CreationDateTime", + table: "Users", + column: "CreationDateTime"); + + migrationBuilder.CreateIndex( + name: "IX_Users_DeletedDateTime", + table: "Users", + column: "DeletedDateTime"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsDeleted", + table: "Users", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_Users_ModificationDateTime", + table: "Users", + column: "ModificationDateTime"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UniqueIdentity", + table: "Users", + column: "UniqueIdentity"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UserName", + table: "Users", + column: "UserName", + unique: true, + filter: "[UserName] IS NOT NULL"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/AuthenticationsContextModelSnapshot.cs b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/AuthenticationsContextModelSnapshot.cs index bb3c822..30ab2c5 100644 --- a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/AuthenticationsContextModelSnapshot.cs +++ b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.Database/Migrations/AuthenticationsContextModelSnapshot.cs @@ -38,10 +38,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("IsDeleted") .HasColumnType("bit"); - + b.Property("IsUsernameVerified") .HasColumnType("bit"); - + b.Property("ModificationDateTime") .HasColumnType("datetime2"); diff --git a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DatabaseBuilder.cs b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DatabaseBuilder.cs index 78809d6..e790b0c 100644 --- a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DatabaseBuilder.cs +++ b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DatabaseBuilder.cs @@ -11,9 +11,11 @@ namespace EasyMicroservices.AuthenticationsMicroservice { public class DatabaseBuilder : IDatabaseBuilder { - readonly IConfiguration config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .Build(); + IConfiguration _configuration; + public DatabaseBuilder(IConfiguration configuration) + { + _configuration = configuration; + } public void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DependencyManager.cs b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DependencyManager.cs index 45f75c1..67ff702 100644 --- a/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DependencyManager.cs +++ b/src/CSharp/EasyMicroservices.AuthenticationsMicroservice.StartUp/DependencyManager.cs @@ -13,6 +13,7 @@ using EasyMicroservices.AuthenticationsMicroservice.Database.Contexts; using System; using System.Linq; +using Microsoft.Extensions.Configuration; namespace EasyMicroservices.AuthenticationsMicroservice { @@ -32,7 +33,9 @@ public virtual IContractLogic(service => new DependencyManager()); - builder.Services.AddScoped(serviceProvider => new DatabaseBuilder()); + builder.Services.AddScoped(serviceProvider => new DatabaseBuilder(_config)); builder.Services.AddScoped(service => new WhiteLabelManager(service, service.GetService())); builder.Services.AddScoped(); builder.Services.AddScoped((serviceProvider) => new DependencyManager().GetContractLogic()); @@ -145,7 +145,9 @@ public static async Task Main(string[] args) static void CreateDatabase() { - using (var context = new AuthenticationsContext(new DatabaseBuilder())) + var _config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build(); + + using (var context = new AuthenticationsContext(new DatabaseBuilder(_config))) { if (context.Database.EnsureCreated()) {