diff --git a/Identity.sln b/Identity.sln index 15f86e9..5549e4c 100644 --- a/Identity.sln +++ b/Identity.sln @@ -34,7 +34,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Identity.Infrastruc EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Identity.Tests", "tests\Logitar.Identity.Tests\Logitar.Identity.Tests.csproj", "{D0781AC3-5827-4DAE-BBAD-481634FF3C0F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Identity.Contracts", "src\Logitar.Identity.Contracts\Logitar.Identity.Contracts.csproj", "{0E9D9B1A-B62C-4036-91B8-6E34CAA5F938}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Identity.Contracts", "src\Logitar.Identity.Contracts\Logitar.Identity.Contracts.csproj", "{0E9D9B1A-B62C-4036-91B8-6E34CAA5F938}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Identity.EntityFrameworkCore.PostgreSQL", "src\Logitar.Identity.EntityFrameworkCore.PostgreSQL\Logitar.Identity.EntityFrameworkCore.PostgreSQL.csproj", "{B06204BC-FE92-4C5E-9A70-25D100AB5857}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Identity.EFCore.Relational.IntegrationTests", "tests\Logitar.Identity.EFCore.Relational.IntegrationTests\Logitar.Identity.EFCore.Relational.IntegrationTests.csproj", "{5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Identity.EFCore.PostgreSQL.IntegrationTests", "tests\Logitar.Identity.EFCore.PostgreSQL.IntegrationTests\Logitar.Identity.EFCore.PostgreSQL.IntegrationTests.csproj", "{FBB0D3D5-0282-4E6A-9B03-144CC1347072}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -82,6 +88,18 @@ Global {0E9D9B1A-B62C-4036-91B8-6E34CAA5F938}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E9D9B1A-B62C-4036-91B8-6E34CAA5F938}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E9D9B1A-B62C-4036-91B8-6E34CAA5F938}.Release|Any CPU.Build.0 = Release|Any CPU + {B06204BC-FE92-4C5E-9A70-25D100AB5857}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B06204BC-FE92-4C5E-9A70-25D100AB5857}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B06204BC-FE92-4C5E-9A70-25D100AB5857}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B06204BC-FE92-4C5E-9A70-25D100AB5857}.Release|Any CPU.Build.0 = Release|Any CPU + {5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA}.Release|Any CPU.Build.0 = Release|Any CPU + {FBB0D3D5-0282-4E6A-9B03-144CC1347072}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBB0D3D5-0282-4E6A-9B03-144CC1347072}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBB0D3D5-0282-4E6A-9B03-144CC1347072}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBB0D3D5-0282-4E6A-9B03-144CC1347072}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -91,6 +109,8 @@ Global {FA9AB722-026B-4842-B888-E9824568CBC1} = {BCB8A692-DF88-4E50-91A7-AD91E466559C} {04C669C6-0B63-45A1-8F0F-16A7E7FC023E} = {BCB8A692-DF88-4E50-91A7-AD91E466559C} {D0781AC3-5827-4DAE-BBAD-481634FF3C0F} = {BCB8A692-DF88-4E50-91A7-AD91E466559C} + {5C6B80B4-D3BA-4DE0-928A-E4F5BA9529CA} = {BCB8A692-DF88-4E50-91A7-AD91E466559C} + {FBB0D3D5-0282-4E6A-9B03-144CC1347072} = {BCB8A692-DF88-4E50-91A7-AD91E466559C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {45FD7647-C5AB-4CE1-A93C-59A73FDD2196} diff --git a/docker-compose.yml b/docker-compose.yml index 68e62c6..1688361 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,14 @@ services: ACCEPT_EULA: 'Y' SA_PASSWORD: Ks875v3qctRxE6Z4 + identity_postgres: + image: postgres + container_name: Logitar.Identity_postgres + ports: + - 5436:5432 + environment: + POSTGRES_PASSWORD: zHSNLvy74Z3nUgcC + identity_demo: build: context: . @@ -18,8 +26,9 @@ services: depends_on: - identity_mssql restart: unless-stopped + ports: + - 8086:8080 environment: ASPNETCORE_Environment: Development + POSTGRESQLCONNSTR_Identity: "User ID=postgres;Password=zHSNLvy74Z3nUgcC;Host=identity_postgres;Port=5432;Database=Identity;" SQLCONNSTR_Identity: "Server=identity_mssql;Database=Identity;User Id=SA;Password=Ks875v3qctRxE6Z4;Persist Security Info=False;Encrypt=False;" - ports: - - 36190:8080 diff --git a/src/Logitar.Identity.Demo/DatabaseProvider.cs b/src/Logitar.Identity.Demo/DatabaseProvider.cs new file mode 100644 index 0000000..826f75e --- /dev/null +++ b/src/Logitar.Identity.Demo/DatabaseProvider.cs @@ -0,0 +1,7 @@ +namespace Logitar.Identity.Demo; + +internal enum DatabaseProvider +{ + EntityFrameworkCorePostgreSQL, + EntityFrameworkCoreSqlServer +} diff --git a/src/Logitar.Identity.Demo/DatabaseProviderNotSupportedException.cs b/src/Logitar.Identity.Demo/DatabaseProviderNotSupportedException.cs new file mode 100644 index 0000000..25f657b --- /dev/null +++ b/src/Logitar.Identity.Demo/DatabaseProviderNotSupportedException.cs @@ -0,0 +1,15 @@ +namespace Logitar.Identity.Demo; + +internal class DatabaseProviderNotSupportedException : NotSupportedException +{ + public DatabaseProvider DatabaseProvider + { + get => (DatabaseProvider)Data[nameof(DatabaseProvider)]!; + private set => Data[nameof(DatabaseProvider)] = value; + } + + public DatabaseProviderNotSupportedException(DatabaseProvider databaseProvider) : base($"The database provider '{databaseProvider}' is not supported.") + { + DatabaseProvider = databaseProvider; + } +} diff --git a/src/Logitar.Identity.Demo/Logitar.Identity.Demo.csproj b/src/Logitar.Identity.Demo/Logitar.Identity.Demo.csproj index fa7dfc1..241724a 100644 --- a/src/Logitar.Identity.Demo/Logitar.Identity.Demo.csproj +++ b/src/Logitar.Identity.Demo/Logitar.Identity.Demo.csproj @@ -17,6 +17,14 @@ True + + + + + + + + all @@ -27,6 +35,7 @@ + diff --git a/src/Logitar.Identity.Demo/Logitar.Identity.Demo.http b/src/Logitar.Identity.Demo/Logitar.Identity.Demo.http deleted file mode 100644 index 1fe8f03..0000000 --- a/src/Logitar.Identity.Demo/Logitar.Identity.Demo.http +++ /dev/null @@ -1,6 +0,0 @@ -@Logitar.Identity.Demo_HostAddress = http://localhost:5062 - -GET {{Logitar.Identity.Demo_HostAddress}}/weatherforecast/ -Accept: application/json - -### diff --git a/src/Logitar.Identity.Demo/Startup.cs b/src/Logitar.Identity.Demo/Startup.cs index 8d63079..ae7f6be 100644 --- a/src/Logitar.Identity.Demo/Startup.cs +++ b/src/Logitar.Identity.Demo/Startup.cs @@ -1,4 +1,5 @@ -using Logitar.Identity.EntityFrameworkCore.SqlServer; +using Logitar.Identity.EntityFrameworkCore.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.SqlServer; namespace Logitar.Identity.Demo; @@ -26,8 +27,21 @@ public override void ConfigureServices(IServiceCollection services) services.AddSwaggerGen(); } - string connectionString = _configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty; - services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); + string connectionString; + DatabaseProvider databaseProvider = _configuration.GetValue("DatabaseProvider") ?? DatabaseProvider.EntityFrameworkCoreSqlServer; + switch (databaseProvider) + { + case DatabaseProvider.EntityFrameworkCorePostgreSQL: + connectionString = _configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty; + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + break; + case DatabaseProvider.EntityFrameworkCoreSqlServer: + connectionString = _configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty; + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); + break; + default: + throw new DatabaseProviderNotSupportedException(databaseProvider); + } } public override void Configure(IApplicationBuilder builder) diff --git a/src/Logitar.Identity.Demo/appsettings.Development.json b/src/Logitar.Identity.Demo/appsettings.Development.json index c9e3b6e..ce253d4 100644 --- a/src/Logitar.Identity.Demo/appsettings.Development.json +++ b/src/Logitar.Identity.Demo/appsettings.Development.json @@ -29,5 +29,6 @@ "Microsoft.AspNetCore": "Warning" } }, + "POSTGRESQLCONNSTR_Identity": "User ID=postgres;Password=zHSNLvy74Z3nUgcC;Host=host.docker.internal;Port=5436;Database=Identity;", "SQLCONNSTR_Identity": "Server=host.docker.internal,1436;Database=Identity;User Id=SA;Password=Ks875v3qctRxE6Z4;Persist Security Info=False;Encrypt=False;" } diff --git a/src/Logitar.Identity.Demo/secrets.example.json b/src/Logitar.Identity.Demo/secrets.example.json new file mode 100644 index 0000000..b3a31eb --- /dev/null +++ b/src/Logitar.Identity.Demo/secrets.example.json @@ -0,0 +1,3 @@ +{ + "DatabaseProvider": "EntityFrameworkCorePostgreSQL" +} \ No newline at end of file diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/DependencyInjectionExtensions.cs b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/DependencyInjectionExtensions.cs new file mode 100644 index 0000000..d7f0024 --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/DependencyInjectionExtensions.cs @@ -0,0 +1,20 @@ +using Logitar.EventSourcing.EntityFrameworkCore.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL; + +public static class DependencyInjectionExtensions +{ + public static IServiceCollection AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(this IServiceCollection services, string connectionString) + { + return services + .AddDbContext(options => options.UseNpgsql(connectionString, + b => b.MigrationsAssembly("Logitar.Identity.EntityFrameworkCore.PostgreSQL") + )) + .AddLogitarEventSourcingWithEntityFrameworkCorePostgreSQL(connectionString) + .AddLogitarIdentityWithEntityFrameworkCoreRelational() + .AddSingleton(); + } +} diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/LICENSE b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/LICENSE new file mode 100644 index 0000000..0487f9b --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Logitar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Logitar.Identity.EntityFrameworkCore.PostgreSQL.csproj b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Logitar.Identity.EntityFrameworkCore.PostgreSQL.csproj new file mode 100644 index 0000000..f6c8810 --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Logitar.Identity.EntityFrameworkCore.PostgreSQL.csproj @@ -0,0 +1,62 @@ + + + + net8.0 + enable + enable + true + Logitar.Identity.EntityFrameworkCore.PostgreSQL + Francis Pion + Logitar + Logitar.Identity + Provides an implementation of a relational event store to be used with Identity management platform, Entity Framework Core and PostgreSQL. + © 2024 Logitar All Rights Reserved. + logitar.png + README.md + https://github.com/Logitar/Identity + git + 0.11.1.0 + $(AssemblyVersion) + LICENSE + True + 0.11.1 + en-CA + False + Updated NuGet packages. + logitar;net;framework;identity;entityframeworkcore;postgres + https://github.com/Logitar/Identity/tree/main/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL + + + + True + + + + True + + + + + \ + True + + + \ + True + + + \ + True + + + + + + + + + + + + + diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.Designer.cs similarity index 72% rename from src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.Designer.cs rename to src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.Designer.cs index fdf88bc..5c698bf 100644 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.Designer.cs +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.Designer.cs @@ -1,19 +1,18 @@ // -using System; using Logitar.Identity.EntityFrameworkCore.Relational; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Migrations { [DbContext(typeof(IdentityContext))] - [Migration("20240122000544_CreateOneTimePasswordTable")] - partial class CreateOneTimePasswordTable + [Migration("20240305022651_LogitarIdentity_1_0_0")] + partial class LogitarIdentity_1_0_0 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -21,43 +20,43 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => { b.Property("ActorId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ActorId")); b.Property("DisplayName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailAddress") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Id") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("PictureUrl") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("Type") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("ActorId"); @@ -79,57 +78,57 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("ApiKeyId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ApiKeyId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ApiKeyId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("DisplayName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("ExpiresOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("SecretHash") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); @@ -163,10 +162,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => { b.Property("ApiKeyId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("ApiKeyId", "RoleId"); @@ -179,17 +178,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("BlacklistedTokenId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BlacklistedTokenId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("BlacklistedTokenId")); b.Property("ExpiresOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("TokenId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("BlacklistedTokenId"); @@ -205,31 +204,31 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("CustomAttributeId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CustomAttributeId")); b.Property("EntityId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("EntityType") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Key") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Value") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ValueShortened") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("CustomAttributeId"); @@ -249,55 +248,55 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("OneTimePasswordId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("OneTimePasswordId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OneTimePasswordId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AttemptCount") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("ExpiresOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("HasValidationSucceeded") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("MaximumAttempts") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("PasswordHash") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); @@ -334,55 +333,55 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("RoleId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("RoleId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("DisplayName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueNameNormalized") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); @@ -409,8 +408,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Version"); b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("Roles", (string)null); }); @@ -419,54 +417,54 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("SessionId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SessionId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("IsActive") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsPersistent") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("SecretHash") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("SignedOutBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("SignedOutOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Version") .HasColumnType("bigint"); @@ -503,206 +501,206 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("UserId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserId")); b.Property("AddressCountry") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressFormatted") .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); + .HasColumnType("character varying(1279)"); b.Property("AddressLocality") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressPostalCode") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressRegion") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressStreet") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Birthdate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("DisabledBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("DisabledOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("EmailAddress") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailAddressNormalized") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("FirstName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("FullName") .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); + .HasColumnType("character varying(767)"); b.Property("Gender") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("HasPassword") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsAddressVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsDisabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsEmailVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsPhoneVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LastName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Locale") .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); + .HasColumnType("character varying(16)"); b.Property("MiddleName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Nickname") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PasswordChangedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("PasswordHash") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PhoneCountryCode") .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); + .HasColumnType("character varying(2)"); b.Property("PhoneE164Formatted") .HasMaxLength(40) - .HasColumnType("nvarchar(40)"); + .HasColumnType("character varying(40)"); b.Property("PhoneExtension") .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); + .HasColumnType("character varying(10)"); b.Property("PhoneNumber") .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); + .HasColumnType("character varying(20)"); b.Property("PhoneVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Picture") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("Profile") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TimeZone") .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); + .HasColumnType("character varying(32)"); b.Property("UniqueName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueNameNormalized") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); b.Property("Website") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.HasKey("UserId"); @@ -800,8 +798,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TenantId", "EmailAddressNormalized"); b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("Users", (string)null); }); @@ -810,26 +807,26 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("UserIdentifierId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserIdentifierId")); b.Property("Key") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Value") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("UserIdentifierId"); @@ -841,8 +838,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsUnique(); b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("UserIdentifiers", (string)null); }); @@ -850,10 +846,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => { b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("UserId", "RoleId"); diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.cs b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.cs new file mode 100644 index 0000000..632485f --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.cs @@ -0,0 +1,882 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Migrations +{ + /// + public partial class LogitarIdentity_1_0_0 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Actors", + columns: table => new + { + ActorId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Id = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Type = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DisplayName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + EmailAddress = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + PictureUrl = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Actors", x => x.ActorId); + }); + + migrationBuilder.CreateTable( + name: "ApiKeys", + columns: table => new + { + ApiKeyId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TenantId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + SecretHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + DisplayName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Description = table.Column(type: "text", nullable: true), + ExpiresOn = table.Column(type: "timestamp with time zone", nullable: true), + AuthenticatedOn = table.Column(type: "timestamp with time zone", nullable: true), + CustomAttributes = table.Column(type: "text", nullable: true), + AggregateId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ApiKeys", x => x.ApiKeyId); + }); + + migrationBuilder.CreateTable( + name: "CustomAttributes", + columns: table => new + { + CustomAttributeId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EntityType = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + EntityId = table.Column(type: "integer", nullable: false), + Key = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Value = table.Column(type: "text", nullable: false), + ValueShortened = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CustomAttributes", x => x.CustomAttributeId); + }); + + migrationBuilder.CreateTable( + name: "OneTimePasswords", + columns: table => new + { + OneTimePasswordId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TenantId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + ExpiresOn = table.Column(type: "timestamp with time zone", nullable: true), + MaximumAttempts = table.Column(type: "integer", nullable: true), + AttemptCount = table.Column(type: "integer", nullable: false), + HasValidationSucceeded = table.Column(type: "boolean", nullable: false), + CustomAttributes = table.Column(type: "text", nullable: true), + AggregateId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OneTimePasswords", x => x.OneTimePasswordId); + }); + + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + RoleId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TenantId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + UniqueName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UniqueNameNormalized = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + DisplayName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + Description = table.Column(type: "text", nullable: true), + CustomAttributes = table.Column(type: "text", nullable: true), + AggregateId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.RoleId); + }); + + migrationBuilder.CreateTable( + name: "TokenBlacklist", + columns: table => new + { + BlacklistedTokenId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TokenId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + ExpiresOn = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_TokenBlacklist", x => x.BlacklistedTokenId); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TenantId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + UniqueName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UniqueNameNormalized = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + PasswordChangedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + PasswordChangedOn = table.Column(type: "timestamp with time zone", nullable: true), + HasPassword = table.Column(type: "boolean", nullable: false), + DisabledBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + DisabledOn = table.Column(type: "timestamp with time zone", nullable: true), + IsDisabled = table.Column(type: "boolean", nullable: false), + AddressStreet = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressLocality = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressPostalCode = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressRegion = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressCountry = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressFormatted = table.Column(type: "character varying(1279)", maxLength: 1279, nullable: true), + AddressVerifiedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + AddressVerifiedOn = table.Column(type: "timestamp with time zone", nullable: true), + IsAddressVerified = table.Column(type: "boolean", nullable: false), + EmailAddress = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + EmailAddressNormalized = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + EmailVerifiedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + EmailVerifiedOn = table.Column(type: "timestamp with time zone", nullable: true), + IsEmailVerified = table.Column(type: "boolean", nullable: false), + PhoneCountryCode = table.Column(type: "character varying(2)", maxLength: 2, nullable: true), + PhoneNumber = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + PhoneExtension = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), + PhoneE164Formatted = table.Column(type: "character varying(40)", maxLength: 40, nullable: true), + PhoneVerifiedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + PhoneVerifiedOn = table.Column(type: "timestamp with time zone", nullable: true), + IsPhoneVerified = table.Column(type: "boolean", nullable: false), + IsConfirmed = table.Column(type: "boolean", nullable: false), + FirstName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + MiddleName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + LastName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + FullName = table.Column(type: "character varying(767)", maxLength: 767, nullable: true), + Nickname = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + Birthdate = table.Column(type: "timestamp with time zone", nullable: true), + Gender = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + Locale = table.Column(type: "character varying(16)", maxLength: 16, nullable: true), + TimeZone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), + Picture = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), + Profile = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), + Website = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), + AuthenticatedOn = table.Column(type: "timestamp with time zone", nullable: true), + CustomAttributes = table.Column(type: "text", nullable: true), + AggregateId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.UserId); + }); + + migrationBuilder.CreateTable( + name: "ApiKeyRoles", + columns: table => new + { + ApiKeyId = table.Column(type: "integer", nullable: false), + RoleId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ApiKeyRoles", x => new { x.ApiKeyId, x.RoleId }); + table.ForeignKey( + name: "FK_ApiKeyRoles_ApiKeys_ApiKeyId", + column: x => x.ApiKeyId, + principalTable: "ApiKeys", + principalColumn: "ApiKeyId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ApiKeyRoles_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "RoleId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Sessions", + columns: table => new + { + SessionId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + SecretHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + IsPersistent = table.Column(type: "boolean", nullable: false), + SignedOutBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + SignedOutOn = table.Column(type: "timestamp with time zone", nullable: true), + IsActive = table.Column(type: "boolean", nullable: false), + CustomAttributes = table.Column(type: "text", nullable: true), + AggregateId = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedBy = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sessions", x => x.SessionId); + table.ForeignKey( + name: "FK_Sessions_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "UserIdentifiers", + columns: table => new + { + UserIdentifierId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + TenantId = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), + Key = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + Value = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserIdentifiers", x => x.UserIdentifierId); + table.ForeignKey( + name: "FK_UserIdentifiers_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + 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: "RoleId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserRoles_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Actors_DisplayName", + table: "Actors", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_EmailAddress", + table: "Actors", + column: "EmailAddress"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_Id", + table: "Actors", + column: "Id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Actors_IsDeleted", + table: "Actors", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_Type", + table: "Actors", + column: "Type"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeyRoles_RoleId", + table: "ApiKeyRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_AggregateId", + table: "ApiKeys", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_AuthenticatedOn", + table: "ApiKeys", + column: "AuthenticatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_CreatedBy", + table: "ApiKeys", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_CreatedOn", + table: "ApiKeys", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_DisplayName", + table: "ApiKeys", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_ExpiresOn", + table: "ApiKeys", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_TenantId", + table: "ApiKeys", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_UpdatedBy", + table: "ApiKeys", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_UpdatedOn", + table: "ApiKeys", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_Version", + table: "ApiKeys", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_EntityType_EntityId", + table: "CustomAttributes", + columns: new[] { "EntityType", "EntityId" }); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_EntityType_EntityId_Key", + table: "CustomAttributes", + columns: new[] { "EntityType", "EntityId", "Key" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_Key", + table: "CustomAttributes", + column: "Key"); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_ValueShortened", + table: "CustomAttributes", + column: "ValueShortened"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_AggregateId", + table: "OneTimePasswords", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_AttemptCount", + table: "OneTimePasswords", + column: "AttemptCount"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_CreatedBy", + table: "OneTimePasswords", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_CreatedOn", + table: "OneTimePasswords", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_ExpiresOn", + table: "OneTimePasswords", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_HasValidationSucceeded", + table: "OneTimePasswords", + column: "HasValidationSucceeded"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_MaximumAttempts", + table: "OneTimePasswords", + column: "MaximumAttempts"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_TenantId", + table: "OneTimePasswords", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_UpdatedBy", + table: "OneTimePasswords", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_UpdatedOn", + table: "OneTimePasswords", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_Version", + table: "OneTimePasswords", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_AggregateId", + table: "Roles", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Roles_CreatedBy", + table: "Roles", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_CreatedOn", + table: "Roles", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_DisplayName", + table: "Roles", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_TenantId", + table: "Roles", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_TenantId_UniqueNameNormalized", + table: "Roles", + columns: new[] { "TenantId", "UniqueNameNormalized" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UniqueName", + table: "Roles", + column: "UniqueName"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UpdatedBy", + table: "Roles", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UpdatedOn", + table: "Roles", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_Version", + table: "Roles", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_AggregateId", + table: "Sessions", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_CreatedBy", + table: "Sessions", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_CreatedOn", + table: "Sessions", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_IsActive", + table: "Sessions", + column: "IsActive"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_IsPersistent", + table: "Sessions", + column: "IsPersistent"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_SignedOutBy", + table: "Sessions", + column: "SignedOutBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_SignedOutOn", + table: "Sessions", + column: "SignedOutOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UpdatedBy", + table: "Sessions", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UpdatedOn", + table: "Sessions", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UserId", + table: "Sessions", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_Version", + table: "Sessions", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_TokenBlacklist_ExpiresOn", + table: "TokenBlacklist", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_TokenBlacklist_TokenId", + table: "TokenBlacklist", + column: "TokenId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_Key", + table: "UserIdentifiers", + column: "Key"); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_TenantId_Key_Value", + table: "UserIdentifiers", + columns: new[] { "TenantId", "Key", "Value" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_UserId_Key", + table: "UserIdentifiers", + columns: new[] { "UserId", "Key" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_Value", + table: "UserIdentifiers", + column: "Value"); + + migrationBuilder.CreateIndex( + name: "IX_UserRoles_RoleId", + table: "UserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressCountry", + table: "Users", + column: "AddressCountry"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressFormatted", + table: "Users", + column: "AddressFormatted"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressLocality", + table: "Users", + column: "AddressLocality"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressPostalCode", + table: "Users", + column: "AddressPostalCode"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressRegion", + table: "Users", + column: "AddressRegion"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressStreet", + table: "Users", + column: "AddressStreet"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressVerifiedBy", + table: "Users", + column: "AddressVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressVerifiedOn", + table: "Users", + column: "AddressVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AggregateId", + table: "Users", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Users_AuthenticatedOn", + table: "Users", + column: "AuthenticatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Birthdate", + table: "Users", + column: "Birthdate"); + + migrationBuilder.CreateIndex( + name: "IX_Users_CreatedBy", + table: "Users", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_CreatedOn", + table: "Users", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_DisabledBy", + table: "Users", + column: "DisabledBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_DisabledOn", + table: "Users", + column: "DisabledOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailAddress", + table: "Users", + column: "EmailAddress"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailVerifiedBy", + table: "Users", + column: "EmailVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailVerifiedOn", + table: "Users", + column: "EmailVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_FirstName", + table: "Users", + column: "FirstName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_FullName", + table: "Users", + column: "FullName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Gender", + table: "Users", + column: "Gender"); + + migrationBuilder.CreateIndex( + name: "IX_Users_HasPassword", + table: "Users", + column: "HasPassword"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsAddressVerified", + table: "Users", + column: "IsAddressVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsConfirmed", + table: "Users", + column: "IsConfirmed"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsDisabled", + table: "Users", + column: "IsDisabled"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsEmailVerified", + table: "Users", + column: "IsEmailVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsPhoneVerified", + table: "Users", + column: "IsPhoneVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_LastName", + table: "Users", + column: "LastName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Locale", + table: "Users", + column: "Locale"); + + migrationBuilder.CreateIndex( + name: "IX_Users_MiddleName", + table: "Users", + column: "MiddleName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Nickname", + table: "Users", + column: "Nickname"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PasswordChangedBy", + table: "Users", + column: "PasswordChangedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PasswordChangedOn", + table: "Users", + column: "PasswordChangedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneCountryCode", + table: "Users", + column: "PhoneCountryCode"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneE164Formatted", + table: "Users", + column: "PhoneE164Formatted"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneExtension", + table: "Users", + column: "PhoneExtension"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneNumber", + table: "Users", + column: "PhoneNumber"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneVerifiedBy", + table: "Users", + column: "PhoneVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneVerifiedOn", + table: "Users", + column: "PhoneVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId", + table: "Users", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId_EmailAddressNormalized", + table: "Users", + columns: new[] { "TenantId", "EmailAddressNormalized" }); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId_UniqueNameNormalized", + table: "Users", + columns: new[] { "TenantId", "UniqueNameNormalized" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Users_TimeZone", + table: "Users", + column: "TimeZone"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UniqueName", + table: "Users", + column: "UniqueName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UpdatedBy", + table: "Users", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UpdatedOn", + table: "Users", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Version", + table: "Users", + column: "Version"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Actors"); + + migrationBuilder.DropTable( + name: "ApiKeyRoles"); + + migrationBuilder.DropTable( + name: "CustomAttributes"); + + migrationBuilder.DropTable( + name: "OneTimePasswords"); + + migrationBuilder.DropTable( + name: "Sessions"); + + migrationBuilder.DropTable( + name: "TokenBlacklist"); + + migrationBuilder.DropTable( + name: "UserIdentifiers"); + + migrationBuilder.DropTable( + name: "UserRoles"); + + migrationBuilder.DropTable( + name: "ApiKeys"); + + migrationBuilder.DropTable( + name: "Roles"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/IdentityContextModelSnapshot.cs similarity index 65% rename from src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.Designer.cs rename to src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/IdentityContextModelSnapshot.cs index d6ccdd6..9253d5e 100644 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.Designer.cs +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/IdentityContextModelSnapshot.cs @@ -1,63 +1,59 @@ // -using System; using Logitar.Identity.EntityFrameworkCore.Relational; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Migrations { [DbContext(typeof(IdentityContext))] - [Migration("20240121052425_CreateTokenBlacklistTable")] - partial class CreateTokenBlacklistTable + partial class IdentityContextModelSnapshot : ModelSnapshot { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) + protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => { b.Property("ActorId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ActorId")); b.Property("DisplayName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailAddress") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Id") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("PictureUrl") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("Type") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("ActorId"); @@ -79,57 +75,57 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("ApiKeyId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ApiKeyId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ApiKeyId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("DisplayName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("ExpiresOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("SecretHash") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); @@ -163,10 +159,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => { b.Property("ApiKeyId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("ApiKeyId", "RoleId"); @@ -179,17 +175,17 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("BlacklistedTokenId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BlacklistedTokenId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("BlacklistedTokenId")); b.Property("ExpiresOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("TokenId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("BlacklistedTokenId"); @@ -205,31 +201,31 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("CustomAttributeId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CustomAttributeId")); b.Property("EntityId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("EntityType") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Key") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Value") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ValueShortened") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("CustomAttributeId"); @@ -245,59 +241,144 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CustomAttributes", (string)null); }); + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.OneTimePasswordEntity", b => + { + b.Property("OneTimePasswordId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OneTimePasswordId")); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("AttemptCount") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("CreatedOn") + .HasColumnType("timestamp with time zone"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("text") + .HasColumnName("CustomAttributes"); + + b.Property("ExpiresOn") + .HasColumnType("timestamp with time zone"); + + b.Property("HasValidationSucceeded") + .HasColumnType("boolean"); + + b.Property("MaximumAttempts") + .HasColumnType("integer"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("UpdatedOn") + .HasColumnType("timestamp with time zone"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.HasKey("OneTimePasswordId"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("AttemptCount"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("ExpiresOn"); + + b.HasIndex("HasValidationSucceeded"); + + b.HasIndex("MaximumAttempts"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("Version"); + + b.ToTable("OneTimePasswords", (string)null); + }); + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => { b.Property("RoleId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("RoleId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("DisplayName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueNameNormalized") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); @@ -324,8 +405,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("Version"); b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("Roles", (string)null); }); @@ -334,54 +414,54 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("SessionId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("SessionId")); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("IsActive") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsPersistent") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("SecretHash") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("SignedOutBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("SignedOutOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Version") .HasColumnType("bigint"); @@ -418,206 +498,206 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("UserId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserId")); b.Property("AddressCountry") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressFormatted") .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); + .HasColumnType("character varying(1279)"); b.Property("AddressLocality") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressPostalCode") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressRegion") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressStreet") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("AggregateId") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Birthdate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CreatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("CreatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") + .HasColumnType("text") .HasColumnName("CustomAttributes"); b.Property("DisabledBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("DisabledOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("EmailAddress") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailAddressNormalized") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("FirstName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("FullName") .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); + .HasColumnType("character varying(767)"); b.Property("Gender") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("HasPassword") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsAddressVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsDisabled") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsEmailVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("IsPhoneVerified") - .HasColumnType("bit"); + .HasColumnType("boolean"); b.Property("LastName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Locale") .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); + .HasColumnType("character varying(16)"); b.Property("MiddleName") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("Nickname") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PasswordChangedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("PasswordHash") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PhoneCountryCode") .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); + .HasColumnType("character varying(2)"); b.Property("PhoneE164Formatted") .HasMaxLength(40) - .HasColumnType("nvarchar(40)"); + .HasColumnType("character varying(40)"); b.Property("PhoneExtension") .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); + .HasColumnType("character varying(10)"); b.Property("PhoneNumber") .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); + .HasColumnType("character varying(20)"); b.Property("PhoneVerifiedBy") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Picture") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("Profile") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TimeZone") .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); + .HasColumnType("character varying(32)"); b.Property("UniqueName") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UniqueNameNormalized") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedBy") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UpdatedOn") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); b.Property("Version") .HasColumnType("bigint"); b.Property("Website") .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); + .HasColumnType("character varying(2048)"); b.HasKey("UserId"); @@ -715,8 +795,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("TenantId", "EmailAddressNormalized"); b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("Users", (string)null); }); @@ -725,26 +804,26 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("UserIdentifierId") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UserIdentifierId")); b.Property("Key") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("TenantId") .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Value") .IsRequired() .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .HasColumnType("character varying(255)"); b.HasKey("UserIdentifierId"); @@ -756,8 +835,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsUnique(); b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); + .IsUnique(); b.ToTable("UserIdentifiers", (string)null); }); @@ -765,10 +843,10 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => { b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("integer"); b.HasKey("UserId", "RoleId"); diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/PostgresHelper.cs b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/PostgresHelper.cs new file mode 100644 index 0000000..02a1746 --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/PostgresHelper.cs @@ -0,0 +1,10 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL; + +public class PostgresHelper : ISqlHelper +{ + public IQueryBuilder QueryFrom(TableId table) => PostgresQueryBuilder.From(table); +} diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/README.md b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/README.md new file mode 100644 index 0000000..922b650 --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/README.md @@ -0,0 +1,31 @@ +# Logitar.Identity.EntityFrameworkCore.PostgreSQL + +Provides an implementation of a relational event store to be used with Identity management platform, Entity Framework Core and PostgreSQL. + +## Migrations + +This project is setup to use migrations. All the commands below must be executed in the solution directory. + +### Create a migration + +To create a new migration, execute the following command. Do not forget to provide a migration name! + +```sh +dotnet ef migrations add --context IdentityContext --project src/Logitar.Identity.EntityFrameworkCore.PostgreSQL --startup-project src/Logitar.Identity.Demo +``` + +### Remove a migration + +To remove the latest unapplied migration, execute the following command. + +```sh +dotnet ef migrations remove --context IdentityContext --project src/Logitar.Identity.EntityFrameworkCore.PostgreSQL --startup-project src/Logitar.Identity.Demo +``` + +### Generate a script + +To generate a script, execute the following command. Do not forget to provide a source migration name! + +```sh +dotnet ef migrations script --context IdentityContext --project src/Logitar.Identity.EntityFrameworkCore.PostgreSQL --startup-project src/Logitar.Identity.Demo +``` \ No newline at end of file diff --git a/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/logitar.png b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/logitar.png new file mode 100644 index 0000000..5b031f4 Binary files /dev/null and b/src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/logitar.png differ diff --git a/src/Logitar.Identity.EntityFrameworkCore.Relational/Entities/UserEntity.cs b/src/Logitar.Identity.EntityFrameworkCore.Relational/Entities/UserEntity.cs index b060126..fd9cd2e 100644 --- a/src/Logitar.Identity.EntityFrameworkCore.Relational/Entities/UserEntity.cs +++ b/src/Logitar.Identity.EntityFrameworkCore.Relational/Entities/UserEntity.cs @@ -188,7 +188,7 @@ public void Authenticate(UserAuthenticatedEvent @event) { Update(@event); - AuthenticatedOn = @event.OccurredOn; + AuthenticatedOn = @event.OccurredOn.ToUniversalTime(); } public void Disable(UserDisabledEvent @event) @@ -323,7 +323,7 @@ public void SignIn(UserSignedInEvent @event) { Update(@event); - AuthenticatedOn = @event.OccurredOn; + AuthenticatedOn = @event.OccurredOn.ToUniversalTime(); } public void Update(UserUpdatedEvent @event) diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.Designer.cs deleted file mode 100644 index 59778e0..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.Designer.cs +++ /dev/null @@ -1,189 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240105181804_InitialMigration")] - partial class InitialMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("FullName"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.cs deleted file mode 100644 index 7193621..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class InitialMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - UserId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - UniqueName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UniqueNameNormalized = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - FullName = table.Column(type: "nvarchar(767)", maxLength: 767, nullable: true), - AuthenticatedOn = table.Column(type: "datetime2", nullable: true), - AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "bigint", nullable: false), - CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - CreatedOn = table.Column(type: "datetime2", nullable: false), - UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UpdatedOn = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.UserId); - }); - - migrationBuilder.CreateTable( - name: "Sessions", - columns: table => new - { - SessionId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "int", nullable: false), - IsActive = table.Column(type: "bit", nullable: false), - AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "bigint", nullable: false), - CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - CreatedOn = table.Column(type: "datetime2", nullable: false), - UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UpdatedOn = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Sessions", x => x.SessionId); - table.ForeignKey( - name: "FK_Sessions_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_AggregateId", - table: "Sessions", - column: "AggregateId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_CreatedBy", - table: "Sessions", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_CreatedOn", - table: "Sessions", - column: "CreatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_IsActive", - table: "Sessions", - column: "IsActive"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_UpdatedBy", - table: "Sessions", - column: "UpdatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_UpdatedOn", - table: "Sessions", - column: "UpdatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_UserId", - table: "Sessions", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_Version", - table: "Sessions", - column: "Version"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AggregateId", - table: "Users", - column: "AggregateId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_AuthenticatedOn", - table: "Users", - column: "AuthenticatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_CreatedBy", - table: "Users", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_CreatedOn", - table: "Users", - column: "CreatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_FullName", - table: "Users", - column: "FullName"); - - migrationBuilder.CreateIndex( - name: "IX_Users_TenantId", - table: "Users", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_Users_TenantId_UniqueNameNormalized", - table: "Users", - columns: new[] { "TenantId", "UniqueNameNormalized" }, - unique: true, - filter: "[TenantId] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_Users_UniqueName", - table: "Users", - column: "UniqueName"); - - migrationBuilder.CreateIndex( - name: "IX_Users_UpdatedBy", - table: "Users", - column: "UpdatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_UpdatedOn", - table: "Users", - column: "UpdatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Version", - table: "Users", - column: "Version"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Sessions"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.Designer.cs deleted file mode 100644 index 0edc5e8..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.Designer.cs +++ /dev/null @@ -1,209 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240105224604_AddUserPasswordColumns")] - partial class AddUserPasswordColumns - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("FullName"); - - b.HasIndex("HasPassword"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.cs deleted file mode 100644 index 608ceb4..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddUserPasswordColumns : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "HasPassword", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "PasswordChangedBy", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "PasswordChangedOn", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "PasswordHash", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_HasPassword", - table: "Users", - column: "HasPassword"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PasswordChangedBy", - table: "Users", - column: "PasswordChangedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PasswordChangedOn", - table: "Users", - column: "PasswordChangedOn"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Users_HasPassword", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PasswordChangedBy", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PasswordChangedOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "HasPassword", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PasswordChangedBy", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PasswordChangedOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PasswordHash", - table: "Users"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.Designer.cs deleted file mode 100644 index e1203c6..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.Designer.cs +++ /dev/null @@ -1,218 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240105230509_AddSessionSecretColumns")] - partial class AddSessionSecretColumns - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("FullName"); - - b.HasIndex("HasPassword"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.cs deleted file mode 100644 index 704ec7a..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddSessionSecretColumns : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IsPersistent", - table: "Sessions", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "SecretHash", - table: "Sessions", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_IsPersistent", - table: "Sessions", - column: "IsPersistent"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Sessions_IsPersistent", - table: "Sessions"); - - migrationBuilder.DropColumn( - name: "IsPersistent", - table: "Sessions"); - - migrationBuilder.DropColumn( - name: "SecretHash", - table: "Sessions"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.Designer.cs deleted file mode 100644 index 6f78429..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.Designer.cs +++ /dev/null @@ -1,268 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240106003527_CreateActorTable")] - partial class CreateActorTable - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("FullName"); - - b.HasIndex("HasPassword"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.cs deleted file mode 100644 index b49e507..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateActorTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Actors", - columns: table => new - { - ActorId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Id = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Type = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - IsDeleted = table.Column(type: "bit", nullable: false), - DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - EmailAddress = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - PictureUrl = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Actors", x => x.ActorId); - }); - - migrationBuilder.CreateIndex( - name: "IX_Actors_DisplayName", - table: "Actors", - column: "DisplayName"); - - migrationBuilder.CreateIndex( - name: "IX_Actors_EmailAddress", - table: "Actors", - column: "EmailAddress"); - - migrationBuilder.CreateIndex( - name: "IX_Actors_Id", - table: "Actors", - column: "Id", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Actors_IsDeleted", - table: "Actors", - column: "IsDeleted"); - - migrationBuilder.CreateIndex( - name: "IX_Actors_Type", - table: "Actors", - column: "Type"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Actors"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.Designer.cs deleted file mode 100644 index f38eba4..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.Designer.cs +++ /dev/null @@ -1,376 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240106175723_AddedUserClaims")] - partial class AddedUserClaims - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.cs deleted file mode 100644 index 8d1d367..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.cs +++ /dev/null @@ -1,389 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddedUserClaims : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Birthdate", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "DisabledBy", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "DisabledOn", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "EmailAddress", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "EmailAddressNormalized", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "EmailVerifiedBy", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "EmailVerifiedOn", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "FirstName", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "Gender", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "IsConfirmed", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "IsDisabled", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "IsEmailVerified", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "LastName", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "Locale", - table: "Users", - type: "nvarchar(16)", - maxLength: 16, - nullable: true); - - migrationBuilder.AddColumn( - name: "MiddleName", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "Nickname", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "Picture", - table: "Users", - type: "nvarchar(2048)", - maxLength: 2048, - nullable: true); - - migrationBuilder.AddColumn( - name: "Profile", - table: "Users", - type: "nvarchar(2048)", - maxLength: 2048, - nullable: true); - - migrationBuilder.AddColumn( - name: "TimeZone", - table: "Users", - type: "nvarchar(32)", - maxLength: 32, - nullable: true); - - migrationBuilder.AddColumn( - name: "Website", - table: "Users", - type: "nvarchar(2048)", - maxLength: 2048, - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_Birthdate", - table: "Users", - column: "Birthdate"); - - migrationBuilder.CreateIndex( - name: "IX_Users_DisabledBy", - table: "Users", - column: "DisabledBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_DisabledOn", - table: "Users", - column: "DisabledOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_EmailAddress", - table: "Users", - column: "EmailAddress"); - - migrationBuilder.CreateIndex( - name: "IX_Users_EmailVerifiedBy", - table: "Users", - column: "EmailVerifiedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_EmailVerifiedOn", - table: "Users", - column: "EmailVerifiedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_FirstName", - table: "Users", - column: "FirstName"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Gender", - table: "Users", - column: "Gender"); - - migrationBuilder.CreateIndex( - name: "IX_Users_IsConfirmed", - table: "Users", - column: "IsConfirmed"); - - migrationBuilder.CreateIndex( - name: "IX_Users_IsDisabled", - table: "Users", - column: "IsDisabled"); - - migrationBuilder.CreateIndex( - name: "IX_Users_IsEmailVerified", - table: "Users", - column: "IsEmailVerified"); - - migrationBuilder.CreateIndex( - name: "IX_Users_LastName", - table: "Users", - column: "LastName"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Locale", - table: "Users", - column: "Locale"); - - migrationBuilder.CreateIndex( - name: "IX_Users_MiddleName", - table: "Users", - column: "MiddleName"); - - migrationBuilder.CreateIndex( - name: "IX_Users_Nickname", - table: "Users", - column: "Nickname"); - - migrationBuilder.CreateIndex( - name: "IX_Users_TenantId_EmailAddressNormalized", - table: "Users", - columns: new[] { "TenantId", "EmailAddressNormalized" }); - - migrationBuilder.CreateIndex( - name: "IX_Users_TimeZone", - table: "Users", - column: "TimeZone"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Users_Birthdate", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_DisabledBy", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_DisabledOn", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_EmailAddress", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_EmailVerifiedBy", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_EmailVerifiedOn", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_FirstName", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_Gender", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_IsConfirmed", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_IsDisabled", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_IsEmailVerified", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_LastName", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_Locale", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_MiddleName", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_Nickname", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_TenantId_EmailAddressNormalized", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_TimeZone", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Birthdate", - table: "Users"); - - migrationBuilder.DropColumn( - name: "DisabledBy", - table: "Users"); - - migrationBuilder.DropColumn( - name: "DisabledOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "EmailAddress", - table: "Users"); - - migrationBuilder.DropColumn( - name: "EmailAddressNormalized", - table: "Users"); - - migrationBuilder.DropColumn( - name: "EmailVerifiedBy", - table: "Users"); - - migrationBuilder.DropColumn( - name: "EmailVerifiedOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "FirstName", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Gender", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsConfirmed", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsDisabled", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsEmailVerified", - table: "Users"); - - migrationBuilder.DropColumn( - name: "LastName", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Locale", - table: "Users"); - - migrationBuilder.DropColumn( - name: "MiddleName", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Nickname", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Picture", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Profile", - table: "Users"); - - migrationBuilder.DropColumn( - name: "TimeZone", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Website", - table: "Users"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.Designer.cs deleted file mode 100644 index 1cbaf00..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.Designer.cs +++ /dev/null @@ -1,387 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240106184348_AddedSessionSigningOut")] - partial class AddedSessionSigningOut - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.cs deleted file mode 100644 index 62d7c4d..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddedSessionSigningOut : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "SignedOutBy", - table: "Sessions", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "SignedOutOn", - table: "Sessions", - type: "datetime2", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_SignedOutBy", - table: "Sessions", - column: "SignedOutBy"); - - migrationBuilder.CreateIndex( - name: "IX_Sessions_SignedOutOn", - table: "Sessions", - column: "SignedOutOn"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Sessions_SignedOutBy", - table: "Sessions"); - - migrationBuilder.DropIndex( - name: "IX_Sessions_SignedOutOn", - table: "Sessions"); - - migrationBuilder.DropColumn( - name: "SignedOutBy", - table: "Sessions"); - - migrationBuilder.DropColumn( - name: "SignedOutOn", - table: "Sessions"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.Designer.cs deleted file mode 100644 index 7e88f85..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.Designer.cs +++ /dev/null @@ -1,395 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240110223034_AddedCustomAttributeColumns")] - partial class AddedCustomAttributeColumns - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.cs deleted file mode 100644 index 94d04c1..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddedCustomAttributeColumns : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "CustomAttributes", - table: "Users", - type: "nvarchar(max)", - nullable: true); - - migrationBuilder.AddColumn( - name: "CustomAttributes", - table: "Sessions", - type: "nvarchar(max)", - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "CustomAttributes", - table: "Users"); - - migrationBuilder.DropColumn( - name: "CustomAttributes", - table: "Sessions"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.Designer.cs deleted file mode 100644 index 08f10c0..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.Designer.cs +++ /dev/null @@ -1,435 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240110234318_AddUserPhoneColumns")] - partial class AddUserPhoneColumns - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.cs deleted file mode 100644 index 61d2176..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddUserPhoneColumns : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IsPhoneVerified", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "PhoneCountryCode", - table: "Users", - type: "nvarchar(2)", - maxLength: 2, - nullable: true); - - migrationBuilder.AddColumn( - name: "PhoneE164Formatted", - table: "Users", - type: "nvarchar(37)", - maxLength: 37, - nullable: true); - - migrationBuilder.AddColumn( - name: "PhoneExtension", - table: "Users", - type: "nvarchar(10)", - maxLength: 10, - nullable: true); - - migrationBuilder.AddColumn( - name: "PhoneNumber", - table: "Users", - type: "nvarchar(17)", - maxLength: 17, - nullable: true); - - migrationBuilder.AddColumn( - name: "PhoneVerifiedBy", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "PhoneVerifiedOn", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_IsPhoneVerified", - table: "Users", - column: "IsPhoneVerified"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneCountryCode", - table: "Users", - column: "PhoneCountryCode"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneE164Formatted", - table: "Users", - column: "PhoneE164Formatted"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneExtension", - table: "Users", - column: "PhoneExtension"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneNumber", - table: "Users", - column: "PhoneNumber"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneVerifiedBy", - table: "Users", - column: "PhoneVerifiedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_PhoneVerifiedOn", - table: "Users", - column: "PhoneVerifiedOn"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Users_IsPhoneVerified", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneCountryCode", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneE164Formatted", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneExtension", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneNumber", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneVerifiedBy", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_PhoneVerifiedOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsPhoneVerified", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneCountryCode", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneE164Formatted", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneExtension", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneNumber", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneVerifiedBy", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PhoneVerifiedOn", - table: "Users"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.Designer.cs deleted file mode 100644 index b085813..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.Designer.cs +++ /dev/null @@ -1,487 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240111000426_AddUserAddressColumns")] - partial class AddUserAddressColumns - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.cs deleted file mode 100644 index 4783ac7..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AddUserAddressColumns : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "AddressCountry", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressFormatted", - table: "Users", - type: "nvarchar(1279)", - maxLength: 1279, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressLocality", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressPostalCode", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressRegion", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressStreet", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressVerifiedBy", - table: "Users", - type: "nvarchar(255)", - maxLength: 255, - nullable: true); - - migrationBuilder.AddColumn( - name: "AddressVerifiedOn", - table: "Users", - type: "datetime2", - nullable: true); - - migrationBuilder.AddColumn( - name: "IsAddressVerified", - table: "Users", - type: "bit", - nullable: false, - defaultValue: false); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressCountry", - table: "Users", - column: "AddressCountry"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressFormatted", - table: "Users", - column: "AddressFormatted"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressLocality", - table: "Users", - column: "AddressLocality"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressPostalCode", - table: "Users", - column: "AddressPostalCode"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressRegion", - table: "Users", - column: "AddressRegion"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressStreet", - table: "Users", - column: "AddressStreet"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressVerifiedBy", - table: "Users", - column: "AddressVerifiedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Users_AddressVerifiedOn", - table: "Users", - column: "AddressVerifiedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Users_IsAddressVerified", - table: "Users", - column: "IsAddressVerified"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Users_AddressCountry", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressFormatted", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressLocality", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressPostalCode", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressRegion", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressStreet", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressVerifiedBy", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_AddressVerifiedOn", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_IsAddressVerified", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressCountry", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressFormatted", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressLocality", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressPostalCode", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressRegion", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressStreet", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressVerifiedBy", - table: "Users"); - - migrationBuilder.DropColumn( - name: "AddressVerifiedOn", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsAddressVerified", - table: "Users"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.Designer.cs deleted file mode 100644 index 8796bac..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.Designer.cs +++ /dev/null @@ -1,531 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240111021330_CreateCustomAttributeTable")] - partial class CreateCustomAttributeTable - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => - { - b.Property("CustomAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); - - b.Property("EntityId") - .HasColumnType("int"); - - b.Property("EntityType") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ValueShortened") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("CustomAttributeId"); - - b.HasIndex("Key"); - - b.HasIndex("ValueShortened"); - - b.HasIndex("EntityType", "EntityId"); - - b.HasIndex("EntityType", "EntityId", "Key") - .IsUnique(); - - b.ToTable("CustomAttributes", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.cs deleted file mode 100644 index 34fd7cd..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateCustomAttributeTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "CustomAttributes", - columns: table => new - { - CustomAttributeId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - EntityType = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - EntityId = table.Column(type: "int", nullable: false), - Key = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Value = table.Column(type: "nvarchar(max)", nullable: false), - ValueShortened = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CustomAttributes", x => x.CustomAttributeId); - }); - - migrationBuilder.CreateIndex( - name: "IX_CustomAttributes_EntityType_EntityId", - table: "CustomAttributes", - columns: new[] { "EntityType", "EntityId" }); - - migrationBuilder.CreateIndex( - name: "IX_CustomAttributes_EntityType_EntityId_Key", - table: "CustomAttributes", - columns: new[] { "EntityType", "EntityId", "Key" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_CustomAttributes_Key", - table: "CustomAttributes", - column: "Key"); - - migrationBuilder.CreateIndex( - name: "IX_CustomAttributes_ValueShortened", - table: "CustomAttributes", - column: "ValueShortened"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CustomAttributes"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.Designer.cs deleted file mode 100644 index c9f0661..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.Designer.cs +++ /dev/null @@ -1,670 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240111040937_CreateRoleTable")] - partial class CreateRoleTable - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => - { - b.Property("CustomAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); - - b.Property("EntityId") - .HasColumnType("int"); - - b.Property("EntityType") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ValueShortened") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("CustomAttributeId"); - - b.HasIndex("Key"); - - b.HasIndex("ValueShortened"); - - b.HasIndex("EntityType", "EntityId"); - - b.HasIndex("EntityType", "EntityId", "Key") - .IsUnique(); - - b.ToTable("CustomAttributes", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => - { - b.Property("RoleId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("RoleId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.Property("UserIdentifierId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("UserIdentifierId"); - - b.HasIndex("Key"); - - b.HasIndex("Value"); - - b.HasIndex("UserId", "Key") - .IsUnique(); - - b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("UserIdentifiers", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Identifiers") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Identifiers"); - - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.cs deleted file mode 100644 index 731a08c..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateRoleTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Roles", - columns: table => new - { - RoleId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - UniqueName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UniqueNameNormalized = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - Description = table.Column(type: "nvarchar(max)", nullable: true), - CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), - AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "bigint", nullable: false), - CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - CreatedOn = table.Column(type: "datetime2", nullable: false), - UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UpdatedOn = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Roles", x => x.RoleId); - }); - - migrationBuilder.CreateTable( - name: "UserIdentifiers", - columns: table => new - { - UserIdentifierId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "int", nullable: false), - TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - Key = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Value = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserIdentifiers", x => x.UserIdentifierId); - table.ForeignKey( - name: "FK_UserIdentifiers_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Roles_AggregateId", - table: "Roles", - column: "AggregateId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Roles_CreatedBy", - table: "Roles", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_CreatedOn", - table: "Roles", - column: "CreatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_DisplayName", - table: "Roles", - column: "DisplayName"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_TenantId", - table: "Roles", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_TenantId_UniqueNameNormalized", - table: "Roles", - columns: new[] { "TenantId", "UniqueNameNormalized" }, - unique: true, - filter: "[TenantId] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_UniqueName", - table: "Roles", - column: "UniqueName"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_UpdatedBy", - table: "Roles", - column: "UpdatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_UpdatedOn", - table: "Roles", - column: "UpdatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_Roles_Version", - table: "Roles", - column: "Version"); - - migrationBuilder.CreateIndex( - name: "IX_UserIdentifiers_Key", - table: "UserIdentifiers", - column: "Key"); - - migrationBuilder.CreateIndex( - name: "IX_UserIdentifiers_TenantId_Key_Value", - table: "UserIdentifiers", - columns: new[] { "TenantId", "Key", "Value" }, - unique: true, - filter: "[TenantId] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_UserIdentifiers_UserId_Key", - table: "UserIdentifiers", - columns: new[] { "UserId", "Key" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_UserIdentifiers_Value", - table: "UserIdentifiers", - column: "Value"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Roles"); - - migrationBuilder.DropTable( - name: "UserIdentifiers"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.Designer.cs deleted file mode 100644 index 7d1a7f7..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.Designer.cs +++ /dev/null @@ -1,700 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240111044308_CreateUserRoleTable")] - partial class CreateUserRoleTable - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => - { - b.Property("CustomAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); - - b.Property("EntityId") - .HasColumnType("int"); - - b.Property("EntityType") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ValueShortened") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("CustomAttributeId"); - - b.HasIndex("Key"); - - b.HasIndex("ValueShortened"); - - b.HasIndex("EntityType", "EntityId"); - - b.HasIndex("EntityType", "EntityId", "Key") - .IsUnique(); - - b.ToTable("CustomAttributes", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => - { - b.Property("RoleId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("RoleId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.Property("UserIdentifierId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("UserIdentifierId"); - - b.HasIndex("Key"); - - b.HasIndex("Value"); - - b.HasIndex("UserId", "Key") - .IsUnique(); - - b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("UserIdentifiers", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.Property("UserId") - .HasColumnType("int"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("UserRoles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Identifiers") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Identifiers"); - - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.cs deleted file mode 100644 index 390ae9b..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateUserRoleTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "UserRoles", - columns: table => new - { - UserId = table.Column(type: "int", nullable: false), - RoleId = table.Column(type: "int", 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: "RoleId", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRoles_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_UserRoles_RoleId", - table: "UserRoles", - column: "RoleId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "UserRoles"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.Designer.cs deleted file mode 100644 index c6d9ec5..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.Designer.cs +++ /dev/null @@ -1,815 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240111164057_CreateApiKeyTables")] - partial class CreateApiKeyTables - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", b => - { - b.Property("ApiKeyId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ApiKeyId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("ExpiresOn") - .HasColumnType("datetime2"); - - b.Property("SecretHash") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("ApiKeyId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("ExpiresOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.ToTable("ApiKeys", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => - { - b.Property("ApiKeyId") - .HasColumnType("int"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("ApiKeyId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("ApiKeyRoles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => - { - b.Property("CustomAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); - - b.Property("EntityId") - .HasColumnType("int"); - - b.Property("EntityType") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ValueShortened") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("CustomAttributeId"); - - b.HasIndex("Key"); - - b.HasIndex("ValueShortened"); - - b.HasIndex("EntityType", "EntityId"); - - b.HasIndex("EntityType", "EntityId", "Key") - .IsUnique(); - - b.ToTable("CustomAttributes", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => - { - b.Property("RoleId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("RoleId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(37) - .HasColumnType("nvarchar(37)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(17) - .HasColumnType("nvarchar(17)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.Property("UserIdentifierId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("UserIdentifierId"); - - b.HasIndex("Key"); - - b.HasIndex("Value"); - - b.HasIndex("UserId", "Key") - .IsUnique(); - - b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("UserIdentifiers", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.Property("UserId") - .HasColumnType("int"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("UserRoles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", null) - .WithMany() - .HasForeignKey("ApiKeyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Identifiers") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Identifiers"); - - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.cs deleted file mode 100644 index 9327168..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateApiKeyTables : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "ApiKeys", - columns: table => new - { - ApiKeyId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - SecretHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: true), - ExpiresOn = table.Column(type: "datetime2", nullable: true), - AuthenticatedOn = table.Column(type: "datetime2", nullable: true), - CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), - AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "bigint", nullable: false), - CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - CreatedOn = table.Column(type: "datetime2", nullable: false), - UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UpdatedOn = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ApiKeys", x => x.ApiKeyId); - }); - - migrationBuilder.CreateTable( - name: "ApiKeyRoles", - columns: table => new - { - ApiKeyId = table.Column(type: "int", nullable: false), - RoleId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ApiKeyRoles", x => new { x.ApiKeyId, x.RoleId }); - table.ForeignKey( - name: "FK_ApiKeyRoles_ApiKeys_ApiKeyId", - column: x => x.ApiKeyId, - principalTable: "ApiKeys", - principalColumn: "ApiKeyId", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ApiKeyRoles_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "RoleId", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeyRoles_RoleId", - table: "ApiKeyRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_AggregateId", - table: "ApiKeys", - column: "AggregateId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_AuthenticatedOn", - table: "ApiKeys", - column: "AuthenticatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_CreatedBy", - table: "ApiKeys", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_CreatedOn", - table: "ApiKeys", - column: "CreatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_DisplayName", - table: "ApiKeys", - column: "DisplayName"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_ExpiresOn", - table: "ApiKeys", - column: "ExpiresOn"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_TenantId", - table: "ApiKeys", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_UpdatedBy", - table: "ApiKeys", - column: "UpdatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_UpdatedOn", - table: "ApiKeys", - column: "UpdatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_ApiKeys_Version", - table: "ApiKeys", - column: "Version"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ApiKeyRoles"); - - migrationBuilder.DropTable( - name: "ApiKeys"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.Designer.cs deleted file mode 100644 index 8215547..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.Designer.cs +++ /dev/null @@ -1,815 +0,0 @@ -// -using System; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20240112010955_AlterUserPhoneColumnLengths")] - partial class AlterUserPhoneColumnLengths - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => - { - b.Property("ActorId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Id") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("PictureUrl") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("ActorId"); - - b.HasIndex("DisplayName"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("Id") - .IsUnique(); - - b.HasIndex("IsDeleted"); - - b.HasIndex("Type"); - - b.ToTable("Actors", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", b => - { - b.Property("ApiKeyId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ApiKeyId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("ExpiresOn") - .HasColumnType("datetime2"); - - b.Property("SecretHash") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("ApiKeyId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("ExpiresOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.ToTable("ApiKeys", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => - { - b.Property("ApiKeyId") - .HasColumnType("int"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("ApiKeyId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("ApiKeyRoles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => - { - b.Property("CustomAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); - - b.Property("EntityId") - .HasColumnType("int"); - - b.Property("EntityType") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ValueShortened") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("CustomAttributeId"); - - b.HasIndex("Key"); - - b.HasIndex("ValueShortened"); - - b.HasIndex("EntityType", "EntityId"); - - b.HasIndex("EntityType", "EntityId", "Key") - .IsUnique(); - - b.ToTable("CustomAttributes", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => - { - b.Property("RoleId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("Description") - .HasColumnType("nvarchar(max)"); - - b.Property("DisplayName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("RoleId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisplayName"); - - b.HasIndex("TenantId"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Roles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.Property("SessionId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("IsPersistent") - .HasColumnType("bit"); - - b.Property("SecretHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("SignedOutOn") - .HasColumnType("datetime2"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("SessionId"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("IsActive"); - - b.HasIndex("IsPersistent"); - - b.HasIndex("SignedOutBy"); - - b.HasIndex("SignedOutOn"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("UserId"); - - b.HasIndex("Version"); - - b.ToTable("Sessions", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); - - b.Property("AddressCountry") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressFormatted") - .HasMaxLength(1279) - .HasColumnType("nvarchar(1279)"); - - b.Property("AddressLocality") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressPostalCode") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressRegion") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressStreet") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AddressVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("AggregateId") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("AuthenticatedOn") - .HasColumnType("datetime2"); - - b.Property("Birthdate") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("CreatedOn") - .HasColumnType("datetime2"); - - b.Property("CustomAttributesSerialized") - .HasColumnType("nvarchar(max)") - .HasColumnName("CustomAttributes"); - - b.Property("DisabledBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("DisabledOn") - .HasColumnType("datetime2"); - - b.Property("EmailAddress") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailAddressNormalized") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("EmailVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("FirstName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("FullName") - .HasMaxLength(767) - .HasColumnType("nvarchar(767)"); - - b.Property("Gender") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("HasPassword") - .HasColumnType("bit"); - - b.Property("IsAddressVerified") - .HasColumnType("bit"); - - b.Property("IsConfirmed") - .HasColumnType("bit"); - - b.Property("IsDisabled") - .HasColumnType("bit"); - - b.Property("IsEmailVerified") - .HasColumnType("bit"); - - b.Property("IsPhoneVerified") - .HasColumnType("bit"); - - b.Property("LastName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Locale") - .HasMaxLength(16) - .HasColumnType("nvarchar(16)"); - - b.Property("MiddleName") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Nickname") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PasswordChangedOn") - .HasColumnType("datetime2"); - - b.Property("PasswordHash") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneCountryCode") - .HasMaxLength(2) - .HasColumnType("nvarchar(2)"); - - b.Property("PhoneE164Formatted") - .HasMaxLength(40) - .HasColumnType("nvarchar(40)"); - - b.Property("PhoneExtension") - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("PhoneNumber") - .HasMaxLength(20) - .HasColumnType("nvarchar(20)"); - - b.Property("PhoneVerifiedBy") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("PhoneVerifiedOn") - .HasColumnType("datetime2"); - - b.Property("Picture") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("Profile") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TimeZone") - .HasMaxLength(32) - .HasColumnType("nvarchar(32)"); - - b.Property("UniqueName") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UniqueNameNormalized") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedBy") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UpdatedOn") - .HasColumnType("datetime2"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.Property("Website") - .HasMaxLength(2048) - .HasColumnType("nvarchar(2048)"); - - b.HasKey("UserId"); - - b.HasIndex("AddressCountry"); - - b.HasIndex("AddressFormatted"); - - b.HasIndex("AddressLocality"); - - b.HasIndex("AddressPostalCode"); - - b.HasIndex("AddressRegion"); - - b.HasIndex("AddressStreet"); - - b.HasIndex("AddressVerifiedBy"); - - b.HasIndex("AddressVerifiedOn"); - - b.HasIndex("AggregateId") - .IsUnique(); - - b.HasIndex("AuthenticatedOn"); - - b.HasIndex("Birthdate"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("CreatedOn"); - - b.HasIndex("DisabledBy"); - - b.HasIndex("DisabledOn"); - - b.HasIndex("EmailAddress"); - - b.HasIndex("EmailVerifiedBy"); - - b.HasIndex("EmailVerifiedOn"); - - b.HasIndex("FirstName"); - - b.HasIndex("FullName"); - - b.HasIndex("Gender"); - - b.HasIndex("HasPassword"); - - b.HasIndex("IsAddressVerified"); - - b.HasIndex("IsConfirmed"); - - b.HasIndex("IsDisabled"); - - b.HasIndex("IsEmailVerified"); - - b.HasIndex("IsPhoneVerified"); - - b.HasIndex("LastName"); - - b.HasIndex("Locale"); - - b.HasIndex("MiddleName"); - - b.HasIndex("Nickname"); - - b.HasIndex("PasswordChangedBy"); - - b.HasIndex("PasswordChangedOn"); - - b.HasIndex("PhoneCountryCode"); - - b.HasIndex("PhoneE164Formatted"); - - b.HasIndex("PhoneExtension"); - - b.HasIndex("PhoneNumber"); - - b.HasIndex("PhoneVerifiedBy"); - - b.HasIndex("PhoneVerifiedOn"); - - b.HasIndex("TenantId"); - - b.HasIndex("TimeZone"); - - b.HasIndex("UniqueName"); - - b.HasIndex("UpdatedBy"); - - b.HasIndex("UpdatedOn"); - - b.HasIndex("Version"); - - b.HasIndex("TenantId", "EmailAddressNormalized"); - - b.HasIndex("TenantId", "UniqueNameNormalized") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("Users", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.Property("UserIdentifierId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); - - b.Property("Key") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("TenantId") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.HasKey("UserIdentifierId"); - - b.HasIndex("Key"); - - b.HasIndex("Value"); - - b.HasIndex("UserId", "Key") - .IsUnique(); - - b.HasIndex("TenantId", "Key", "Value") - .IsUnique() - .HasFilter("[TenantId] IS NOT NULL"); - - b.ToTable("UserIdentifiers", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.Property("UserId") - .HasColumnType("int"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("UserRoles", (string)null); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", null) - .WithMany() - .HasForeignKey("ApiKeyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Sessions") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") - .WithMany("Identifiers") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => - { - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => - { - b.Navigation("Identifiers"); - - b.Navigation("Sessions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.cs deleted file mode 100644 index cb076fc..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class AlterUserPhoneColumnLengths : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "PhoneNumber", - table: "Users", - type: "nvarchar(20)", - maxLength: 20, - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(17)", - oldMaxLength: 17, - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "PhoneE164Formatted", - table: "Users", - type: "nvarchar(40)", - maxLength: 40, - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(37)", - oldMaxLength: 37, - oldNullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "PhoneNumber", - table: "Users", - type: "nvarchar(17)", - maxLength: 17, - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(20)", - oldMaxLength: 20, - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "PhoneE164Formatted", - table: "Users", - type: "nvarchar(37)", - maxLength: 37, - nullable: true, - oldClrType: typeof(string), - oldType: "nvarchar(40)", - oldMaxLength: 40, - oldNullable: true); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.cs deleted file mode 100644 index c871427..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateTokenBlacklistTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "TokenBlacklist", - columns: table => new - { - BlacklistedTokenId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TokenId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - ExpiresOn = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_TokenBlacklist", x => x.BlacklistedTokenId); - }); - - migrationBuilder.CreateIndex( - name: "IX_TokenBlacklist_ExpiresOn", - table: "TokenBlacklist", - column: "ExpiresOn"); - - migrationBuilder.CreateIndex( - name: "IX_TokenBlacklist_TokenId", - table: "TokenBlacklist", - column: "TokenId", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "TokenBlacklist"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.cs deleted file mode 100644 index 5601644..0000000 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations -{ - /// - public partial class CreateOneTimePasswordTable : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "OneTimePasswords", - columns: table => new - { - OneTimePasswordId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), - PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - ExpiresOn = table.Column(type: "datetime2", nullable: true), - MaximumAttempts = table.Column(type: "int", nullable: true), - AttemptCount = table.Column(type: "int", nullable: false), - HasValidationSucceeded = table.Column(type: "bit", nullable: false), - CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), - AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - Version = table.Column(type: "bigint", nullable: false), - CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - CreatedOn = table.Column(type: "datetime2", nullable: false), - UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), - UpdatedOn = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OneTimePasswords", x => x.OneTimePasswordId); - }); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_AggregateId", - table: "OneTimePasswords", - column: "AggregateId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_AttemptCount", - table: "OneTimePasswords", - column: "AttemptCount"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_CreatedBy", - table: "OneTimePasswords", - column: "CreatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_CreatedOn", - table: "OneTimePasswords", - column: "CreatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_ExpiresOn", - table: "OneTimePasswords", - column: "ExpiresOn"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_HasValidationSucceeded", - table: "OneTimePasswords", - column: "HasValidationSucceeded"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_MaximumAttempts", - table: "OneTimePasswords", - column: "MaximumAttempts"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_TenantId", - table: "OneTimePasswords", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_UpdatedBy", - table: "OneTimePasswords", - column: "UpdatedBy"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_UpdatedOn", - table: "OneTimePasswords", - column: "UpdatedOn"); - - migrationBuilder.CreateIndex( - name: "IX_OneTimePasswords_Version", - table: "OneTimePasswords", - column: "Version"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "OneTimePasswords"); - } - } -} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.Designer.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.Designer.cs new file mode 100644 index 0000000..c469575 --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.Designer.cs @@ -0,0 +1,925 @@ +// +using Logitar.Identity.EntityFrameworkCore.Relational; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations +{ + [DbContext(typeof(IdentityContext))] + [Migration("20240305022614_LogitarIdentity_1_0_0")] + partial class LogitarIdentity_1_0_0 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ActorEntity", b => + { + b.Property("ActorId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ActorId")); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("EmailAddress") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Id") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("PictureUrl") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("ActorId"); + + b.HasIndex("DisplayName"); + + b.HasIndex("EmailAddress"); + + b.HasIndex("Id") + .IsUnique(); + + b.HasIndex("IsDeleted"); + + b.HasIndex("Type"); + + b.ToTable("Actors", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", b => + { + b.Property("ApiKeyId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ApiKeyId")); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AuthenticatedOn") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("nvarchar(max)") + .HasColumnName("CustomAttributes"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("ExpiresOn") + .HasColumnType("datetime2"); + + b.Property("SecretHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedOn") + .HasColumnType("datetime2"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.HasKey("ApiKeyId"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("AuthenticatedOn"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("DisplayName"); + + b.HasIndex("ExpiresOn"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("Version"); + + b.ToTable("ApiKeys", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => + { + b.Property("ApiKeyId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("ApiKeyId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("ApiKeyRoles", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.BlacklistedTokenEntity", b => + { + b.Property("BlacklistedTokenId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("BlacklistedTokenId")); + + b.Property("ExpiresOn") + .HasColumnType("datetime2"); + + b.Property("TokenId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("BlacklistedTokenId"); + + b.HasIndex("ExpiresOn"); + + b.HasIndex("TokenId") + .IsUnique(); + + b.ToTable("TokenBlacklist", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.CustomAttributeEntity", b => + { + b.Property("CustomAttributeId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CustomAttributeId")); + + b.Property("EntityId") + .HasColumnType("int"); + + b.Property("EntityType") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Value") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ValueShortened") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("CustomAttributeId"); + + b.HasIndex("Key"); + + b.HasIndex("ValueShortened"); + + b.HasIndex("EntityType", "EntityId"); + + b.HasIndex("EntityType", "EntityId", "Key") + .IsUnique(); + + b.ToTable("CustomAttributes", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.OneTimePasswordEntity", b => + { + b.Property("OneTimePasswordId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("OneTimePasswordId")); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AttemptCount") + .HasColumnType("int"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("nvarchar(max)") + .HasColumnName("CustomAttributes"); + + b.Property("ExpiresOn") + .HasColumnType("datetime2"); + + b.Property("HasValidationSucceeded") + .HasColumnType("bit"); + + b.Property("MaximumAttempts") + .HasColumnType("int"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedOn") + .HasColumnType("datetime2"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.HasKey("OneTimePasswordId"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("AttemptCount"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("ExpiresOn"); + + b.HasIndex("HasValidationSucceeded"); + + b.HasIndex("MaximumAttempts"); + + b.HasIndex("TenantId"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("Version"); + + b.ToTable("OneTimePasswords", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", b => + { + b.Property("RoleId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("RoleId")); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("nvarchar(max)") + .HasColumnName("CustomAttributes"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("DisplayName") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UniqueName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UniqueNameNormalized") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedOn") + .HasColumnType("datetime2"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.HasKey("RoleId"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("DisplayName"); + + b.HasIndex("TenantId"); + + b.HasIndex("UniqueName"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("Version"); + + b.HasIndex("TenantId", "UniqueNameNormalized") + .IsUnique() + .HasFilter("[TenantId] IS NOT NULL"); + + b.ToTable("Roles", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => + { + b.Property("SessionId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("SessionId")); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("nvarchar(max)") + .HasColumnName("CustomAttributes"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsPersistent") + .HasColumnType("bit"); + + b.Property("SecretHash") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("SignedOutBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("SignedOutOn") + .HasColumnType("datetime2"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedOn") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.HasKey("SessionId"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("IsActive"); + + b.HasIndex("IsPersistent"); + + b.HasIndex("SignedOutBy"); + + b.HasIndex("SignedOutOn"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("UserId"); + + b.HasIndex("Version"); + + b.ToTable("Sessions", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId")); + + b.Property("AddressCountry") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressFormatted") + .HasMaxLength(1279) + .HasColumnType("nvarchar(1279)"); + + b.Property("AddressLocality") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressPostalCode") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressRegion") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressStreet") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressVerifiedBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AddressVerifiedOn") + .HasColumnType("datetime2"); + + b.Property("AggregateId") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("AuthenticatedOn") + .HasColumnType("datetime2"); + + b.Property("Birthdate") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("CreatedOn") + .HasColumnType("datetime2"); + + b.Property("CustomAttributesSerialized") + .HasColumnType("nvarchar(max)") + .HasColumnName("CustomAttributes"); + + b.Property("DisabledBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("DisabledOn") + .HasColumnType("datetime2"); + + b.Property("EmailAddress") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("EmailAddressNormalized") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("EmailVerifiedBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("EmailVerifiedOn") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("FullName") + .HasMaxLength(767) + .HasColumnType("nvarchar(767)"); + + b.Property("Gender") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("HasPassword") + .HasColumnType("bit"); + + b.Property("IsAddressVerified") + .HasColumnType("bit"); + + b.Property("IsConfirmed") + .HasColumnType("bit"); + + b.Property("IsDisabled") + .HasColumnType("bit"); + + b.Property("IsEmailVerified") + .HasColumnType("bit"); + + b.Property("IsPhoneVerified") + .HasColumnType("bit"); + + b.Property("LastName") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Locale") + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("MiddleName") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Nickname") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PasswordChangedBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PasswordChangedOn") + .HasColumnType("datetime2"); + + b.Property("PasswordHash") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PhoneCountryCode") + .HasMaxLength(2) + .HasColumnType("nvarchar(2)"); + + b.Property("PhoneE164Formatted") + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("PhoneExtension") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("PhoneNumber") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("PhoneVerifiedBy") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PhoneVerifiedOn") + .HasColumnType("datetime2"); + + b.Property("Picture") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.Property("Profile") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TimeZone") + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("UniqueName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UniqueNameNormalized") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedOn") + .HasColumnType("datetime2"); + + b.Property("Version") + .HasColumnType("bigint"); + + b.Property("Website") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.HasKey("UserId"); + + b.HasIndex("AddressCountry"); + + b.HasIndex("AddressFormatted"); + + b.HasIndex("AddressLocality"); + + b.HasIndex("AddressPostalCode"); + + b.HasIndex("AddressRegion"); + + b.HasIndex("AddressStreet"); + + b.HasIndex("AddressVerifiedBy"); + + b.HasIndex("AddressVerifiedOn"); + + b.HasIndex("AggregateId") + .IsUnique(); + + b.HasIndex("AuthenticatedOn"); + + b.HasIndex("Birthdate"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("CreatedOn"); + + b.HasIndex("DisabledBy"); + + b.HasIndex("DisabledOn"); + + b.HasIndex("EmailAddress"); + + b.HasIndex("EmailVerifiedBy"); + + b.HasIndex("EmailVerifiedOn"); + + b.HasIndex("FirstName"); + + b.HasIndex("FullName"); + + b.HasIndex("Gender"); + + b.HasIndex("HasPassword"); + + b.HasIndex("IsAddressVerified"); + + b.HasIndex("IsConfirmed"); + + b.HasIndex("IsDisabled"); + + b.HasIndex("IsEmailVerified"); + + b.HasIndex("IsPhoneVerified"); + + b.HasIndex("LastName"); + + b.HasIndex("Locale"); + + b.HasIndex("MiddleName"); + + b.HasIndex("Nickname"); + + b.HasIndex("PasswordChangedBy"); + + b.HasIndex("PasswordChangedOn"); + + b.HasIndex("PhoneCountryCode"); + + b.HasIndex("PhoneE164Formatted"); + + b.HasIndex("PhoneExtension"); + + b.HasIndex("PhoneNumber"); + + b.HasIndex("PhoneVerifiedBy"); + + b.HasIndex("PhoneVerifiedOn"); + + b.HasIndex("TenantId"); + + b.HasIndex("TimeZone"); + + b.HasIndex("UniqueName"); + + b.HasIndex("UpdatedBy"); + + b.HasIndex("UpdatedOn"); + + b.HasIndex("Version"); + + b.HasIndex("TenantId", "EmailAddressNormalized"); + + b.HasIndex("TenantId", "UniqueNameNormalized") + .IsUnique() + .HasFilter("[TenantId] IS NOT NULL"); + + b.ToTable("Users", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => + { + b.Property("UserIdentifierId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserIdentifierId")); + + b.Property("Key") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TenantId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("UserIdentifierId"); + + b.HasIndex("Key"); + + b.HasIndex("Value"); + + b.HasIndex("UserId", "Key") + .IsUnique(); + + b.HasIndex("TenantId", "Key", "Value") + .IsUnique() + .HasFilter("[TenantId] IS NOT NULL"); + + b.ToTable("UserIdentifiers", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("UserRoles", (string)null); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyRoleEntity", b => + { + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.ApiKeyEntity", null) + .WithMany() + .HasForeignKey("ApiKeyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.SessionEntity", b => + { + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") + .WithMany("Sessions") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserIdentifierEntity", b => + { + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", "User") + .WithMany("Identifiers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserRoleEntity", b => + { + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.RoleEntity", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Logitar.Identity.EntityFrameworkCore.Relational.Entities.UserEntity", b => + { + b.Navigation("Identifiers"); + + b.Navigation("Sessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.cs new file mode 100644 index 0000000..4f4c10d --- /dev/null +++ b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.cs @@ -0,0 +1,884 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Migrations +{ + /// + public partial class LogitarIdentity_1_0_0 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Actors", + columns: table => new + { + ActorId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Id = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Type = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + EmailAddress = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + PictureUrl = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Actors", x => x.ActorId); + }); + + migrationBuilder.CreateTable( + name: "ApiKeys", + columns: table => new + { + ApiKeyId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + SecretHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: true), + ExpiresOn = table.Column(type: "datetime2", nullable: true), + AuthenticatedOn = table.Column(type: "datetime2", nullable: true), + CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), + AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "datetime2", nullable: false), + UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ApiKeys", x => x.ApiKeyId); + }); + + migrationBuilder.CreateTable( + name: "CustomAttributes", + columns: table => new + { + CustomAttributeId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + EntityType = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + EntityId = table.Column(type: "int", nullable: false), + Key = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Value = table.Column(type: "nvarchar(max)", nullable: false), + ValueShortened = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CustomAttributes", x => x.CustomAttributeId); + }); + + migrationBuilder.CreateTable( + name: "OneTimePasswords", + columns: table => new + { + OneTimePasswordId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + ExpiresOn = table.Column(type: "datetime2", nullable: true), + MaximumAttempts = table.Column(type: "int", nullable: true), + AttemptCount = table.Column(type: "int", nullable: false), + HasValidationSucceeded = table.Column(type: "bit", nullable: false), + CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), + AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "datetime2", nullable: false), + UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OneTimePasswords", x => x.OneTimePasswordId); + }); + + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + RoleId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + UniqueName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UniqueNameNormalized = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + DisplayName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Description = table.Column(type: "nvarchar(max)", nullable: true), + CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), + AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "datetime2", nullable: false), + UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.RoleId); + }); + + migrationBuilder.CreateTable( + name: "TokenBlacklist", + columns: table => new + { + BlacklistedTokenId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TokenId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + ExpiresOn = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_TokenBlacklist", x => x.BlacklistedTokenId); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + UserId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + UniqueName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UniqueNameNormalized = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + PasswordChangedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + PasswordChangedOn = table.Column(type: "datetime2", nullable: true), + HasPassword = table.Column(type: "bit", nullable: false), + DisabledBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + DisabledOn = table.Column(type: "datetime2", nullable: true), + IsDisabled = table.Column(type: "bit", nullable: false), + AddressStreet = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressLocality = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressPostalCode = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressRegion = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressCountry = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressFormatted = table.Column(type: "nvarchar(1279)", maxLength: 1279, nullable: true), + AddressVerifiedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + AddressVerifiedOn = table.Column(type: "datetime2", nullable: true), + IsAddressVerified = table.Column(type: "bit", nullable: false), + EmailAddress = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + EmailAddressNormalized = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + EmailVerifiedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + EmailVerifiedOn = table.Column(type: "datetime2", nullable: true), + IsEmailVerified = table.Column(type: "bit", nullable: false), + PhoneCountryCode = table.Column(type: "nvarchar(2)", maxLength: 2, nullable: true), + PhoneNumber = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + PhoneExtension = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: true), + PhoneE164Formatted = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: true), + PhoneVerifiedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + PhoneVerifiedOn = table.Column(type: "datetime2", nullable: true), + IsPhoneVerified = table.Column(type: "bit", nullable: false), + IsConfirmed = table.Column(type: "bit", nullable: false), + FirstName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + MiddleName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + LastName = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + FullName = table.Column(type: "nvarchar(767)", maxLength: 767, nullable: true), + Nickname = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Birthdate = table.Column(type: "datetime2", nullable: true), + Gender = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Locale = table.Column(type: "nvarchar(16)", maxLength: 16, nullable: true), + TimeZone = table.Column(type: "nvarchar(32)", maxLength: 32, nullable: true), + Picture = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true), + Profile = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true), + Website = table.Column(type: "nvarchar(2048)", maxLength: 2048, nullable: true), + AuthenticatedOn = table.Column(type: "datetime2", nullable: true), + CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), + AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "datetime2", nullable: false), + UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.UserId); + }); + + migrationBuilder.CreateTable( + name: "ApiKeyRoles", + columns: table => new + { + ApiKeyId = table.Column(type: "int", nullable: false), + RoleId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ApiKeyRoles", x => new { x.ApiKeyId, x.RoleId }); + table.ForeignKey( + name: "FK_ApiKeyRoles_ApiKeys_ApiKeyId", + column: x => x.ApiKeyId, + principalTable: "ApiKeys", + principalColumn: "ApiKeyId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ApiKeyRoles_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "RoleId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Sessions", + columns: table => new + { + SessionId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false), + SecretHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + IsPersistent = table.Column(type: "bit", nullable: false), + SignedOutBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + SignedOutOn = table.Column(type: "datetime2", nullable: true), + IsActive = table.Column(type: "bit", nullable: false), + CustomAttributes = table.Column(type: "nvarchar(max)", nullable: true), + AggregateId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Version = table.Column(type: "bigint", nullable: false), + CreatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + CreatedOn = table.Column(type: "datetime2", nullable: false), + UpdatedBy = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + UpdatedOn = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sessions", x => x.SessionId); + table.ForeignKey( + name: "FK_Sessions_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "UserIdentifiers", + columns: table => new + { + UserIdentifierId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false), + TenantId = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), + Key = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + Value = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserIdentifiers", x => x.UserIdentifierId); + table.ForeignKey( + name: "FK_UserIdentifiers_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "UserRoles", + columns: table => new + { + UserId = table.Column(type: "int", nullable: false), + RoleId = table.Column(type: "int", 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: "RoleId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserRoles_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Actors_DisplayName", + table: "Actors", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_EmailAddress", + table: "Actors", + column: "EmailAddress"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_Id", + table: "Actors", + column: "Id", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Actors_IsDeleted", + table: "Actors", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_Actors_Type", + table: "Actors", + column: "Type"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeyRoles_RoleId", + table: "ApiKeyRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_AggregateId", + table: "ApiKeys", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_AuthenticatedOn", + table: "ApiKeys", + column: "AuthenticatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_CreatedBy", + table: "ApiKeys", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_CreatedOn", + table: "ApiKeys", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_DisplayName", + table: "ApiKeys", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_ExpiresOn", + table: "ApiKeys", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_TenantId", + table: "ApiKeys", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_UpdatedBy", + table: "ApiKeys", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_UpdatedOn", + table: "ApiKeys", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_ApiKeys_Version", + table: "ApiKeys", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_EntityType_EntityId", + table: "CustomAttributes", + columns: new[] { "EntityType", "EntityId" }); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_EntityType_EntityId_Key", + table: "CustomAttributes", + columns: new[] { "EntityType", "EntityId", "Key" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_Key", + table: "CustomAttributes", + column: "Key"); + + migrationBuilder.CreateIndex( + name: "IX_CustomAttributes_ValueShortened", + table: "CustomAttributes", + column: "ValueShortened"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_AggregateId", + table: "OneTimePasswords", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_AttemptCount", + table: "OneTimePasswords", + column: "AttemptCount"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_CreatedBy", + table: "OneTimePasswords", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_CreatedOn", + table: "OneTimePasswords", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_ExpiresOn", + table: "OneTimePasswords", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_HasValidationSucceeded", + table: "OneTimePasswords", + column: "HasValidationSucceeded"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_MaximumAttempts", + table: "OneTimePasswords", + column: "MaximumAttempts"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_TenantId", + table: "OneTimePasswords", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_UpdatedBy", + table: "OneTimePasswords", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_UpdatedOn", + table: "OneTimePasswords", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_OneTimePasswords_Version", + table: "OneTimePasswords", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_AggregateId", + table: "Roles", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Roles_CreatedBy", + table: "Roles", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_CreatedOn", + table: "Roles", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_DisplayName", + table: "Roles", + column: "DisplayName"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_TenantId", + table: "Roles", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_TenantId_UniqueNameNormalized", + table: "Roles", + columns: new[] { "TenantId", "UniqueNameNormalized" }, + unique: true, + filter: "[TenantId] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UniqueName", + table: "Roles", + column: "UniqueName"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UpdatedBy", + table: "Roles", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_UpdatedOn", + table: "Roles", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_Version", + table: "Roles", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_AggregateId", + table: "Sessions", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_CreatedBy", + table: "Sessions", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_CreatedOn", + table: "Sessions", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_IsActive", + table: "Sessions", + column: "IsActive"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_IsPersistent", + table: "Sessions", + column: "IsPersistent"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_SignedOutBy", + table: "Sessions", + column: "SignedOutBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_SignedOutOn", + table: "Sessions", + column: "SignedOutOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UpdatedBy", + table: "Sessions", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UpdatedOn", + table: "Sessions", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_UserId", + table: "Sessions", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_Version", + table: "Sessions", + column: "Version"); + + migrationBuilder.CreateIndex( + name: "IX_TokenBlacklist_ExpiresOn", + table: "TokenBlacklist", + column: "ExpiresOn"); + + migrationBuilder.CreateIndex( + name: "IX_TokenBlacklist_TokenId", + table: "TokenBlacklist", + column: "TokenId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_Key", + table: "UserIdentifiers", + column: "Key"); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_TenantId_Key_Value", + table: "UserIdentifiers", + columns: new[] { "TenantId", "Key", "Value" }, + unique: true, + filter: "[TenantId] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_UserId_Key", + table: "UserIdentifiers", + columns: new[] { "UserId", "Key" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_UserIdentifiers_Value", + table: "UserIdentifiers", + column: "Value"); + + migrationBuilder.CreateIndex( + name: "IX_UserRoles_RoleId", + table: "UserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressCountry", + table: "Users", + column: "AddressCountry"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressFormatted", + table: "Users", + column: "AddressFormatted"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressLocality", + table: "Users", + column: "AddressLocality"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressPostalCode", + table: "Users", + column: "AddressPostalCode"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressRegion", + table: "Users", + column: "AddressRegion"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressStreet", + table: "Users", + column: "AddressStreet"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressVerifiedBy", + table: "Users", + column: "AddressVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AddressVerifiedOn", + table: "Users", + column: "AddressVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_AggregateId", + table: "Users", + column: "AggregateId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Users_AuthenticatedOn", + table: "Users", + column: "AuthenticatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Birthdate", + table: "Users", + column: "Birthdate"); + + migrationBuilder.CreateIndex( + name: "IX_Users_CreatedBy", + table: "Users", + column: "CreatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_CreatedOn", + table: "Users", + column: "CreatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_DisabledBy", + table: "Users", + column: "DisabledBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_DisabledOn", + table: "Users", + column: "DisabledOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailAddress", + table: "Users", + column: "EmailAddress"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailVerifiedBy", + table: "Users", + column: "EmailVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_EmailVerifiedOn", + table: "Users", + column: "EmailVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_FirstName", + table: "Users", + column: "FirstName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_FullName", + table: "Users", + column: "FullName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Gender", + table: "Users", + column: "Gender"); + + migrationBuilder.CreateIndex( + name: "IX_Users_HasPassword", + table: "Users", + column: "HasPassword"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsAddressVerified", + table: "Users", + column: "IsAddressVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsConfirmed", + table: "Users", + column: "IsConfirmed"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsDisabled", + table: "Users", + column: "IsDisabled"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsEmailVerified", + table: "Users", + column: "IsEmailVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_IsPhoneVerified", + table: "Users", + column: "IsPhoneVerified"); + + migrationBuilder.CreateIndex( + name: "IX_Users_LastName", + table: "Users", + column: "LastName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Locale", + table: "Users", + column: "Locale"); + + migrationBuilder.CreateIndex( + name: "IX_Users_MiddleName", + table: "Users", + column: "MiddleName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Nickname", + table: "Users", + column: "Nickname"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PasswordChangedBy", + table: "Users", + column: "PasswordChangedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PasswordChangedOn", + table: "Users", + column: "PasswordChangedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneCountryCode", + table: "Users", + column: "PhoneCountryCode"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneE164Formatted", + table: "Users", + column: "PhoneE164Formatted"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneExtension", + table: "Users", + column: "PhoneExtension"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneNumber", + table: "Users", + column: "PhoneNumber"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneVerifiedBy", + table: "Users", + column: "PhoneVerifiedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_PhoneVerifiedOn", + table: "Users", + column: "PhoneVerifiedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId", + table: "Users", + column: "TenantId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId_EmailAddressNormalized", + table: "Users", + columns: new[] { "TenantId", "EmailAddressNormalized" }); + + migrationBuilder.CreateIndex( + name: "IX_Users_TenantId_UniqueNameNormalized", + table: "Users", + columns: new[] { "TenantId", "UniqueNameNormalized" }, + unique: true, + filter: "[TenantId] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_Users_TimeZone", + table: "Users", + column: "TimeZone"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UniqueName", + table: "Users", + column: "UniqueName"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UpdatedBy", + table: "Users", + column: "UpdatedBy"); + + migrationBuilder.CreateIndex( + name: "IX_Users_UpdatedOn", + table: "Users", + column: "UpdatedOn"); + + migrationBuilder.CreateIndex( + name: "IX_Users_Version", + table: "Users", + column: "Version"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Actors"); + + migrationBuilder.DropTable( + name: "ApiKeyRoles"); + + migrationBuilder.DropTable( + name: "CustomAttributes"); + + migrationBuilder.DropTable( + name: "OneTimePasswords"); + + migrationBuilder.DropTable( + name: "Sessions"); + + migrationBuilder.DropTable( + name: "TokenBlacklist"); + + migrationBuilder.DropTable( + name: "UserIdentifiers"); + + migrationBuilder.DropTable( + name: "UserRoles"); + + migrationBuilder.DropTable( + name: "ApiKeys"); + + migrationBuilder.DropTable( + name: "Roles"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/IdentityContextModelSnapshot.cs b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/IdentityContextModelSnapshot.cs index 0849ed9..f2d0a9f 100644 --- a/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/IdentityContextModelSnapshot.cs +++ b/src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/IdentityContextModelSnapshot.cs @@ -1,5 +1,4 @@ // -using System; using Logitar.Identity.EntityFrameworkCore.Relational; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests.csproj b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests.csproj new file mode 100644 index 0000000..5eace0b --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests.csproj @@ -0,0 +1,53 @@ + + + + net8.0 + enable + enable + + false + true + Logitar.Identity.EntityFrameworkCore.PostgreSQL + + + + True + + + + True + + + + + + + + + PreserveNewest + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs new file mode 100644 index 0000000..7f806ae --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Repositories; + +[Trait(Traits.Category, Categories.Integration)] +public class ApiKeyRepositoryTests : ApiKeyRepositoryTestsBase, IAsyncLifetime +{ + public ApiKeyRepositoryTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs new file mode 100644 index 0000000..2f87931 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Repositories; + +[Trait(Traits.Category, Categories.Integration)] +public class OneTimePasswordRepositoryTests : OneTimePasswordRepositoryTestsBase, IAsyncLifetime +{ + public OneTimePasswordRepositoryTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/RoleRepositoryTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/RoleRepositoryTests.cs new file mode 100644 index 0000000..1856e59 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/RoleRepositoryTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Repositories; + +[Trait(Traits.Category, Categories.Integration)] +public class RoleRepositoryTests : RoleRepositoryTestsBase, IAsyncLifetime +{ + public RoleRepositoryTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/SessionRepositoryTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/SessionRepositoryTests.cs new file mode 100644 index 0000000..211f63d --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/SessionRepositoryTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Repositories; + +[Trait(Traits.Category, Categories.Integration)] +public class SessionRepositoryTests : SessionRepositoryTestsBase, IAsyncLifetime +{ + public SessionRepositoryTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/UserRepositoryTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/UserRepositoryTests.cs new file mode 100644 index 0000000..251c10e --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/UserRepositoryTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Repositories; + +[Trait(Traits.Category, Categories.Integration)] +public class UserRepositoryTests : UserRepositoryTestsBase, IAsyncLifetime +{ + public UserRepositoryTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Tokens/TokenBlacklistTests.cs b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Tokens/TokenBlacklistTests.cs new file mode 100644 index 0000000..719e966 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Tokens/TokenBlacklistTests.cs @@ -0,0 +1,23 @@ +using Logitar.Data; +using Logitar.Data.PostgreSQL; +using Logitar.Identity.EntityFrameworkCore.Relational.Tokens; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.PostgreSQL.Tokens; + +[Trait(Traits.Category, Categories.Integration)] +public class TokenBlacklistTests : TokenBlacklistTestsBase, IAsyncLifetime +{ + public TokenBlacklistTests() : base() + { + } + + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + string connectionString = (configuration.GetValue("POSTGRESQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCorePostgreSQL(connectionString); + } + + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => PostgresDeleteBuilder.From(table); +} diff --git a/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/appsettings.json b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/appsettings.json new file mode 100644 index 0000000..41584a8 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/appsettings.json @@ -0,0 +1,3 @@ +{ + "POSTGRESQLCONNSTR_Identity": "User ID=postgres;Password=zHSNLvy74Z3nUgcC;Host=host.docker.internal;Port=5436;Database={Database};" +} \ No newline at end of file diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertApiKeys.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertApiKeys.cs similarity index 83% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertApiKeys.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertApiKeys.cs index b40b1de..0e51718 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertApiKeys.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertApiKeys.cs @@ -1,9 +1,8 @@ using Logitar.Identity.Domain.ApiKeys; using Logitar.Identity.Domain.Roles; -using Logitar.Identity.EntityFrameworkCore.Relational; using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class AssertApiKeys { @@ -18,16 +17,16 @@ public static void AreEqual(ApiKeyAggregate? apiKey, ApiKeyEntity? entity) Assert.Equal(apiKey.Version, entity.Version); Assert.Equal(apiKey.CreatedBy.Value, entity.CreatedBy); - Assertions.Equal(apiKey.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(apiKey.CreatedOn, entity.CreatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(apiKey.UpdatedBy.Value, entity.UpdatedBy); - Assertions.Equal(apiKey.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(apiKey.UpdatedOn, entity.UpdatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(apiKey.TenantId?.Value, entity.TenantId); Assert.NotEmpty(entity.SecretHash); Assert.Equal(apiKey.DisplayName.Value, entity.DisplayName); Assert.Equal(apiKey.Description?.Value, entity.Description); - Assert.Equal(apiKey.ExpiresOn?.ToUniversalTime(), entity.ExpiresOn); - Assert.Equal(apiKey.AuthenticatedOn?.ToUniversalTime(), entity.AuthenticatedOn); + Assertions.Equal(apiKey.ExpiresOn?.ToUniversalTime(), entity.ExpiresOn, TimeSpan.FromSeconds(1)); + Assertions.Equal(apiKey.AuthenticatedOn?.ToUniversalTime(), entity.AuthenticatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(apiKey.CustomAttributes, entity.CustomAttributes); diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertOneTimePasswords.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertOneTimePasswords.cs similarity index 89% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertOneTimePasswords.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertOneTimePasswords.cs index c8fd1fa..c3748f6 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertOneTimePasswords.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertOneTimePasswords.cs @@ -1,7 +1,7 @@ using Logitar.Identity.Domain.Passwords; using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class AssertOneTimePasswords { @@ -16,13 +16,13 @@ public static void AreEqual(OneTimePasswordAggregate? oneTimePassword, OneTimePa Assert.Equal(oneTimePassword.Version, entity.Version); Assert.Equal(oneTimePassword.CreatedBy.Value, entity.CreatedBy); - Assertions.Equal(oneTimePassword.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(oneTimePassword.CreatedOn, entity.CreatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(oneTimePassword.UpdatedBy.Value, entity.UpdatedBy); - Assertions.Equal(oneTimePassword.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(oneTimePassword.UpdatedOn, entity.UpdatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(oneTimePassword.TenantId?.Value, entity.TenantId); - Assertions.Equal(oneTimePassword.ExpiresOn, entity.ExpiresOn); + Assertions.Equal(oneTimePassword.ExpiresOn, entity.ExpiresOn, TimeSpan.FromSeconds(1)); Assert.Equal(oneTimePassword.MaximumAttempts, entity.MaximumAttempts); Assert.Equal(oneTimePassword.AttemptCount, entity.AttemptCount); diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertRoles.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertRoles.cs similarity index 91% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertRoles.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertRoles.cs index b6ebbe5..158221c 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertRoles.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertRoles.cs @@ -1,7 +1,7 @@ using Logitar.Identity.Domain.Roles; using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class AssertRoles { @@ -16,9 +16,9 @@ public static void AreEqual(RoleAggregate? role, RoleEntity? entity) Assert.Equal(role.Version, entity.Version); Assert.Equal(role.CreatedBy.Value, entity.CreatedBy); - Assertions.Equal(role.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(role.CreatedOn, entity.CreatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(role.UpdatedBy.Value, entity.UpdatedBy); - Assertions.Equal(role.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(role.UpdatedOn, entity.UpdatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(role.TenantId?.Value, entity.TenantId); Assert.Equal(role.UniqueName.Value, entity.UniqueName); diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertSessions.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertSessions.cs similarity index 93% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertSessions.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertSessions.cs index 84d55b7..fd76735 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertSessions.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertSessions.cs @@ -1,7 +1,7 @@ using Logitar.Identity.Domain.Sessions; using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class AssertSessions { @@ -16,9 +16,9 @@ public static void AreEqual(SessionAggregate? session, SessionEntity? entity) Assert.Equal(session.Version, entity.Version); Assert.Equal(session.CreatedBy.Value, entity.CreatedBy); - Assertions.Equal(session.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(session.CreatedOn, entity.CreatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(session.UpdatedBy.Value, entity.UpdatedBy); - Assertions.Equal(session.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(session.UpdatedOn, entity.UpdatedOn, TimeSpan.FromSeconds(1)); Assert.NotNull(entity.User); Assert.Equal(session.UserId.Value, entity.User.AggregateId); diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertUsers.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertUsers.cs similarity index 95% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertUsers.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertUsers.cs index 4f9ffb3..8292509 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/AssertUsers.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/AssertUsers.cs @@ -1,9 +1,8 @@ using Logitar.Identity.Domain.Roles; using Logitar.Identity.Domain.Users; -using Logitar.Identity.EntityFrameworkCore.Relational; using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class AssertUsers { @@ -18,9 +17,9 @@ public static void AreEqual(UserAggregate? user, UserEntity? entity) Assert.Equal(user.Version, entity.Version); Assert.Equal(user.CreatedBy.Value, entity.CreatedBy); - Assertions.Equal(user.CreatedOn, entity.CreatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(user.CreatedOn, entity.CreatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(user.UpdatedBy.Value, entity.UpdatedBy); - Assertions.Equal(user.UpdatedOn, entity.UpdatedOn, TimeSpan.FromMinutes(1)); + Assertions.Equal(user.UpdatedOn, entity.UpdatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(user.TenantId?.Value, entity.TenantId); @@ -114,7 +113,7 @@ public static void AreEqual(UserAggregate? user, UserEntity? entity) Assert.Equal(user.FullName, entity.FullName); Assert.Equal(user.Nickname?.Value, entity.Nickname); - Assertions.Equal(user.Birthdate, entity.Birthdate, TimeSpan.FromMinutes(1)); + Assertions.Equal(user.Birthdate, entity.Birthdate, TimeSpan.FromSeconds(1)); Assert.Equal(user.Gender?.Value, entity.Gender); Assert.Equal(user.Locale?.Code, entity.Locale); Assert.Equal(user.TimeZone?.Id, entity.TimeZone); @@ -123,7 +122,7 @@ public static void AreEqual(UserAggregate? user, UserEntity? entity) Assert.Equal(user.Profile?.Value, entity.Profile); Assert.Equal(user.Website?.Value, entity.Website); - Assert.Equal(user.AuthenticatedOn, entity.AuthenticatedOn); + Assertions.Equal(user.AuthenticatedOn, entity.AuthenticatedOn, TimeSpan.FromSeconds(1)); Assert.Equal(user.CustomAttributes, entity.CustomAttributes); diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Assertions.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Assertions.cs similarity index 70% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Assertions.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Assertions.cs index c7a587b..9d65d38 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Assertions.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Assertions.cs @@ -1,4 +1,4 @@ -namespace Logitar.Identity.EntityFrameworkCore.SqlServer; +namespace Logitar.Identity.EntityFrameworkCore.Relational; internal static class Assertions { @@ -22,16 +22,16 @@ public static void Equal(DateTime expected, DateTime actual, TimeSpan? precision } if (actual.Kind == DateTimeKind.Unspecified) { - actual = DateTime.SpecifyKind(expected, DateTimeKind.Utc); + actual = DateTime.SpecifyKind(actual, DateTimeKind.Utc); } if (precision.HasValue) { - Assert.Equal(expected, actual, precision.Value); + Assert.Equal(expected.ToUniversalTime(), actual.ToUniversalTime(), precision.Value); } else { - Assert.Equal(expected, actual); + Assert.Equal(expected.ToUniversalTime(), actual.ToUniversalTime()); } } } diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Logitar.Identity.EFCore.Relational.IntegrationTests.csproj b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Logitar.Identity.EFCore.Relational.IntegrationTests.csproj new file mode 100644 index 0000000..ac98a11 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Logitar.Identity.EFCore.Relational.IntegrationTests.csproj @@ -0,0 +1,44 @@ + + + + net8.0 + enable + enable + + false + true + Logitar.Identity.EntityFrameworkCore.Relational + + + + True + + + + True + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/ApiKeyRepositoryTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/ApiKeyRepositoryTestsBase.cs new file mode 100644 index 0000000..899d5b8 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/ApiKeyRepositoryTestsBase.cs @@ -0,0 +1,233 @@ +using Logitar.Data; +using Logitar.EventSourcing; +using Logitar.EventSourcing.EntityFrameworkCore.Relational; +using Logitar.Identity.Contracts.Settings; +using Logitar.Identity.Domain.ApiKeys; +using Logitar.Identity.Domain.Passwords; +using Logitar.Identity.Domain.Roles; +using Logitar.Identity.Domain.Settings; +using Logitar.Identity.Domain.Shared; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; + +public abstract class ApiKeyRepositoryTestsBase : RepositoryTests, IAsyncLifetime +{ + private readonly IApiKeyRepository _apiKeyRepository; + private readonly IPasswordManager _passwordManager; + private readonly IRoleRepository _roleRepository; + private readonly IRoleSettings _roleSettings; + + private readonly Password _secret; + private readonly string _secretString; + + private readonly ApiKeyAggregate _apiKey; + private readonly RoleAggregate _role; + + public ApiKeyRepositoryTestsBase() : base() + { + _apiKeyRepository = ServiceProvider.GetRequiredService(); + _passwordManager = ServiceProvider.GetRequiredService(); + _roleRepository = ServiceProvider.GetRequiredService(); + _roleSettings = ServiceProvider.GetRequiredService().Resolve(); + + ApiKeyId apiKeyId = ApiKeyId.NewId(); + ActorId actorId = new(apiKeyId.Value); + TenantId tenantId = new("tests"); + + _role = new(new UniqueNameUnit(_roleSettings.UniqueName, "clerk"), tenantId, actorId); + + DisplayNameUnit displayName = new("Default"); + _secret = _passwordManager.GenerateBase64(32, out _secretString); + _apiKey = new(displayName, _secret, tenantId, actorId, apiKeyId) + { + Description = new DescriptionUnit("This is the default API key.") + }; + _apiKey.SetExpiration(DateTime.Now.AddYears(1)); + _apiKey.SetCustomAttribute("OwnerId", Guid.NewGuid().ToString()); + _apiKey.Update(actorId); + + _apiKey.AddRole(_role, actorId); + + _apiKey.Authenticate(_secretString, actorId); + } + + public async Task InitializeAsync() + { + await EventContext.Database.MigrateAsync(); + await IdentityContext.Database.MigrateAsync(); + + TableId[] tables = + [ + IdentityDb.ApiKeys.Table, + IdentityDb.Roles.Table, + IdentityDb.CustomAttributes.Table, + IdentityDb.Actors.Table, + EventDb.Events.Table + ]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + + await _roleRepository.SaveAsync(_role); + await _apiKeyRepository.SaveAsync(_apiKey); + } + + [Fact(DisplayName = "LoadAsync: it should load all the API keys.")] + public async Task LoadAsync_it_should_load_all_the_Api_keys() + { + ApiKeyAggregate deleted = new(_apiKey.DisplayName, _secret, tenantId: null); + deleted.Delete(); + await _apiKeyRepository.SaveAsync(deleted); + + IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(includeDeleted: true); + Assert.Equal(2, apiKeys.Count()); + Assert.Contains(apiKeys, _apiKey.Equals); + Assert.Contains(apiKeys, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the API key by identifier.")] + public async Task LoadAsync_it_should_load_the_Api_key_by_identifier() + { + Assert.Null(await _apiKeyRepository.LoadAsync(ApiKeyId.NewId())); + + _apiKey.Delete(); + long version = _apiKey.Version; + + DateTime? authenticatedOn = _apiKey.AuthenticatedOn; + _apiKey.Authenticate(_secretString); + await _apiKeyRepository.SaveAsync(_apiKey); + + Assert.Null(await _apiKeyRepository.LoadAsync(_apiKey.Id, version)); + + ApiKeyAggregate? apiKey = await _apiKeyRepository.LoadAsync(_apiKey.Id, version, includeDeleted: true); + Assert.NotNull(apiKey); + Assert.Equal(authenticatedOn, apiKey.AuthenticatedOn); + Assert.Equal(_apiKey, apiKey); + } + + [Fact(DisplayName = "LoadAsync: it should load the API key by role.")] + public async Task LoadAsync_it_should_load_the_Api_key_by_role() + { + RoleAggregate admin = new(new UniqueNameUnit(_roleSettings.UniqueName, "admin"), _apiKey.TenantId); + await _roleRepository.SaveAsync(admin); + + Assert.Empty(await _apiKeyRepository.LoadAsync(admin)); + + IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(_role); + Assert.Equal(_apiKey, apiKeys.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the API keys by tenant identifier.")] + public async Task LoadAsync_it_should_load_the_apiKeys_by_tenant_identifier() + { + ApiKeyAggregate apiKey = new(new DisplayNameUnit("Other API key"), _secret, tenantId: null); + ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret, _apiKey.TenantId); + deleted.Delete(); + await _apiKeyRepository.SaveAsync([apiKey, deleted]); + + IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(_apiKey.TenantId); + Assert.Equal(_apiKey, apiKeys.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the API keys by identifiers.")] + public async Task LoadAsync_it_should_load_the_Api_keys_by_identifiers() + { + ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret, tenantId: null); + deleted.Delete(); + await _apiKeyRepository.SaveAsync(deleted); + + IEnumerable apiKeys = await _apiKeyRepository.LoadAsync([_apiKey.Id, deleted.Id, ApiKeyId.NewId()], includeDeleted: true); + Assert.Equal(2, apiKeys.Count()); + Assert.Contains(apiKeys, _apiKey.Equals); + Assert.Contains(apiKeys, deleted.Equals); + } + + [Fact(DisplayName = "SaveAsync: it should save the deleted API key.")] + public async Task SaveAsync_it_should_save_the_deleted_Api_key() + { + _apiKey.SetCustomAttribute("Confidentiality", "Private"); + _apiKey.SetCustomAttribute("SubSystem", "IntegrationTests"); + _apiKey.Update(); + await _apiKeyRepository.SaveAsync(_apiKey); + + ApiKeyEntity? entity = await IdentityContext.ApiKeys.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _apiKey.Id.Value); + Assert.NotNull(entity); + + CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) + .ToArrayAsync(); + Assert.Equal(_apiKey.CustomAttributes.Count, customAttributes.Length); + foreach (KeyValuePair customAttribute in _apiKey.CustomAttributes) + { + Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); + } + + _apiKey.Delete(); + await _apiKeyRepository.SaveAsync(_apiKey); + + customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) + .ToArrayAsync(); + Assert.Empty(customAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified API key.")] + public async Task SaveAsync_it_should_save_the_specified_Api_key() + { + ApiKeyEntity? entity = await IdentityContext.ApiKeys.AsNoTracking() + .Include(x => x.Roles) + .SingleOrDefaultAsync(x => x.AggregateId == _apiKey.Id.Value); + Assert.NotNull(entity); + AssertApiKeys.AreEqual(_apiKey, entity); + + ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() + .SingleOrDefaultAsync(x => x.Id == _apiKey.Id.Value); + AssertApiKeys.AreEquivalent(entity, actor); + + Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) + .ToDictionaryAsync(x => x.Key, x => x.Value); + Assert.Equal(_apiKey.CustomAttributes, customAttributes); + + ApiKeyAggregate? apiKey = await _apiKeyRepository.LoadAsync(_apiKey.Id); + Assert.NotNull(apiKey); + Assert.Equal(_apiKey.Description, apiKey.Description); + Assert.Equal(_apiKey.ExpiresOn, apiKey.ExpiresOn); + Assert.Equal(_apiKey.CustomAttributes, apiKey.CustomAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified API keys.")] + public async Task SaveAsync_it_should_save_the_specified_Api_keys() + { + ApiKeyAggregate authenticated = new(new DisplayNameUnit("authenticated"), _secret); + ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret); + await _apiKeyRepository.SaveAsync([authenticated, deleted]); + + Dictionary entities = await IdentityContext.ApiKeys.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(authenticated.Id.Value)); + Assert.True(entities.ContainsKey(deleted.Id.Value)); + + authenticated.Authenticate(_secretString); + deleted.Delete(); + await _apiKeyRepository.SaveAsync([authenticated, deleted]); + + entities = await IdentityContext.ApiKeys.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(authenticated.Id.Value)); + Assert.False(entities.ContainsKey(deleted.Id.Value)); + + AssertApiKeys.AreEqual(authenticated, entities[authenticated.Id.Value]); + + ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() + .SingleOrDefaultAsync(x => x.Id == deleted.Id.Value); + Assert.NotNull(actor); + Assert.True(actor.IsDeleted); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/OneTimePasswordRepositoryTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/OneTimePasswordRepositoryTestsBase.cs new file mode 100644 index 0000000..120d86e --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/OneTimePasswordRepositoryTestsBase.cs @@ -0,0 +1,183 @@ +using Logitar.Data; +using Logitar.EventSourcing; +using Logitar.EventSourcing.EntityFrameworkCore.Relational; +using Logitar.Identity.Domain.Passwords; +using Logitar.Identity.Domain.Shared; +using Logitar.Identity.Domain.Users; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; + +public abstract class OneTimePasswordRepositoryTestsBase : RepositoryTests, IAsyncLifetime +{ + private const string PasswordString = "284199"; + + private readonly IOneTimePasswordRepository _oneTimePasswordRepository; + private readonly IPasswordManager _passwordManager; + + private readonly Password _password; + private readonly OneTimePasswordAggregate _oneTimePassword; + + public OneTimePasswordRepositoryTestsBase() : base() + { + _oneTimePasswordRepository = ServiceProvider.GetRequiredService(); + _passwordManager = ServiceProvider.GetRequiredService(); + + TenantId tenantId = new("tests"); + DateTime expiresOn = DateTime.Now.AddHours(1); + int maximumAttempts = 5; + ActorId actorId = ActorId.NewId(); + OneTimePasswordId id = OneTimePasswordId.NewId(); + + _password = _passwordManager.Create(PasswordString); + _oneTimePassword = new(_password, tenantId, expiresOn, maximumAttempts, actorId, id); + _oneTimePassword.SetCustomAttribute("Purpose", "MultiFactorAuthentication"); + _oneTimePassword.SetCustomAttribute("UserId", Guid.NewGuid().ToString()); + _oneTimePassword.Update(actorId); + } + + public async Task InitializeAsync() + { + await EventContext.Database.MigrateAsync(); + await IdentityContext.Database.MigrateAsync(); + + TableId[] tables = [IdentityDb.OneTimePasswords.Table, IdentityDb.CustomAttributes.Table, EventDb.Events.Table]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + + await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); + } + + [Fact(DisplayName = "LoadAsync: it should load all the One-Time Passwords.")] + public async Task LoadAsync_it_should_load_all_the_One_Time_Passwords() + { + OneTimePasswordAggregate deleted = new(_password, tenantId: null); + deleted.Delete(); + await _oneTimePasswordRepository.SaveAsync(deleted); + + IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync(includeDeleted: true); + Assert.Equal(2, oneTimePasswords.Count()); + Assert.Contains(oneTimePasswords, _oneTimePassword.Equals); + Assert.Contains(oneTimePasswords, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the One-Time Password by identifier.")] + public async Task LoadAsync_it_should_load_the_One_Time_Password_by_identifier() + { + Assert.Null(await _oneTimePasswordRepository.LoadAsync(OneTimePasswordId.NewId())); + + _oneTimePassword.Delete(); + long version = _oneTimePassword.Version; + + _oneTimePassword.Validate(PasswordString); + await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); + + Assert.Null(await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id, version)); + + OneTimePasswordAggregate? oneTimePassword = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id, version, includeDeleted: true); + Assert.NotNull(oneTimePassword); + Assert.Equal(_oneTimePassword, oneTimePassword); + } + + [Fact(DisplayName = "LoadAsync: it should load the One-Time Passwords by tenant identifier.")] + public async Task LoadAsync_it_should_load_the_One_Time_Passwords_by_tenant_identifier() + { + OneTimePasswordAggregate oneTimePassword = new(_password, tenantId: null); + OneTimePasswordAggregate deleted = new(_password, _oneTimePassword.TenantId); + deleted.Delete(); + await _oneTimePasswordRepository.SaveAsync([oneTimePassword, deleted]); + + IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.TenantId); + Assert.Equal(_oneTimePassword, oneTimePasswords.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the One-Time Passwords by identifiers.")] + public async Task LoadAsync_it_should_load_the_One_Time_Passwords_by_identifiers() + { + OneTimePasswordAggregate deleted = new(_password, tenantId: null); + deleted.Delete(); + await _oneTimePasswordRepository.SaveAsync(deleted); + + IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync([_oneTimePassword.Id, deleted.Id, OneTimePasswordId.NewId()], includeDeleted: true); + Assert.Equal(2, oneTimePasswords.Count()); + Assert.Contains(oneTimePasswords, _oneTimePassword.Equals); + Assert.Contains(oneTimePasswords, deleted.Equals); + } + + [Fact(DisplayName = "SaveAsync: it should save the deleted One-Time Password.")] + public async Task SaveAsync_it_should_save_the_deleted_One_Time_Password() + { + _oneTimePassword.SetCustomAttribute("Purpose", "reset_password"); + _oneTimePassword.SetCustomAttribute("UserId", UserId.NewId().Value); + _oneTimePassword.Update(); + await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); + + OneTimePasswordEntity? entity = await IdentityContext.OneTimePasswords.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _oneTimePassword.Id.Value); + Assert.NotNull(entity); + + CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) + .ToArrayAsync(); + Assert.Equal(_oneTimePassword.CustomAttributes.Count, customAttributes.Length); + foreach (KeyValuePair customAttribute in _oneTimePassword.CustomAttributes) + { + Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); + } + + _oneTimePassword.Delete(); + await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); + + customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) + .ToArrayAsync(); + Assert.Empty(customAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified One-Time Password.")] + public async Task SaveAsync_it_should_save_the_specified_One_Time_Password() + { + OneTimePasswordEntity? entity = await IdentityContext.OneTimePasswords.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _oneTimePassword.Id.Value); + Assert.NotNull(entity); + AssertOneTimePasswords.AreEqual(_oneTimePassword, entity); + + Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) + .ToDictionaryAsync(x => x.Key, x => x.Value); + Assert.Equal(_oneTimePassword.CustomAttributes, customAttributes); + + OneTimePasswordAggregate? oneTimePassword = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id); + Assert.NotNull(oneTimePassword); + Assert.Equal(_oneTimePassword.CustomAttributes, oneTimePassword.CustomAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified One-Time Passwords.")] + public async Task SaveAsync_it_should_save_the_specified_One_Time_Passwords() + { + OneTimePasswordAggregate succeeded = new(_password); + OneTimePasswordAggregate deleted = new(_password); + await _oneTimePasswordRepository.SaveAsync([succeeded, deleted]); + + Dictionary entities = await IdentityContext.OneTimePasswords.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(succeeded.Id.Value)); + Assert.True(entities.ContainsKey(deleted.Id.Value)); + + succeeded.Validate(PasswordString); + deleted.Delete(); + await _oneTimePasswordRepository.SaveAsync([succeeded, deleted]); + + entities = await IdentityContext.OneTimePasswords.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(succeeded.Id.Value)); + Assert.False(entities.ContainsKey(deleted.Id.Value)); + + AssertOneTimePasswords.AreEqual(succeeded, entities[succeeded.Id.Value]); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RepositoryTests.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RepositoryTests.cs similarity index 62% rename from tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RepositoryTests.cs rename to tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RepositoryTests.cs index 444823f..a5c19d5 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RepositoryTests.cs @@ -1,10 +1,10 @@ using Bogus; +using Logitar.Data; using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; public abstract class RepositoryTests { @@ -20,15 +20,16 @@ protected RepositoryTests() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) .Build(); - string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty) - .Replace("{Database}", GetType().Name); - - ServiceProvider = new ServiceCollection() - .AddSingleton(configuration) - .AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString) - .BuildServiceProvider(); + ServiceCollection services = new(); + services.AddSingleton(configuration); + ConfigureServices(services, configuration); + ServiceProvider = services.BuildServiceProvider(); EventContext = ServiceProvider.GetRequiredService(); IdentityContext = ServiceProvider.GetRequiredService(); } + + protected abstract void ConfigureServices(IServiceCollection services, IConfiguration configuration); + + protected abstract IDeleteBuilder CreateDeleteBuilder(TableId table); } diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RoleRepositoryTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RoleRepositoryTestsBase.cs new file mode 100644 index 0000000..72ca43a --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RoleRepositoryTestsBase.cs @@ -0,0 +1,245 @@ +using Logitar.Data; +using Logitar.EventSourcing; +using Logitar.EventSourcing.EntityFrameworkCore.Relational; +using Logitar.Identity.Contracts.Settings; +using Logitar.Identity.Domain.ApiKeys; +using Logitar.Identity.Domain.Passwords; +using Logitar.Identity.Domain.Roles; +using Logitar.Identity.Domain.Settings; +using Logitar.Identity.Domain.Shared; +using Logitar.Identity.Domain.Users; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; + +public abstract class RoleRepositoryTestsBase : RepositoryTests, IAsyncLifetime +{ + private readonly IApiKeyRepository _apiKeyRepository; + private readonly IPasswordManager _passwordManager; + private readonly IRoleRepository _roleRepository; + private readonly IRoleSettings _roleSettings; + private readonly IUserRepository _userRepository; + private readonly IUserSettings _userSettings; + + private readonly RoleAggregate _role; + + public RoleRepositoryTestsBase() : base() + { + _apiKeyRepository = ServiceProvider.GetRequiredService(); + _passwordManager = ServiceProvider.GetRequiredService(); + _roleRepository = ServiceProvider.GetRequiredService(); + _roleSettings = ServiceProvider.GetRequiredService().Resolve(); + _userRepository = ServiceProvider.GetRequiredService(); + _userSettings = ServiceProvider.GetRequiredService().Resolve(); + + RoleId roleId = RoleId.NewId(); + ActorId actorId = new(roleId.Value); + TenantId tenantId = new("tests"); + + UniqueNameUnit uniqueName = new(_roleSettings.UniqueName, "send_messages"); + _role = new(uniqueName, tenantId, actorId, roleId) + { + DisplayName = new DisplayNameUnit("Send Messages"), + Description = new DescriptionUnit("This role allows to send messages.") + }; + _role.SetCustomAttribute("manage_messages", bool.TrueString); + _role.Update(actorId); + } + + public async Task InitializeAsync() + { + await EventContext.Database.MigrateAsync(); + await IdentityContext.Database.MigrateAsync(); + + TableId[] tables = + [ + IdentityDb.Roles.Table, + IdentityDb.CustomAttributes.Table, + EventDb.Events.Table + ]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + + await _roleRepository.SaveAsync(_role); + await _roleRepository.SaveAsync(_role); + } + + [Fact(DisplayName = "LoadAsync: it should load all the roles.")] + public async Task LoadAsync_it_should_load_all_the_roles() + { + RoleAggregate deleted = new(_role.UniqueName, tenantId: null); + deleted.Delete(); + await _roleRepository.SaveAsync(deleted); + + IEnumerable roles = await _roleRepository.LoadAsync(includeDeleted: true); + Assert.Equal(2, roles.Count()); + Assert.Contains(roles, _role.Equals); + Assert.Contains(roles, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the role by identifier.")] + public async Task LoadAsync_it_should_load_the_role_by_identifier() + { + Assert.Null(await _roleRepository.LoadAsync(RoleId.NewId())); + + _role.Delete(); + long version = _role.Version; + + UniqueNameUnit oldUniqueName = _role.UniqueName; + _role.SetUniqueName(new UniqueNameUnit(_roleSettings.UniqueName, "guest")); + await _roleRepository.SaveAsync(_role); + + Assert.Null(await _roleRepository.LoadAsync(_role.Id, version)); + + RoleAggregate? role = await _roleRepository.LoadAsync(_role.Id, version, includeDeleted: true); + Assert.NotNull(role); + Assert.Equal(oldUniqueName, role.UniqueName); + Assert.Equal(_role, role); + } + + [Fact(DisplayName = "LoadAsync: it should load the roles by tenant identifier.")] + public async Task LoadAsync_it_should_load_the_roles_by_tenant_identifier() + { + RoleAggregate role = new(_role.UniqueName, tenantId: null); + RoleAggregate deleted = new(new UniqueNameUnit(_roleSettings.UniqueName, "deleted"), _role.TenantId); + deleted.Delete(); + await _roleRepository.SaveAsync([role, deleted]); + + IEnumerable roles = await _roleRepository.LoadAsync(_role.TenantId); + Assert.Equal(_role, roles.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the role by unique name.")] + public async Task LoadAsync_it_should_load_the_role_by_unique_name() + { + Assert.Null(await _roleRepository.LoadAsync(tenantId: null, _role.UniqueName)); + + UniqueNameUnit uniqueName = new(_roleSettings.UniqueName, $"{_role.UniqueName.Value}2"); + Assert.Null(await _roleRepository.LoadAsync(_role.TenantId, uniqueName)); + + RoleAggregate? role = await _roleRepository.LoadAsync(_role.TenantId, _role.UniqueName); + Assert.NotNull(role); + Assert.Equal(_role, role); + } + + [Fact(DisplayName = "LoadAsync: it should load the roles by identifiers.")] + public async Task LoadAsync_it_should_load_the_roles_by_identifiers() + { + RoleAggregate deleted = new(_role.UniqueName, tenantId: null); + deleted.Delete(); + await _roleRepository.SaveAsync(deleted); + + IEnumerable roles = await _roleRepository.LoadAsync([_role.Id, deleted.Id, RoleId.NewId()], includeDeleted: true); + Assert.Equal(2, roles.Count()); + Assert.Contains(roles, _role.Equals); + Assert.Contains(roles, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the roles by API key.")] + public async Task LoadAsync_it_should_load_the_roles_by_Api_key() + { + RoleAggregate manageUsers = new(new UniqueNameUnit(_roleSettings.UniqueName, "manage_users")); + await _roleRepository.SaveAsync(manageUsers); + + Password secret = _passwordManager.GenerateBase64(32, out _); + ApiKeyAggregate apiKey = new(new DisplayNameUnit("Default"), secret); + apiKey.AddRole(manageUsers); + await _apiKeyRepository.SaveAsync(apiKey); + + RoleAggregate role = Assert.Single(await _roleRepository.LoadAsync(apiKey)); + Assert.Equal(manageUsers, role); + } + + [Fact(DisplayName = "LoadAsync: it should load the roles by user.")] + public async Task LoadAsync_it_should_load_the_roles_by_user() + { + RoleAggregate manageUsers = new(new UniqueNameUnit(_roleSettings.UniqueName, "manage_users")); + await _roleRepository.SaveAsync(manageUsers); + + UserAggregate user = new(new UniqueNameUnit(_userSettings.UniqueName, Faker.Internet.UserName())); + user.AddRole(manageUsers); + await _userRepository.SaveAsync(user); + + RoleAggregate role = Assert.Single(await _roleRepository.LoadAsync(user)); + Assert.Equal(manageUsers, role); + } + + [Fact(DisplayName = "SaveAsync: it should save the deleted role.")] + public async Task SaveAsync_it_should_save_the_deleted_role() + { + _role.SetCustomAttribute("read_messages", bool.TrueString); + _role.SetCustomAttribute("edit_messages", bool.FalseString); + _role.Update(); + await _roleRepository.SaveAsync(_role); + + RoleEntity? entity = await IdentityContext.Roles.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _role.Id.Value); + Assert.NotNull(entity); + + CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) + .ToArrayAsync(); + Assert.Equal(_role.CustomAttributes.Count, customAttributes.Length); + foreach (KeyValuePair customAttribute in _role.CustomAttributes) + { + Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); + } + + _role.Delete(); + await _roleRepository.SaveAsync(_role); + + customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) + .ToArrayAsync(); + Assert.Empty(customAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified role.")] + public async Task SaveAsync_it_should_save_the_specified_role() + { + RoleEntity? entity = await IdentityContext.Roles.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _role.Id.Value); + Assert.NotNull(entity); + AssertRoles.AreEqual(_role, entity); + + Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) + .ToDictionaryAsync(x => x.Key, x => x.Value); + Assert.Equal(_role.CustomAttributes, customAttributes); + + RoleAggregate? role = await _roleRepository.LoadAsync(_role.Id); + Assert.NotNull(role); + Assert.Equal(_role.DisplayName, role.DisplayName); + Assert.Equal(_role.Description, role.Description); + Assert.Equal(_role.CustomAttributes, role.CustomAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified roles.")] + public async Task SaveAsync_it_should_save_the_specified_roles() + { + RoleAggregate guest = new(new UniqueNameUnit(_roleSettings.UniqueName, "gwest")); + RoleAggregate deleted = new(new UniqueNameUnit(_roleSettings.UniqueName, "deleted")); + await _roleRepository.SaveAsync([guest, deleted]); + + Dictionary entities = await IdentityContext.Roles.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(guest.Id.Value)); + Assert.True(entities.ContainsKey(deleted.Id.Value)); + + guest.SetUniqueName(new UniqueNameUnit(_roleSettings.UniqueName, "guest")); + deleted.Delete(); + await _roleRepository.SaveAsync([guest, deleted]); + + entities = await IdentityContext.Roles.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(guest.Id.Value)); + Assert.False(entities.ContainsKey(deleted.Id.Value)); + + AssertRoles.AreEqual(guest, entities[guest.Id.Value]); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/SessionRepositoryTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/SessionRepositoryTestsBase.cs new file mode 100644 index 0000000..1c8df7d --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/SessionRepositoryTestsBase.cs @@ -0,0 +1,225 @@ +using Logitar.Data; +using Logitar.EventSourcing; +using Logitar.Identity.Contracts.Settings; +using Logitar.Identity.Domain.Sessions; +using Logitar.Identity.Domain.Settings; +using Logitar.Identity.Domain.Shared; +using Logitar.Identity.Domain.Users; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; + +public abstract class SessionRepositoryTestsBase : RepositoryTests, IAsyncLifetime +{ + private readonly ISessionRepository _sessionRepository; + private readonly IUserRepository _userRepository; + private readonly IUserSettings _userSettings; + + private readonly UserAggregate _user; + private readonly SessionAggregate _session; + + public SessionRepositoryTestsBase() : base() + { + _sessionRepository = ServiceProvider.GetRequiredService(); + _userRepository = ServiceProvider.GetRequiredService(); + _userSettings = ServiceProvider.GetRequiredService().Resolve(); + + UserId userId = UserId.NewId(); + ActorId actorId = new(userId.Value); + + TenantId tenantId = new("tests"); + UniqueNameUnit uniqueName = new(_userSettings.UniqueName, Faker.Person.UserName); + _user = new(uniqueName, tenantId, actorId, userId); + + _session = new(_user); + + _session.SetCustomAttribute("IpAddress", Faker.Internet.Ip()); + _session.Update(actorId); + } + + public async Task InitializeAsync() + { + await EventContext.Database.MigrateAsync(); + await IdentityContext.Database.MigrateAsync(); + + TableId[] tables = [IdentityDb.Sessions.Table, IdentityDb.Users.Table, IdentityDb.CustomAttributes.Table, IdentityDb.Actors.Table, EventDb.Events.Table]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + + await _userRepository.SaveAsync(_user); + await _sessionRepository.SaveAsync(_session); + } + + [Fact(DisplayName = "LoadAsync: it should load all the sessions.")] + public async Task LoadAsync_it_should_load_all_the_sessions() + { + SessionAggregate deleted = new(_user); + deleted.Delete(); + await _sessionRepository.SaveAsync(deleted); + + IEnumerable sessions = await _sessionRepository.LoadAsync(includeDeleted: true); + Assert.Equal(2, sessions.Count()); + Assert.Contains(sessions, _session.Equals); + Assert.Contains(sessions, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the active sessions by user.")] + public async Task LoadAsync_it_should_load_the_active_sessions_by_user() + { + UserAggregate user = new(_user.UniqueName, tenantId: null); + await _userRepository.SaveAsync(user); + + SessionAggregate session = new(user); + SessionAggregate deleted = new(_user); + deleted.Delete(); + SessionAggregate signedOut = new(_user); + signedOut.SignOut(); + await _sessionRepository.SaveAsync([session, deleted, signedOut]); + IEnumerable sessions = await _sessionRepository.LoadActiveAsync(_user); + Assert.Equal(_session, sessions.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the session by identifier.")] + public async Task LoadAsync_it_should_load_the_session_by_identifier() + { + Assert.Null(await _sessionRepository.LoadAsync(SessionId.NewId())); + + _session.Delete(); + long version = _session.Version; + + _session.SignOut(); + await _sessionRepository.SaveAsync(_session); + + Assert.Null(await _sessionRepository.LoadAsync(_session.Id, version)); + + SessionAggregate? session = await _sessionRepository.LoadAsync(_session.Id, version, includeDeleted: true); + Assert.NotNull(session); + Assert.True(session.IsActive); + Assert.Equal(_session, session); + } + + [Fact(DisplayName = "LoadAsync: it should load the sessions by tenant identifier.")] + public async Task LoadAsync_it_should_load_the_sessions_by_tenant_identifier() + { + UserAggregate user = new(_user.UniqueName, tenantId: null); + await _userRepository.SaveAsync(user); + + SessionAggregate session = new(user); + SessionAggregate deleted = new(_user); + deleted.Delete(); + await _sessionRepository.SaveAsync([session, deleted]); + + IEnumerable sessions = await _sessionRepository.LoadAsync(_user.TenantId); + Assert.Equal(_session, sessions.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the sessions by user.")] + public async Task LoadAsync_it_should_load_the_sessions_by_user() + { + UserAggregate user = new(_user.UniqueName, tenantId: null); + await _userRepository.SaveAsync(user); + + SessionAggregate session = new(user); + SessionAggregate deleted = new(_user); + deleted.Delete(); + SessionAggregate signedOut = new(_user); + signedOut.SignOut(); + await _sessionRepository.SaveAsync([session, deleted, signedOut]); + + IEnumerable sessions = await _sessionRepository.LoadAsync(_user); + Assert.Equal(2, sessions.Count()); + Assert.Contains(sessions, _session.Equals); + Assert.Contains(sessions, signedOut.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the sessions by identifiers.")] + public async Task LoadAsync_it_should_load_the_sessions_by_identifiers() + { + SessionAggregate deleted = new(_user); + deleted.Delete(); + await _sessionRepository.SaveAsync(deleted); + + IEnumerable sessions = await _sessionRepository.LoadAsync([_session.Id, deleted.Id, SessionId.NewId()], includeDeleted: true); + Assert.Equal(2, sessions.Count()); + Assert.Contains(sessions, _session.Equals); + Assert.Contains(sessions, deleted.Equals); + } + + [Fact(DisplayName = "SaveAsync: it should save the deleted session.")] + public async Task SaveAsync_it_should_save_the_deleted_session() + { + _session.SetCustomAttribute("AdditionalInformation", $@"{{""User-Agent"":""{Faker.Internet.UserAgent()}""}}"); + _session.SetCustomAttribute("IpAddress", Faker.Internet.Ip()); + _session.Update(); + await _sessionRepository.SaveAsync(_session); + + SessionEntity? entity = await IdentityContext.Sessions.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _session.Id.Value); + Assert.NotNull(entity); + + CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) + .ToArrayAsync(); + Assert.Equal(_session.CustomAttributes.Count, customAttributes.Length); + foreach (KeyValuePair customAttribute in _session.CustomAttributes) + { + Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); + } + + _session.Delete(); + await _sessionRepository.SaveAsync(_session); + + customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) + .ToArrayAsync(); + Assert.Empty(customAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified session.")] + public async Task SaveAsync_it_should_save_the_specified_session() + { + SessionEntity? entity = await IdentityContext.Sessions.AsNoTracking() + .Include(x => x.User) + .SingleOrDefaultAsync(x => x.AggregateId == _session.Id.Value); + Assert.NotNull(entity); + AssertSessions.AreEqual(_session, entity); + + Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) + .ToDictionaryAsync(x => x.Key, x => x.Value); + Assert.Equal(_session.CustomAttributes, customAttributes); + + SessionAggregate? session = await _sessionRepository.LoadAsync(_session.Id); + Assert.NotNull(session); + Assert.Equal(_session.CustomAttributes, session.CustomAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified sessions.")] + public async Task SaveAsync_it_should_save_the_specified_sessions() + { + SessionAggregate signedOut = new(_user); + SessionAggregate deleted = new(_user); + await _sessionRepository.SaveAsync([signedOut, deleted]); + + Dictionary entities = await IdentityContext.Sessions.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(signedOut.Id.Value)); + Assert.True(entities.ContainsKey(deleted.Id.Value)); + + signedOut.SignOut(); + deleted.Delete(); + await _sessionRepository.SaveAsync([signedOut, deleted]); + + entities = await IdentityContext.Sessions.AsNoTracking().Include(x => x.User).ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(signedOut.Id.Value)); + Assert.False(entities.ContainsKey(deleted.Id.Value)); + + AssertSessions.AreEqual(signedOut, entities[signedOut.Id.Value]); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/UserRepositoryTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/UserRepositoryTestsBase.cs new file mode 100644 index 0000000..a9afd84 --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/UserRepositoryTestsBase.cs @@ -0,0 +1,319 @@ +using Logitar.Data; +using Logitar.EventSourcing; +using Logitar.EventSourcing.EntityFrameworkCore.Relational; +using Logitar.Identity.Contracts.Settings; +using Logitar.Identity.Domain.Passwords; +using Logitar.Identity.Domain.Roles; +using Logitar.Identity.Domain.Sessions; +using Logitar.Identity.Domain.Settings; +using Logitar.Identity.Domain.Shared; +using Logitar.Identity.Domain.Users; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories; + +public abstract class UserRepositoryTestsBase : RepositoryTests, IAsyncLifetime +{ + private const string EmployeeIdKey = "EmployeeId"; + private const string PasswordString = "P@s$W0rD"; + + private readonly IPasswordManager _passwordManager; + private readonly IRoleRepository _roleRepository; + private readonly IRoleSettings _roleSettings; + private readonly IUserRepository _userRepository; + private readonly IUserSettings _userSettings; + + private readonly RoleAggregate _role; + private readonly UserAggregate _user; + + public UserRepositoryTestsBase() : base() + { + _passwordManager = ServiceProvider.GetRequiredService(); + _roleRepository = ServiceProvider.GetRequiredService(); + _roleSettings = ServiceProvider.GetRequiredService().Resolve(); + _userRepository = ServiceProvider.GetRequiredService(); + _userSettings = ServiceProvider.GetRequiredService().Resolve(); + + UserId userId = UserId.NewId(); + ActorId actorId = new(userId.Value); + TenantId tenantId = new("tests"); + + _role = new(new UniqueNameUnit(_roleSettings.UniqueName, "clerk"), tenantId, actorId); + + UniqueNameUnit uniqueName = new(_userSettings.UniqueName, Faker.Person.UserName); + _user = new(uniqueName, tenantId, actorId, userId) + { + FirstName = new PersonNameUnit(Faker.Person.FirstName), + MiddleName = new PersonNameUnit(Faker.Name.FirstName()), + LastName = new PersonNameUnit(Faker.Person.LastName), + Nickname = new PersonNameUnit("Toto"), + Birthdate = Faker.Person.DateOfBirth, + Gender = new GenderUnit(Faker.Person.Gender.ToString()), + Locale = new LocaleUnit(Faker.Locale), + TimeZone = new TimeZoneUnit("America/Montreal"), + Picture = new UrlUnit($"https://www.{Faker.Person.Website}/img/profile.jpg"), + Profile = new UrlUnit($"https://www.desjardins.com/profiles/toto"), + Website = new UrlUnit($"https://www.{Faker.Person.Website}") + }; + _user.SetCustomAttribute("Department", "Finances"); + _user.Update(actorId); + + _user.SetAddress(new AddressUnit("150 Saint-Catherine St W", "Montreal", "CA", "QC", "H2X 3Y2"), actorId); + _user.SetEmail(new EmailUnit(Faker.Person.Email, isVerified: true), actorId); + _user.SetPhone(new PhoneUnit("+1 (514) 845-4636", "CA", "123456"), actorId); + + _user.AddRole(_role, actorId); + _user.SetCustomIdentifier(EmployeeIdKey, Guid.NewGuid().ToString(), actorId); + _user.SetPassword(_passwordManager.Create(PasswordString), actorId); + + _user.Authenticate(PasswordString, actorId); + } + + public async Task InitializeAsync() + { + await EventContext.Database.MigrateAsync(); + await IdentityContext.Database.MigrateAsync(); + + TableId[] tables = + [ + IdentityDb.Sessions.Table, + IdentityDb.Users.Table, + IdentityDb.ApiKeys.Table, + IdentityDb.Roles.Table, + IdentityDb.CustomAttributes.Table, + IdentityDb.Actors.Table, + EventDb.Events.Table + ]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + + await _roleRepository.SaveAsync(_role); + await _userRepository.SaveAsync(_user); + } + + [Fact(DisplayName = "LoadAsync: it should load all the users.")] + public async Task LoadAsync_it_should_load_all_the_users() + { + UserAggregate deleted = new(_user.UniqueName, tenantId: null); + deleted.Delete(); + await _userRepository.SaveAsync(deleted); + + IEnumerable users = await _userRepository.LoadAsync(includeDeleted: true); + Assert.Equal(2, users.Count()); + Assert.Contains(users, _user.Equals); + Assert.Contains(users, deleted.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the user by custom identifier.")] + public async Task LoadAsync_it_should_load_the_user_by_custom_identifier() + { + Assert.Null(await _userRepository.LoadAsync(tenantId: null, EmployeeIdKey, _user.CustomIdentifiers[EmployeeIdKey])); + Assert.Null(await _userRepository.LoadAsync(_user.TenantId, "EmployeeNo", _user.CustomIdentifiers[EmployeeIdKey])); + Assert.Null(await _userRepository.LoadAsync(_user.TenantId, EmployeeIdKey, Guid.NewGuid().ToString())); + + UserAggregate? user = await _userRepository.LoadAsync(_user.TenantId, EmployeeIdKey, _user.CustomIdentifiers[EmployeeIdKey]); + Assert.NotNull(user); + Assert.Equal(_user, user); + } + + [Fact(DisplayName = "LoadAsync: it should load the user by identifier.")] + public async Task LoadAsync_it_should_load_the_user_by_identifier() + { + Assert.Null(await _userRepository.LoadAsync(UserId.NewId())); + + _user.Delete(); + long version = _user.Version; + + _user.Disable(); + await _userRepository.SaveAsync(_user); + + Assert.Null(await _userRepository.LoadAsync(_user.Id, version)); + + UserAggregate? user = await _userRepository.LoadAsync(_user.Id, version, includeDeleted: true); + Assert.NotNull(user); + Assert.False(user.IsDisabled); + Assert.Equal(_user, user); + } + + [Fact(DisplayName = "LoadAsync: it should load the user by role.")] + public async Task LoadAsync_it_should_load_the_user_by_role() + { + RoleAggregate admin = new(new UniqueNameUnit(_roleSettings.UniqueName, "admin"), _user.TenantId); + await _roleRepository.SaveAsync(admin); + + Assert.Empty(await _userRepository.LoadAsync(admin)); + + IEnumerable users = await _userRepository.LoadAsync(_role); + Assert.Equal(_user, users.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the user by session.")] + public async Task LoadAsync_it_should_load_the_user_by_session() + { + SessionAggregate session = _user.SignIn(); + + UserAggregate? user = await _userRepository.LoadAsync(session); + Assert.NotNull(user); + Assert.Equal(_user, user); + } + + [Fact(DisplayName = "LoadAsync: it should load the users by tenant identifier.")] + public async Task LoadAsync_it_should_load_the_users_by_tenant_identifier() + { + UserAggregate user = new(_user.UniqueName, tenantId: null); + UserAggregate deleted = new(new UniqueNameUnit(_userSettings.UniqueName, "deleted"), _user.TenantId); + deleted.Delete(); + await _userRepository.SaveAsync([user, deleted]); + + IEnumerable users = await _userRepository.LoadAsync(_user.TenantId); + Assert.Equal(_user, users.Single()); + } + + [Fact(DisplayName = "LoadAsync: it should load the user by unique name.")] + public async Task LoadAsync_it_should_load_the_user_by_unique_name() + { + Assert.Null(await _userRepository.LoadAsync(tenantId: null, _user.UniqueName)); + + UniqueNameUnit uniqueName = new(_userSettings.UniqueName, $"{_user.UniqueName.Value}2"); + Assert.Null(await _userRepository.LoadAsync(_user.TenantId, uniqueName)); + + UserAggregate? user = await _userRepository.LoadAsync(_user.TenantId, _user.UniqueName); + Assert.NotNull(user); + Assert.Equal(_user, user); + } + + [Fact(DisplayName = "LoadAsync: it should load the users by email address.")] + public async Task LoadAsync_it_should_load_the_users_by_email_address() + { + Assert.NotNull(_user.Email); + + Assert.Empty(await _userRepository.LoadAsync(tenantId: null, _user.Email)); + + EmailUnit email = new($"{_user.Email.Address}2"); + Assert.Empty(await _userRepository.LoadAsync(_user.TenantId, email)); + + IEnumerable users = await _userRepository.LoadAsync(_user.TenantId, _user.Email); + Assert.Equal(_user, users.Single()); + + UserAggregate other = new(new UniqueNameUnit(_userSettings.UniqueName, $"{_user.UniqueName.Value}2"), _user.TenantId); + other.SetEmail(_user.Email); + await _userRepository.SaveAsync(other); + + users = await _userRepository.LoadAsync(_user.TenantId, _user.Email); + Assert.Equal(2, users.Count()); + Assert.Contains(users, _user.Equals); + Assert.Contains(users, other.Equals); + } + + [Fact(DisplayName = "LoadAsync: it should load the users by identifiers.")] + public async Task LoadAsync_it_should_load_the_users_by_identifiers() + { + UserAggregate deleted = new(_user.UniqueName, tenantId: null); + deleted.Delete(); + await _userRepository.SaveAsync(deleted); + + IEnumerable users = await _userRepository.LoadAsync([_user.Id, deleted.Id, UserId.NewId()], includeDeleted: true); + Assert.Equal(2, users.Count()); + Assert.Contains(users, _user.Equals); + Assert.Contains(users, deleted.Equals); + } + + [Fact(DisplayName = "SaveAsync: it should save the deleted user.")] + public async Task SaveAsync_it_should_save_the_deleted_user() + { + _user.SetCustomAttribute("HealthInsuranceNumber", Faker.Person.BuildHealthInsuranceNumber()); + _user.SetCustomAttribute("JobTitle", "Sales Manager"); + _user.Update(); + await _userRepository.SaveAsync(_user); + + UserEntity? entity = await IdentityContext.Users.AsNoTracking() + .SingleOrDefaultAsync(x => x.AggregateId == _user.Id.Value); + Assert.NotNull(entity); + + CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) + .ToArrayAsync(); + Assert.Equal(_user.CustomAttributes.Count, customAttributes.Length); + foreach (KeyValuePair customAttribute in _user.CustomAttributes) + { + Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); + } + + _user.Delete(); + await _userRepository.SaveAsync(_user); + + customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) + .ToArrayAsync(); + Assert.Empty(customAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified user.")] + public async Task SaveAsync_it_should_save_the_specified_user() + { + UserEntity? entity = await IdentityContext.Users.AsNoTracking() + .Include(x => x.Identifiers) + .Include(x => x.Roles) + .SingleOrDefaultAsync(x => x.AggregateId == _user.Id.Value); + Assert.NotNull(entity); + AssertUsers.AreEqual(_user, entity); + + ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() + .SingleOrDefaultAsync(x => x.Id == _user.Id.Value); + AssertUsers.AreEquivalent(entity, actor); + + Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() + .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) + .ToDictionaryAsync(x => x.Key, x => x.Value); + Assert.Equal(_user.CustomAttributes, customAttributes); + + UserAggregate? user = await _userRepository.LoadAsync(_user.Id); + Assert.NotNull(user); + Assert.Equal(_user.FirstName, user.FirstName); + Assert.Equal(_user.MiddleName, user.MiddleName); + Assert.Equal(_user.LastName, user.LastName); + Assert.Equal(_user.Nickname, user.Nickname); + Assert.Equal(_user.Birthdate, user.Birthdate); + Assert.Equal(_user.Gender, user.Gender); + Assert.Equal(_user.Locale, user.Locale); + Assert.Equal(_user.TimeZone, user.TimeZone); + Assert.Equal(_user.Picture, user.Picture); + Assert.Equal(_user.Profile, user.Profile); + Assert.Equal(_user.Website, user.Website); + Assert.Equal(_user.CustomAttributes, user.CustomAttributes); + } + + [Fact(DisplayName = "SaveAsync: it should save the specified users.")] + public async Task SaveAsync_it_should_save_the_specified_users() + { + UserAggregate disabled = new(new UniqueNameUnit(_userSettings.UniqueName, "disabled")); + UserAggregate deleted = new(new UniqueNameUnit(_userSettings.UniqueName, "deleted")); + await _userRepository.SaveAsync([disabled, deleted]); + + Dictionary entities = await IdentityContext.Users.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(disabled.Id.Value)); + Assert.True(entities.ContainsKey(deleted.Id.Value)); + + disabled.Disable(); + deleted.Delete(); + await _userRepository.SaveAsync([disabled, deleted]); + + entities = await IdentityContext.Users.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); + Assert.True(entities.ContainsKey(disabled.Id.Value)); + Assert.False(entities.ContainsKey(deleted.Id.Value)); + + AssertUsers.AreEqual(disabled, entities[disabled.Id.Value]); + + ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() + .SingleOrDefaultAsync(x => x.Id == deleted.Id.Value); + Assert.NotNull(actor); + Assert.True(actor.IsDeleted); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Tokens/TokenBlacklistTestsBase.cs b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Tokens/TokenBlacklistTestsBase.cs new file mode 100644 index 0000000..41063da --- /dev/null +++ b/tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Tokens/TokenBlacklistTestsBase.cs @@ -0,0 +1,138 @@ +using Logitar.Data; +using Logitar.EventSourcing.EntityFrameworkCore.Relational; +using Logitar.Identity.Domain.Tokens; +using Logitar.Identity.EntityFrameworkCore.Relational.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Logitar.Identity.EntityFrameworkCore.Relational.Tokens; + +public abstract class TokenBlacklistTestsBase : IAsyncLifetime +{ + private readonly EventContext _eventContext; + private readonly IdentityContext _identityContext; + private readonly IServiceProvider _serviceProvider; + private readonly ITokenBlacklist _tokenBlacklist; + + public TokenBlacklistTestsBase() + { + IConfiguration configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) + .Build(); + + ServiceCollection services = new(); + services.AddSingleton(configuration); + ConfigureServices(services, configuration); + _serviceProvider = services.BuildServiceProvider(); + + _eventContext = _serviceProvider.GetRequiredService(); + _identityContext = _serviceProvider.GetRequiredService(); + _tokenBlacklist = _serviceProvider.GetRequiredService(); + } + protected abstract void ConfigureServices(IServiceCollection services, IConfiguration configuration); + + public async Task InitializeAsync() + { + await _eventContext.Database.MigrateAsync(); + await _identityContext.Database.MigrateAsync(); + + TableId[] tables = [IdentityDb.TokenBlacklist.Table]; + foreach (TableId table in tables) + { + ICommand command = CreateDeleteBuilder(table).Build(); + await _identityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); + } + } + protected abstract IDeleteBuilder CreateDeleteBuilder(TableId table); + + [Fact(DisplayName = "BlacklistAsync: it should blacklist identifiers with expiration.")] + public async Task BlacklistAsync_it_should_blacklist_identifiers_with_expiration() + { + string duplicate = Guid.NewGuid().ToString(); + string[] tokenIds = [Guid.NewGuid().ToString(), duplicate, duplicate]; + DateTime expiresOn = DateTime.UtcNow.AddHours(1); + + await _tokenBlacklist.BlacklistAsync(tokenIds, expiresOn); + Dictionary entities = await _identityContext.TokenBlacklist.AsNoTracking() + .ToDictionaryAsync(x => x.TokenId, x => x); + Assert.Equal(2, entities.Count); + foreach (string tokenId in tokenIds) + { + Assert.True(entities.ContainsKey(tokenId)); + Assertions.Equal(expiresOn, entities[tokenId].ExpiresOn, TimeSpan.FromSeconds(1)); + } + } + + [Fact(DisplayName = "BlacklistAsync: it should blacklist identifiers without expiration.")] + public async Task BlacklistAsync_it_should_blacklist_identifiers_without_expiration() + { + string duplicate = Guid.NewGuid().ToString(); + string[] tokenIds = [Guid.NewGuid().ToString(), duplicate, duplicate]; + Dictionary entities; + + await _tokenBlacklist.BlacklistAsync(tokenIds); + entities = await _identityContext.TokenBlacklist.AsNoTracking().ToDictionaryAsync(x => x.TokenId, x => x); + foreach (string tokenId in tokenIds) + { + Assert.True(entities.ContainsKey(tokenId)); + Assert.Null(entities[tokenId].ExpiresOn); + } + + await _tokenBlacklist.BlacklistAsync(tokenIds, expiresOn: null); + entities = await _identityContext.TokenBlacklist.AsNoTracking().ToDictionaryAsync(x => x.TokenId, x => x); + foreach (string tokenId in tokenIds) + { + Assert.True(entities.ContainsKey(tokenId)); + Assert.Null(entities[tokenId].ExpiresOn); + } + } + + [Fact(DisplayName = "GetBlacklistedAsync: it should return empty when no ID is blacklisted.")] + public async Task GetBlacklistedAsync_it_should_return_empty_when_no_Id_is_blacklisted() + { + string[] tokenIds = [Guid.NewGuid().ToString(), Guid.NewGuid().ToString()]; + IEnumerable blacklistedIds = await _tokenBlacklist.GetBlacklistedAsync(tokenIds); + Assert.Empty(blacklistedIds); + } + + [Fact(DisplayName = "GetBlacklistedAsync: it should return only the blacklisted IDs.")] + public async Task GetBlacklistedAsync_it_should_return_only_the_blacklisted_Ids() + { + string blacklistedId = Guid.NewGuid().ToString(); + string otherId = Guid.NewGuid().ToString(); + + BlacklistedTokenEntity entity = new(blacklistedId); + _identityContext.TokenBlacklist.Add(entity); + await _identityContext.SaveChangesAsync(); + + string[] tokenIds = [blacklistedId, otherId]; + IEnumerable blacklistedIds = await _tokenBlacklist.GetBlacklistedAsync(tokenIds); + Assert.Equal([blacklistedId], blacklistedIds); + } + + [Fact(DisplayName = "PurgeAsync: it should remove only expired items.")] + public async Task PurgeAsync_it_should_remove_only_expired_items() + { + BlacklistedTokenEntity expired = new("expired") + { + ExpiresOn = DateTime.Now.AddDays(-1).ToUniversalTime() + }; + BlacklistedTokenEntity notExpired = new("notExpired") + { + ExpiresOn = DateTime.Now.AddDays(1).ToUniversalTime() + }; + BlacklistedTokenEntity noExpiration = new("noExpiration"); + _identityContext.TokenBlacklist.AddRange(expired, notExpired, noExpiration); + await _identityContext.SaveChangesAsync(); + + await _tokenBlacklist.PurgeAsync(); + + HashSet entities = [.. (await _identityContext.TokenBlacklist.AsNoTracking().Select(x => x.TokenId).ToArrayAsync())]; + Assert.Equal(2, entities.Count); + Assert.Contains(notExpired.TokenId, entities); + Assert.Contains(noExpiration.TokenId, entities); + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Logitar.Identity.EFCore.SqlServer.IntegrationTests.csproj b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Logitar.Identity.EFCore.SqlServer.IntegrationTests.csproj index c8b0668..497e46b 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Logitar.Identity.EFCore.SqlServer.IntegrationTests.csproj +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Logitar.Identity.EFCore.SqlServer.IntegrationTests.csproj @@ -23,7 +23,6 @@ - @@ -38,7 +37,7 @@ - + diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs index 7917f7a..ff91fdf 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs @@ -1,236 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing; -using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.Contracts.Settings; -using Logitar.Identity.Domain.ApiKeys; -using Logitar.Identity.Domain.Passwords; -using Logitar.Identity.Domain.Roles; -using Logitar.Identity.Domain.Settings; -using Logitar.Identity.Domain.Shared; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; [Trait(Traits.Category, Categories.Integration)] -public class ApiKeyRepositoryTests : RepositoryTests, IAsyncLifetime +public class ApiKeyRepositoryTests : ApiKeyRepositoryTestsBase, IAsyncLifetime { - private readonly IApiKeyRepository _apiKeyRepository; - private readonly IPasswordManager _passwordManager; - private readonly IRoleRepository _roleRepository; - private readonly IRoleSettings _roleSettings; - - private readonly Password _secret; - private readonly string _secretString; - - private readonly ApiKeyAggregate _apiKey; - private readonly RoleAggregate _role; - public ApiKeyRepositoryTests() : base() { - _apiKeyRepository = ServiceProvider.GetRequiredService(); - _passwordManager = ServiceProvider.GetRequiredService(); - _roleRepository = ServiceProvider.GetRequiredService(); - _roleSettings = ServiceProvider.GetRequiredService().Resolve(); - - ApiKeyId apiKeyId = ApiKeyId.NewId(); - ActorId actorId = new(apiKeyId.Value); - TenantId tenantId = new("tests"); - - _role = new(new UniqueNameUnit(_roleSettings.UniqueName, "clerk"), tenantId, actorId); - - DisplayNameUnit displayName = new("Default"); - _secret = _passwordManager.GenerateBase64(32, out _secretString); - _apiKey = new(displayName, _secret, tenantId, actorId, apiKeyId) - { - Description = new DescriptionUnit("This is the default API key.") - }; - _apiKey.SetExpiration(DateTime.Now.AddYears(1)); - _apiKey.SetCustomAttribute("OwnerId", Guid.NewGuid().ToString()); - _apiKey.Update(actorId); - - _apiKey.AddRole(_role, actorId); - - _apiKey.Authenticate(_secretString, actorId); - } - - public async Task InitializeAsync() - { - await EventContext.Database.MigrateAsync(); - await IdentityContext.Database.MigrateAsync(); - - TableId[] tables = - [ - IdentityDb.ApiKeys.Table, - IdentityDb.Roles.Table, - IdentityDb.CustomAttributes.Table, - IdentityDb.Actors.Table, - EventDb.Events.Table - ]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } - - await _roleRepository.SaveAsync(_role); - await _apiKeyRepository.SaveAsync(_apiKey); - } - - [Fact(DisplayName = "LoadAsync: it should load all the API keys.")] - public async Task LoadAsync_it_should_load_all_the_Api_keys() - { - ApiKeyAggregate deleted = new(_apiKey.DisplayName, _secret, tenantId: null); - deleted.Delete(); - await _apiKeyRepository.SaveAsync(deleted); - - IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(includeDeleted: true); - Assert.Equal(2, apiKeys.Count()); - Assert.Contains(apiKeys, _apiKey.Equals); - Assert.Contains(apiKeys, deleted.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the API key by identifier.")] - public async Task LoadAsync_it_should_load_the_Api_key_by_identifier() - { - Assert.Null(await _apiKeyRepository.LoadAsync(ApiKeyId.NewId())); - - _apiKey.Delete(); - long version = _apiKey.Version; - - DateTime? authenticatedOn = _apiKey.AuthenticatedOn; - _apiKey.Authenticate(_secretString); - await _apiKeyRepository.SaveAsync(_apiKey); - - Assert.Null(await _apiKeyRepository.LoadAsync(_apiKey.Id, version)); - - ApiKeyAggregate? apiKey = await _apiKeyRepository.LoadAsync(_apiKey.Id, version, includeDeleted: true); - Assert.NotNull(apiKey); - Assert.Equal(authenticatedOn, apiKey.AuthenticatedOn); - Assert.Equal(_apiKey, apiKey); } - [Fact(DisplayName = "LoadAsync: it should load the API key by role.")] - public async Task LoadAsync_it_should_load_the_Api_key_by_role() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - RoleAggregate admin = new(new UniqueNameUnit(_roleSettings.UniqueName, "admin"), _apiKey.TenantId); - await _roleRepository.SaveAsync(admin); - - Assert.Empty(await _apiKeyRepository.LoadAsync(admin)); - - IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(_role); - Assert.Equal(_apiKey, apiKeys.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the API keys by tenant identifier.")] - public async Task LoadAsync_it_should_load_the_apiKeys_by_tenant_identifier() - { - ApiKeyAggregate apiKey = new(new DisplayNameUnit("Other API key"), _secret, tenantId: null); - ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret, _apiKey.TenantId); - deleted.Delete(); - await _apiKeyRepository.SaveAsync([apiKey, deleted]); - - IEnumerable apiKeys = await _apiKeyRepository.LoadAsync(_apiKey.TenantId); - Assert.Equal(_apiKey, apiKeys.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the API keys by identifiers.")] - public async Task LoadAsync_it_should_load_the_Api_keys_by_identifiers() - { - ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret, tenantId: null); - deleted.Delete(); - await _apiKeyRepository.SaveAsync(deleted); - - IEnumerable apiKeys = await _apiKeyRepository.LoadAsync([_apiKey.Id, deleted.Id, ApiKeyId.NewId()], includeDeleted: true); - Assert.Equal(2, apiKeys.Count()); - Assert.Contains(apiKeys, _apiKey.Equals); - Assert.Contains(apiKeys, deleted.Equals); - } - - [Fact(DisplayName = "SaveAsync: it should save the deleted API key.")] - public async Task SaveAsync_it_should_save_the_deleted_Api_key() - { - _apiKey.SetCustomAttribute("Confidentiality", "Private"); - _apiKey.SetCustomAttribute("SubSystem", "IntegrationTests"); - _apiKey.Update(); - await _apiKeyRepository.SaveAsync(_apiKey); - - ApiKeyEntity? entity = await IdentityContext.ApiKeys.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _apiKey.Id.Value); - Assert.NotNull(entity); - - CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) - .ToArrayAsync(); - Assert.Equal(_apiKey.CustomAttributes.Count, customAttributes.Length); - foreach (KeyValuePair customAttribute in _apiKey.CustomAttributes) - { - Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); - } - - _apiKey.Delete(); - await _apiKeyRepository.SaveAsync(_apiKey); - - customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) - .ToArrayAsync(); - Assert.Empty(customAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified API key.")] - public async Task SaveAsync_it_should_save_the_specified_Api_key() - { - ApiKeyEntity? entity = await IdentityContext.ApiKeys.AsNoTracking() - .Include(x => x.Roles) - .SingleOrDefaultAsync(x => x.AggregateId == _apiKey.Id.Value); - Assert.NotNull(entity); - AssertApiKeys.AreEqual(_apiKey, entity); - - ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() - .SingleOrDefaultAsync(x => x.Id == _apiKey.Id.Value); - AssertApiKeys.AreEquivalent(entity, actor); - - Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.ApiKeys) && x.EntityId == entity.ApiKeyId) - .ToDictionaryAsync(x => x.Key, x => x.Value); - Assert.Equal(_apiKey.CustomAttributes, customAttributes); - - ApiKeyAggregate? apiKey = await _apiKeyRepository.LoadAsync(_apiKey.Id); - Assert.NotNull(apiKey); - Assert.Equal(_apiKey.Description, apiKey.Description); - Assert.Equal(_apiKey.ExpiresOn, apiKey.ExpiresOn); - Assert.Equal(_apiKey.CustomAttributes, apiKey.CustomAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified API keys.")] - public async Task SaveAsync_it_should_save_the_specified_Api_keys() - { - ApiKeyAggregate authenticated = new(new DisplayNameUnit("authenticated"), _secret); - ApiKeyAggregate deleted = new(new DisplayNameUnit("deleted"), _secret); - await _apiKeyRepository.SaveAsync([authenticated, deleted]); - - Dictionary entities = await IdentityContext.ApiKeys.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(authenticated.Id.Value)); - Assert.True(entities.ContainsKey(deleted.Id.Value)); - - authenticated.Authenticate(_secretString); - deleted.Delete(); - await _apiKeyRepository.SaveAsync([authenticated, deleted]); - - entities = await IdentityContext.ApiKeys.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(authenticated.Id.Value)); - Assert.False(entities.ContainsKey(deleted.Id.Value)); - - AssertApiKeys.AreEqual(authenticated, entities[authenticated.Id.Value]); - - ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() - .SingleOrDefaultAsync(x => x.Id == deleted.Id.Value); - Assert.NotNull(actor); - Assert.True(actor.IsDeleted); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); } diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs index c009601..95684cc 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs @@ -1,186 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing; -using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.Domain.Passwords; -using Logitar.Identity.Domain.Shared; -using Logitar.Identity.Domain.Users; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; [Trait(Traits.Category, Categories.Integration)] -public class OneTimePasswordRepositoryTests : RepositoryTests, IAsyncLifetime +public class OneTimePasswordRepositoryTests : OneTimePasswordRepositoryTestsBase, IAsyncLifetime { - private const string PasswordString = "284199"; - - private readonly IOneTimePasswordRepository _oneTimePasswordRepository; - private readonly IPasswordManager _passwordManager; - - private readonly Password _password; - private readonly OneTimePasswordAggregate _oneTimePassword; - public OneTimePasswordRepositoryTests() : base() { - _oneTimePasswordRepository = ServiceProvider.GetRequiredService(); - _passwordManager = ServiceProvider.GetRequiredService(); - - TenantId tenantId = new("tests"); - DateTime expiresOn = DateTime.Now.AddHours(1); - int maximumAttempts = 5; - ActorId actorId = ActorId.NewId(); - OneTimePasswordId id = OneTimePasswordId.NewId(); - - _password = _passwordManager.Create(PasswordString); - _oneTimePassword = new(_password, tenantId, expiresOn, maximumAttempts, actorId, id); - _oneTimePassword.SetCustomAttribute("Purpose", "MultiFactorAuthentication"); - _oneTimePassword.SetCustomAttribute("UserId", Guid.NewGuid().ToString()); - _oneTimePassword.Update(actorId); - } - - public async Task InitializeAsync() - { - await EventContext.Database.MigrateAsync(); - await IdentityContext.Database.MigrateAsync(); - - TableId[] tables = [IdentityDb.OneTimePasswords.Table, IdentityDb.CustomAttributes.Table, EventDb.Events.Table]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } - - await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); } - [Fact(DisplayName = "LoadAsync: it should load all the One-Time Passwords.")] - public async Task LoadAsync_it_should_load_all_the_One_Time_Passwords() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - OneTimePasswordAggregate deleted = new(_password, tenantId: null); - deleted.Delete(); - await _oneTimePasswordRepository.SaveAsync(deleted); - - IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync(includeDeleted: true); - Assert.Equal(2, oneTimePasswords.Count()); - Assert.Contains(oneTimePasswords, _oneTimePassword.Equals); - Assert.Contains(oneTimePasswords, deleted.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the One-Time Password by identifier.")] - public async Task LoadAsync_it_should_load_the_One_Time_Password_by_identifier() - { - Assert.Null(await _oneTimePasswordRepository.LoadAsync(OneTimePasswordId.NewId())); - - _oneTimePassword.Delete(); - long version = _oneTimePassword.Version; - - _oneTimePassword.Validate(PasswordString); - await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); - - Assert.Null(await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id, version)); - - OneTimePasswordAggregate? oneTimePassword = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id, version, includeDeleted: true); - Assert.NotNull(oneTimePassword); - Assert.Equal(_oneTimePassword, oneTimePassword); - } - - [Fact(DisplayName = "LoadAsync: it should load the One-Time Passwords by tenant identifier.")] - public async Task LoadAsync_it_should_load_the_One_Time_Passwords_by_tenant_identifier() - { - OneTimePasswordAggregate oneTimePassword = new(_password, tenantId: null); - OneTimePasswordAggregate deleted = new(_password, _oneTimePassword.TenantId); - deleted.Delete(); - await _oneTimePasswordRepository.SaveAsync([oneTimePassword, deleted]); - - IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.TenantId); - Assert.Equal(_oneTimePassword, oneTimePasswords.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the One-Time Passwords by identifiers.")] - public async Task LoadAsync_it_should_load_the_One_Time_Passwords_by_identifiers() - { - OneTimePasswordAggregate deleted = new(_password, tenantId: null); - deleted.Delete(); - await _oneTimePasswordRepository.SaveAsync(deleted); - - IEnumerable oneTimePasswords = await _oneTimePasswordRepository.LoadAsync([_oneTimePassword.Id, deleted.Id, OneTimePasswordId.NewId()], includeDeleted: true); - Assert.Equal(2, oneTimePasswords.Count()); - Assert.Contains(oneTimePasswords, _oneTimePassword.Equals); - Assert.Contains(oneTimePasswords, deleted.Equals); - } - - [Fact(DisplayName = "SaveAsync: it should save the deleted One-Time Password.")] - public async Task SaveAsync_it_should_save_the_deleted_One_Time_Password() - { - _oneTimePassword.SetCustomAttribute("Purpose", "reset_password"); - _oneTimePassword.SetCustomAttribute("UserId", UserId.NewId().Value); - _oneTimePassword.Update(); - await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); - - OneTimePasswordEntity? entity = await IdentityContext.OneTimePasswords.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _oneTimePassword.Id.Value); - Assert.NotNull(entity); - - CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) - .ToArrayAsync(); - Assert.Equal(_oneTimePassword.CustomAttributes.Count, customAttributes.Length); - foreach (KeyValuePair customAttribute in _oneTimePassword.CustomAttributes) - { - Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); - } - - _oneTimePassword.Delete(); - await _oneTimePasswordRepository.SaveAsync(_oneTimePassword); - - customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) - .ToArrayAsync(); - Assert.Empty(customAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified One-Time Password.")] - public async Task SaveAsync_it_should_save_the_specified_One_Time_Password() - { - OneTimePasswordEntity? entity = await IdentityContext.OneTimePasswords.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _oneTimePassword.Id.Value); - Assert.NotNull(entity); - AssertOneTimePasswords.AreEqual(_oneTimePassword, entity); - - Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.OneTimePasswords) && x.EntityId == entity.OneTimePasswordId) - .ToDictionaryAsync(x => x.Key, x => x.Value); - Assert.Equal(_oneTimePassword.CustomAttributes, customAttributes); - - OneTimePasswordAggregate? oneTimePassword = await _oneTimePasswordRepository.LoadAsync(_oneTimePassword.Id); - Assert.NotNull(oneTimePassword); - Assert.Equal(_oneTimePassword.CustomAttributes, oneTimePassword.CustomAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified One-Time Passwords.")] - public async Task SaveAsync_it_should_save_the_specified_One_Time_Passwords() - { - OneTimePasswordAggregate succeeded = new(_password); - OneTimePasswordAggregate deleted = new(_password); - await _oneTimePasswordRepository.SaveAsync([succeeded, deleted]); - - Dictionary entities = await IdentityContext.OneTimePasswords.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(succeeded.Id.Value)); - Assert.True(entities.ContainsKey(deleted.Id.Value)); - - succeeded.Validate(PasswordString); - deleted.Delete(); - await _oneTimePasswordRepository.SaveAsync([succeeded, deleted]); - - entities = await IdentityContext.OneTimePasswords.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(succeeded.Id.Value)); - Assert.False(entities.ContainsKey(deleted.Id.Value)); - - AssertOneTimePasswords.AreEqual(succeeded, entities[succeeded.Id.Value]); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); } diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RoleRepositoryTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RoleRepositoryTests.cs index 63471b7..1bfc849 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RoleRepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/RoleRepositoryTests.cs @@ -1,248 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing; -using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.Contracts.Settings; -using Logitar.Identity.Domain.ApiKeys; -using Logitar.Identity.Domain.Passwords; -using Logitar.Identity.Domain.Roles; -using Logitar.Identity.Domain.Settings; -using Logitar.Identity.Domain.Shared; -using Logitar.Identity.Domain.Users; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; [Trait(Traits.Category, Categories.Integration)] -public class RoleRepositoryTests : RepositoryTests, IAsyncLifetime +public class RoleRepositoryTests : RoleRepositoryTestsBase, IAsyncLifetime { - private readonly IApiKeyRepository _apiKeyRepository; - private readonly IPasswordManager _passwordManager; - private readonly IRoleRepository _roleRepository; - private readonly IRoleSettings _roleSettings; - private readonly IUserRepository _userRepository; - private readonly IUserSettings _userSettings; - - private readonly RoleAggregate _role; - public RoleRepositoryTests() : base() { - _apiKeyRepository = ServiceProvider.GetRequiredService(); - _passwordManager = ServiceProvider.GetRequiredService(); - _roleRepository = ServiceProvider.GetRequiredService(); - _roleSettings = ServiceProvider.GetRequiredService().Resolve(); - _userRepository = ServiceProvider.GetRequiredService(); - _userSettings = ServiceProvider.GetRequiredService().Resolve(); - - RoleId roleId = RoleId.NewId(); - ActorId actorId = new(roleId.Value); - TenantId tenantId = new("tests"); - - UniqueNameUnit uniqueName = new(_roleSettings.UniqueName, "send_messages"); - _role = new(uniqueName, tenantId, actorId, roleId) - { - DisplayName = new DisplayNameUnit("Send Messages"), - Description = new DescriptionUnit("This role allows to send messages.") - }; - _role.SetCustomAttribute("manage_messages", bool.TrueString); - _role.Update(actorId); - } - - public async Task InitializeAsync() - { - await EventContext.Database.MigrateAsync(); - await IdentityContext.Database.MigrateAsync(); - - TableId[] tables = - [ - IdentityDb.Roles.Table, - IdentityDb.CustomAttributes.Table, - EventDb.Events.Table - ]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } - - await _roleRepository.SaveAsync(_role); - await _roleRepository.SaveAsync(_role); - } - - [Fact(DisplayName = "LoadAsync: it should load all the roles.")] - public async Task LoadAsync_it_should_load_all_the_roles() - { - RoleAggregate deleted = new(_role.UniqueName, tenantId: null); - deleted.Delete(); - await _roleRepository.SaveAsync(deleted); - - IEnumerable roles = await _roleRepository.LoadAsync(includeDeleted: true); - Assert.Equal(2, roles.Count()); - Assert.Contains(roles, _role.Equals); - Assert.Contains(roles, deleted.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the role by identifier.")] - public async Task LoadAsync_it_should_load_the_role_by_identifier() - { - Assert.Null(await _roleRepository.LoadAsync(RoleId.NewId())); - - _role.Delete(); - long version = _role.Version; - - UniqueNameUnit oldUniqueName = _role.UniqueName; - _role.SetUniqueName(new UniqueNameUnit(_roleSettings.UniqueName, "guest")); - await _roleRepository.SaveAsync(_role); - - Assert.Null(await _roleRepository.LoadAsync(_role.Id, version)); - - RoleAggregate? role = await _roleRepository.LoadAsync(_role.Id, version, includeDeleted: true); - Assert.NotNull(role); - Assert.Equal(oldUniqueName, role.UniqueName); - Assert.Equal(_role, role); } - [Fact(DisplayName = "LoadAsync: it should load the roles by tenant identifier.")] - public async Task LoadAsync_it_should_load_the_roles_by_tenant_identifier() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - RoleAggregate role = new(_role.UniqueName, tenantId: null); - RoleAggregate deleted = new(new UniqueNameUnit(_roleSettings.UniqueName, "deleted"), _role.TenantId); - deleted.Delete(); - await _roleRepository.SaveAsync([role, deleted]); - - IEnumerable roles = await _roleRepository.LoadAsync(_role.TenantId); - Assert.Equal(_role, roles.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the role by unique name.")] - public async Task LoadAsync_it_should_load_the_role_by_unique_name() - { - Assert.Null(await _roleRepository.LoadAsync(tenantId: null, _role.UniqueName)); - - UniqueNameUnit uniqueName = new(_roleSettings.UniqueName, $"{_role.UniqueName.Value}2"); - Assert.Null(await _roleRepository.LoadAsync(_role.TenantId, uniqueName)); - - RoleAggregate? role = await _roleRepository.LoadAsync(_role.TenantId, _role.UniqueName); - Assert.NotNull(role); - Assert.Equal(_role, role); - } - - [Fact(DisplayName = "LoadAsync: it should load the roles by identifiers.")] - public async Task LoadAsync_it_should_load_the_roles_by_identifiers() - { - RoleAggregate deleted = new(_role.UniqueName, tenantId: null); - deleted.Delete(); - await _roleRepository.SaveAsync(deleted); - - IEnumerable roles = await _roleRepository.LoadAsync([_role.Id, deleted.Id, RoleId.NewId()], includeDeleted: true); - Assert.Equal(2, roles.Count()); - Assert.Contains(roles, _role.Equals); - Assert.Contains(roles, deleted.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the roles by API key.")] - public async Task LoadAsync_it_should_load_the_roles_by_Api_key() - { - RoleAggregate manageUsers = new(new UniqueNameUnit(_roleSettings.UniqueName, "manage_users")); - await _roleRepository.SaveAsync(manageUsers); - - Password secret = _passwordManager.GenerateBase64(32, out _); - ApiKeyAggregate apiKey = new(new DisplayNameUnit("Default"), secret); - apiKey.AddRole(manageUsers); - await _apiKeyRepository.SaveAsync(apiKey); - - RoleAggregate role = Assert.Single(await _roleRepository.LoadAsync(apiKey)); - Assert.Equal(manageUsers, role); - } - - [Fact(DisplayName = "LoadAsync: it should load the roles by user.")] - public async Task LoadAsync_it_should_load_the_roles_by_user() - { - RoleAggregate manageUsers = new(new UniqueNameUnit(_roleSettings.UniqueName, "manage_users")); - await _roleRepository.SaveAsync(manageUsers); - - UserAggregate user = new(new UniqueNameUnit(_userSettings.UniqueName, Faker.Internet.UserName())); - user.AddRole(manageUsers); - await _userRepository.SaveAsync(user); - - RoleAggregate role = Assert.Single(await _roleRepository.LoadAsync(user)); - Assert.Equal(manageUsers, role); - } - - [Fact(DisplayName = "SaveAsync: it should save the deleted role.")] - public async Task SaveAsync_it_should_save_the_deleted_role() - { - _role.SetCustomAttribute("read_messages", bool.TrueString); - _role.SetCustomAttribute("edit_messages", bool.FalseString); - _role.Update(); - await _roleRepository.SaveAsync(_role); - - RoleEntity? entity = await IdentityContext.Roles.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _role.Id.Value); - Assert.NotNull(entity); - - CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) - .ToArrayAsync(); - Assert.Equal(_role.CustomAttributes.Count, customAttributes.Length); - foreach (KeyValuePair customAttribute in _role.CustomAttributes) - { - Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); - } - - _role.Delete(); - await _roleRepository.SaveAsync(_role); - - customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) - .ToArrayAsync(); - Assert.Empty(customAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified role.")] - public async Task SaveAsync_it_should_save_the_specified_role() - { - RoleEntity? entity = await IdentityContext.Roles.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _role.Id.Value); - Assert.NotNull(entity); - AssertRoles.AreEqual(_role, entity); - - Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Roles) && x.EntityId == entity.RoleId) - .ToDictionaryAsync(x => x.Key, x => x.Value); - Assert.Equal(_role.CustomAttributes, customAttributes); - - RoleAggregate? role = await _roleRepository.LoadAsync(_role.Id); - Assert.NotNull(role); - Assert.Equal(_role.DisplayName, role.DisplayName); - Assert.Equal(_role.Description, role.Description); - Assert.Equal(_role.CustomAttributes, role.CustomAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified roles.")] - public async Task SaveAsync_it_should_save_the_specified_roles() - { - RoleAggregate guest = new(new UniqueNameUnit(_roleSettings.UniqueName, "gwest")); - RoleAggregate deleted = new(new UniqueNameUnit(_roleSettings.UniqueName, "deleted")); - await _roleRepository.SaveAsync([guest, deleted]); - - Dictionary entities = await IdentityContext.Roles.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(guest.Id.Value)); - Assert.True(entities.ContainsKey(deleted.Id.Value)); - - guest.SetUniqueName(new UniqueNameUnit(_roleSettings.UniqueName, "guest")); - deleted.Delete(); - await _roleRepository.SaveAsync([guest, deleted]); - - entities = await IdentityContext.Roles.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(guest.Id.Value)); - Assert.False(entities.ContainsKey(deleted.Id.Value)); - - AssertRoles.AreEqual(guest, entities[guest.Id.Value]); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); } diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/SessionRepositoryTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/SessionRepositoryTests.cs index 7effee2..bced6d7 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/SessionRepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/SessionRepositoryTests.cs @@ -1,227 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing; -using Logitar.Identity.Contracts.Settings; -using Logitar.Identity.Domain.Sessions; -using Logitar.Identity.Domain.Settings; -using Logitar.Identity.Domain.Shared; -using Logitar.Identity.Domain.Users; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; -public class SessionRepositoryTests : RepositoryTests, IAsyncLifetime +[Trait(Traits.Category, Categories.Integration)] +public class SessionRepositoryTests : SessionRepositoryTestsBase, IAsyncLifetime { - private readonly ISessionRepository _sessionRepository; - private readonly IUserRepository _userRepository; - private readonly IUserSettings _userSettings; - - private readonly UserAggregate _user; - private readonly SessionAggregate _session; - public SessionRepositoryTests() : base() { - _sessionRepository = ServiceProvider.GetRequiredService(); - _userRepository = ServiceProvider.GetRequiredService(); - _userSettings = ServiceProvider.GetRequiredService().Resolve(); - - UserId userId = UserId.NewId(); - ActorId actorId = new(userId.Value); - - TenantId tenantId = new("tests"); - UniqueNameUnit uniqueName = new(_userSettings.UniqueName, Faker.Person.UserName); - _user = new(uniqueName, tenantId, actorId, userId); - - _session = new(_user); - - _session.SetCustomAttribute("IpAddress", Faker.Internet.Ip()); - _session.Update(actorId); - } - - public async Task InitializeAsync() - { - await EventContext.Database.MigrateAsync(); - await IdentityContext.Database.MigrateAsync(); - - TableId[] tables = [IdentityDb.Sessions.Table, IdentityDb.Users.Table, IdentityDb.CustomAttributes.Table, IdentityDb.Actors.Table, EventDb.Events.Table]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } - - await _userRepository.SaveAsync(_user); - await _sessionRepository.SaveAsync(_session); - } - - [Fact(DisplayName = "LoadAsync: it should load all the sessions.")] - public async Task LoadAsync_it_should_load_all_the_sessions() - { - SessionAggregate deleted = new(_user); - deleted.Delete(); - await _sessionRepository.SaveAsync(deleted); - - IEnumerable sessions = await _sessionRepository.LoadAsync(includeDeleted: true); - Assert.Equal(2, sessions.Count()); - Assert.Contains(sessions, _session.Equals); - Assert.Contains(sessions, deleted.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the active sessions by user.")] - public async Task LoadAsync_it_should_load_the_active_sessions_by_user() - { - UserAggregate user = new(_user.UniqueName, tenantId: null); - await _userRepository.SaveAsync(user); - - SessionAggregate session = new(user); - SessionAggregate deleted = new(_user); - deleted.Delete(); - SessionAggregate signedOut = new(_user); - signedOut.SignOut(); - await _sessionRepository.SaveAsync([session, deleted, signedOut]); - IEnumerable sessions = await _sessionRepository.LoadActiveAsync(_user); - Assert.Equal(_session, sessions.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the session by identifier.")] - public async Task LoadAsync_it_should_load_the_session_by_identifier() - { - Assert.Null(await _sessionRepository.LoadAsync(SessionId.NewId())); - - _session.Delete(); - long version = _session.Version; - - _session.SignOut(); - await _sessionRepository.SaveAsync(_session); - - Assert.Null(await _sessionRepository.LoadAsync(_session.Id, version)); - - SessionAggregate? session = await _sessionRepository.LoadAsync(_session.Id, version, includeDeleted: true); - Assert.NotNull(session); - Assert.True(session.IsActive); - Assert.Equal(_session, session); - } - - [Fact(DisplayName = "LoadAsync: it should load the sessions by tenant identifier.")] - public async Task LoadAsync_it_should_load_the_sessions_by_tenant_identifier() - { - UserAggregate user = new(_user.UniqueName, tenantId: null); - await _userRepository.SaveAsync(user); - - SessionAggregate session = new(user); - SessionAggregate deleted = new(_user); - deleted.Delete(); - await _sessionRepository.SaveAsync([session, deleted]); - - IEnumerable sessions = await _sessionRepository.LoadAsync(_user.TenantId); - Assert.Equal(_session, sessions.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the sessions by user.")] - public async Task LoadAsync_it_should_load_the_sessions_by_user() - { - UserAggregate user = new(_user.UniqueName, tenantId: null); - await _userRepository.SaveAsync(user); - - SessionAggregate session = new(user); - SessionAggregate deleted = new(_user); - deleted.Delete(); - SessionAggregate signedOut = new(_user); - signedOut.SignOut(); - await _sessionRepository.SaveAsync([session, deleted, signedOut]); - - IEnumerable sessions = await _sessionRepository.LoadAsync(_user); - Assert.Equal(2, sessions.Count()); - Assert.Contains(sessions, _session.Equals); - Assert.Contains(sessions, signedOut.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the sessions by identifiers.")] - public async Task LoadAsync_it_should_load_the_sessions_by_identifiers() - { - SessionAggregate deleted = new(_user); - deleted.Delete(); - await _sessionRepository.SaveAsync(deleted); - - IEnumerable sessions = await _sessionRepository.LoadAsync([_session.Id, deleted.Id, SessionId.NewId()], includeDeleted: true); - Assert.Equal(2, sessions.Count()); - Assert.Contains(sessions, _session.Equals); - Assert.Contains(sessions, deleted.Equals); - } - - [Fact(DisplayName = "SaveAsync: it should save the deleted session.")] - public async Task SaveAsync_it_should_save_the_deleted_session() - { - _session.SetCustomAttribute("AdditionalInformation", $@"{{""User-Agent"":""{Faker.Internet.UserAgent()}""}}"); - _session.SetCustomAttribute("IpAddress", Faker.Internet.Ip()); - _session.Update(); - await _sessionRepository.SaveAsync(_session); - - SessionEntity? entity = await IdentityContext.Sessions.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _session.Id.Value); - Assert.NotNull(entity); - - CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) - .ToArrayAsync(); - Assert.Equal(_session.CustomAttributes.Count, customAttributes.Length); - foreach (KeyValuePair customAttribute in _session.CustomAttributes) - { - Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); - } - - _session.Delete(); - await _sessionRepository.SaveAsync(_session); - - customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) - .ToArrayAsync(); - Assert.Empty(customAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified session.")] - public async Task SaveAsync_it_should_save_the_specified_session() - { - SessionEntity? entity = await IdentityContext.Sessions.AsNoTracking() - .Include(x => x.User) - .SingleOrDefaultAsync(x => x.AggregateId == _session.Id.Value); - Assert.NotNull(entity); - AssertSessions.AreEqual(_session, entity); - - Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Sessions) && x.EntityId == entity.SessionId) - .ToDictionaryAsync(x => x.Key, x => x.Value); - Assert.Equal(_session.CustomAttributes, customAttributes); - - SessionAggregate? session = await _sessionRepository.LoadAsync(_session.Id); - Assert.NotNull(session); - Assert.Equal(_session.CustomAttributes, session.CustomAttributes); } - [Fact(DisplayName = "SaveAsync: it should save the specified sessions.")] - public async Task SaveAsync_it_should_save_the_specified_sessions() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - SessionAggregate signedOut = new(_user); - SessionAggregate deleted = new(_user); - await _sessionRepository.SaveAsync([signedOut, deleted]); - - Dictionary entities = await IdentityContext.Sessions.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(signedOut.Id.Value)); - Assert.True(entities.ContainsKey(deleted.Id.Value)); - - signedOut.SignOut(); - deleted.Delete(); - await _sessionRepository.SaveAsync([signedOut, deleted]); - - entities = await IdentityContext.Sessions.AsNoTracking().Include(x => x.User).ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(signedOut.Id.Value)); - Assert.False(entities.ContainsKey(deleted.Id.Value)); - - AssertSessions.AreEqual(signedOut, entities[signedOut.Id.Value]); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); } diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/UserRepositoryTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/UserRepositoryTests.cs index 71e0ae2..2201922 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/UserRepositoryTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Repositories/UserRepositoryTests.cs @@ -1,322 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing; -using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.Contracts.Settings; -using Logitar.Identity.Domain.Passwords; -using Logitar.Identity.Domain.Roles; -using Logitar.Identity.Domain.Sessions; -using Logitar.Identity.Domain.Settings; -using Logitar.Identity.Domain.Shared; -using Logitar.Identity.Domain.Users; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Repositories; [Trait(Traits.Category, Categories.Integration)] -public class UserRepositoryTests : RepositoryTests, IAsyncLifetime +public class UserRepositoryTests : UserRepositoryTestsBase, IAsyncLifetime { - private const string EmployeeIdKey = "EmployeeId"; - private const string PasswordString = "P@s$W0rD"; - - private readonly IPasswordManager _passwordManager; - private readonly IRoleRepository _roleRepository; - private readonly IRoleSettings _roleSettings; - private readonly IUserRepository _userRepository; - private readonly IUserSettings _userSettings; - - private readonly RoleAggregate _role; - private readonly UserAggregate _user; - public UserRepositoryTests() : base() { - _passwordManager = ServiceProvider.GetRequiredService(); - _roleRepository = ServiceProvider.GetRequiredService(); - _roleSettings = ServiceProvider.GetRequiredService().Resolve(); - _userRepository = ServiceProvider.GetRequiredService(); - _userSettings = ServiceProvider.GetRequiredService().Resolve(); - - UserId userId = UserId.NewId(); - ActorId actorId = new(userId.Value); - TenantId tenantId = new("tests"); - - _role = new(new UniqueNameUnit(_roleSettings.UniqueName, "clerk"), tenantId, actorId); - - UniqueNameUnit uniqueName = new(_userSettings.UniqueName, Faker.Person.UserName); - _user = new(uniqueName, tenantId, actorId, userId) - { - FirstName = new PersonNameUnit(Faker.Person.FirstName), - MiddleName = new PersonNameUnit(Faker.Name.FirstName()), - LastName = new PersonNameUnit(Faker.Person.LastName), - Nickname = new PersonNameUnit("Toto"), - Birthdate = Faker.Person.DateOfBirth, - Gender = new GenderUnit(Faker.Person.Gender.ToString()), - Locale = new LocaleUnit(Faker.Locale), - TimeZone = new TimeZoneUnit("America/Montreal"), - Picture = new UrlUnit($"https://www.{Faker.Person.Website}/img/profile.jpg"), - Profile = new UrlUnit($"https://www.desjardins.com/profiles/toto"), - Website = new UrlUnit($"https://www.{Faker.Person.Website}") - }; - _user.SetCustomAttribute("Department", "Finances"); - _user.Update(actorId); - - _user.SetAddress(new AddressUnit("150 Saint-Catherine St W", "Montreal", "CA", "QC", "H2X 3Y2"), actorId); - _user.SetEmail(new EmailUnit(Faker.Person.Email, isVerified: true), actorId); - _user.SetPhone(new PhoneUnit("+1 (514) 845-4636", "CA", "123456"), actorId); - - _user.AddRole(_role, actorId); - _user.SetCustomIdentifier(EmployeeIdKey, Guid.NewGuid().ToString(), actorId); - _user.SetPassword(_passwordManager.Create(PasswordString), actorId); - - _user.Authenticate(PasswordString, actorId); - } - - public async Task InitializeAsync() - { - await EventContext.Database.MigrateAsync(); - await IdentityContext.Database.MigrateAsync(); - - TableId[] tables = - [ - IdentityDb.Sessions.Table, - IdentityDb.Users.Table, - IdentityDb.ApiKeys.Table, - IdentityDb.Roles.Table, - IdentityDb.CustomAttributes.Table, - IdentityDb.Actors.Table, - EventDb.Events.Table - ]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await IdentityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } - - await _roleRepository.SaveAsync(_role); - await _userRepository.SaveAsync(_user); - } - - [Fact(DisplayName = "LoadAsync: it should load all the users.")] - public async Task LoadAsync_it_should_load_all_the_users() - { - UserAggregate deleted = new(_user.UniqueName, tenantId: null); - deleted.Delete(); - await _userRepository.SaveAsync(deleted); - - IEnumerable users = await _userRepository.LoadAsync(includeDeleted: true); - Assert.Equal(2, users.Count()); - Assert.Contains(users, _user.Equals); - Assert.Contains(users, deleted.Equals); } - [Fact(DisplayName = "LoadAsync: it should load the user by custom identifier.")] - public async Task LoadAsync_it_should_load_the_user_by_custom_identifier() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - Assert.Null(await _userRepository.LoadAsync(tenantId: null, EmployeeIdKey, _user.CustomIdentifiers[EmployeeIdKey])); - Assert.Null(await _userRepository.LoadAsync(_user.TenantId, "EmployeeNo", _user.CustomIdentifiers[EmployeeIdKey])); - Assert.Null(await _userRepository.LoadAsync(_user.TenantId, EmployeeIdKey, Guid.NewGuid().ToString())); - - UserAggregate? user = await _userRepository.LoadAsync(_user.TenantId, EmployeeIdKey, _user.CustomIdentifiers[EmployeeIdKey]); - Assert.NotNull(user); - Assert.Equal(_user, user); - } - - [Fact(DisplayName = "LoadAsync: it should load the user by identifier.")] - public async Task LoadAsync_it_should_load_the_user_by_identifier() - { - Assert.Null(await _userRepository.LoadAsync(UserId.NewId())); - - _user.Delete(); - long version = _user.Version; - - _user.Disable(); - await _userRepository.SaveAsync(_user); - - Assert.Null(await _userRepository.LoadAsync(_user.Id, version)); - - UserAggregate? user = await _userRepository.LoadAsync(_user.Id, version, includeDeleted: true); - Assert.NotNull(user); - Assert.False(user.IsDisabled); - Assert.Equal(_user, user); - } - - [Fact(DisplayName = "LoadAsync: it should load the user by role.")] - public async Task LoadAsync_it_should_load_the_user_by_role() - { - RoleAggregate admin = new(new UniqueNameUnit(_roleSettings.UniqueName, "admin"), _user.TenantId); - await _roleRepository.SaveAsync(admin); - - Assert.Empty(await _userRepository.LoadAsync(admin)); - - IEnumerable users = await _userRepository.LoadAsync(_role); - Assert.Equal(_user, users.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the user by session.")] - public async Task LoadAsync_it_should_load_the_user_by_session() - { - SessionAggregate session = _user.SignIn(); - - UserAggregate? user = await _userRepository.LoadAsync(session); - Assert.NotNull(user); - Assert.Equal(_user, user); - } - - [Fact(DisplayName = "LoadAsync: it should load the users by tenant identifier.")] - public async Task LoadAsync_it_should_load_the_users_by_tenant_identifier() - { - UserAggregate user = new(_user.UniqueName, tenantId: null); - UserAggregate deleted = new(new UniqueNameUnit(_userSettings.UniqueName, "deleted"), _user.TenantId); - deleted.Delete(); - await _userRepository.SaveAsync([user, deleted]); - - IEnumerable users = await _userRepository.LoadAsync(_user.TenantId); - Assert.Equal(_user, users.Single()); - } - - [Fact(DisplayName = "LoadAsync: it should load the user by unique name.")] - public async Task LoadAsync_it_should_load_the_user_by_unique_name() - { - Assert.Null(await _userRepository.LoadAsync(tenantId: null, _user.UniqueName)); - - UniqueNameUnit uniqueName = new(_userSettings.UniqueName, $"{_user.UniqueName.Value}2"); - Assert.Null(await _userRepository.LoadAsync(_user.TenantId, uniqueName)); - - UserAggregate? user = await _userRepository.LoadAsync(_user.TenantId, _user.UniqueName); - Assert.NotNull(user); - Assert.Equal(_user, user); - } - - [Fact(DisplayName = "LoadAsync: it should load the users by email address.")] - public async Task LoadAsync_it_should_load_the_users_by_email_address() - { - Assert.NotNull(_user.Email); - - Assert.Empty(await _userRepository.LoadAsync(tenantId: null, _user.Email)); - - EmailUnit email = new($"{_user.Email.Address}2"); - Assert.Empty(await _userRepository.LoadAsync(_user.TenantId, email)); - - IEnumerable users = await _userRepository.LoadAsync(_user.TenantId, _user.Email); - Assert.Equal(_user, users.Single()); - - UserAggregate other = new(new UniqueNameUnit(_userSettings.UniqueName, $"{_user.UniqueName.Value}2"), _user.TenantId); - other.SetEmail(_user.Email); - await _userRepository.SaveAsync(other); - - users = await _userRepository.LoadAsync(_user.TenantId, _user.Email); - Assert.Equal(2, users.Count()); - Assert.Contains(users, _user.Equals); - Assert.Contains(users, other.Equals); - } - - [Fact(DisplayName = "LoadAsync: it should load the users by identifiers.")] - public async Task LoadAsync_it_should_load_the_users_by_identifiers() - { - UserAggregate deleted = new(_user.UniqueName, tenantId: null); - deleted.Delete(); - await _userRepository.SaveAsync(deleted); - - IEnumerable users = await _userRepository.LoadAsync([_user.Id, deleted.Id, UserId.NewId()], includeDeleted: true); - Assert.Equal(2, users.Count()); - Assert.Contains(users, _user.Equals); - Assert.Contains(users, deleted.Equals); - } - - [Fact(DisplayName = "SaveAsync: it should save the deleted user.")] - public async Task SaveAsync_it_should_save_the_deleted_user() - { - _user.SetCustomAttribute("HealthInsuranceNumber", Faker.Person.BuildHealthInsuranceNumber()); - _user.SetCustomAttribute("JobTitle", "Sales Manager"); - _user.Update(); - await _userRepository.SaveAsync(_user); - - UserEntity? entity = await IdentityContext.Users.AsNoTracking() - .SingleOrDefaultAsync(x => x.AggregateId == _user.Id.Value); - Assert.NotNull(entity); - - CustomAttributeEntity[] customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) - .ToArrayAsync(); - Assert.Equal(_user.CustomAttributes.Count, customAttributes.Length); - foreach (KeyValuePair customAttribute in _user.CustomAttributes) - { - Assert.Contains(customAttributes, c => c.Key == customAttribute.Key && c.Value == customAttribute.Value); - } - - _user.Delete(); - await _userRepository.SaveAsync(_user); - - customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) - .ToArrayAsync(); - Assert.Empty(customAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified user.")] - public async Task SaveAsync_it_should_save_the_specified_user() - { - UserEntity? entity = await IdentityContext.Users.AsNoTracking() - .Include(x => x.Identifiers) - .Include(x => x.Roles) - .SingleOrDefaultAsync(x => x.AggregateId == _user.Id.Value); - Assert.NotNull(entity); - AssertUsers.AreEqual(_user, entity); - - ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() - .SingleOrDefaultAsync(x => x.Id == _user.Id.Value); - AssertUsers.AreEquivalent(entity, actor); - - Dictionary customAttributes = await IdentityContext.CustomAttributes.AsNoTracking() - .Where(x => x.EntityType == nameof(IdentityContext.Users) && x.EntityId == entity.UserId) - .ToDictionaryAsync(x => x.Key, x => x.Value); - Assert.Equal(_user.CustomAttributes, customAttributes); - - UserAggregate? user = await _userRepository.LoadAsync(_user.Id); - Assert.NotNull(user); - Assert.Equal(_user.FirstName, user.FirstName); - Assert.Equal(_user.MiddleName, user.MiddleName); - Assert.Equal(_user.LastName, user.LastName); - Assert.Equal(_user.Nickname, user.Nickname); - Assert.Equal(_user.Birthdate, user.Birthdate); - Assert.Equal(_user.Gender, user.Gender); - Assert.Equal(_user.Locale, user.Locale); - Assert.Equal(_user.TimeZone, user.TimeZone); - Assert.Equal(_user.Picture, user.Picture); - Assert.Equal(_user.Profile, user.Profile); - Assert.Equal(_user.Website, user.Website); - Assert.Equal(_user.CustomAttributes, user.CustomAttributes); - } - - [Fact(DisplayName = "SaveAsync: it should save the specified users.")] - public async Task SaveAsync_it_should_save_the_specified_users() - { - UserAggregate disabled = new(new UniqueNameUnit(_userSettings.UniqueName, "disabled")); - UserAggregate deleted = new(new UniqueNameUnit(_userSettings.UniqueName, "deleted")); - await _userRepository.SaveAsync([disabled, deleted]); - - Dictionary entities = await IdentityContext.Users.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(disabled.Id.Value)); - Assert.True(entities.ContainsKey(deleted.Id.Value)); - - disabled.Disable(); - deleted.Delete(); - await _userRepository.SaveAsync([disabled, deleted]); - - entities = await IdentityContext.Users.AsNoTracking().ToDictionaryAsync(x => x.AggregateId, x => x); - Assert.True(entities.ContainsKey(disabled.Id.Value)); - Assert.False(entities.ContainsKey(deleted.Id.Value)); - - AssertUsers.AreEqual(disabled, entities[disabled.Id.Value]); - - ActorEntity? actor = await IdentityContext.Actors.AsNoTracking() - .SingleOrDefaultAsync(x => x.Id == deleted.Id.Value); - Assert.NotNull(actor); - Assert.True(actor.IsDeleted); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); } diff --git a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Tokens/TokenBlacklistTests.cs b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Tokens/TokenBlacklistTests.cs index dc43d9c..7796863 100644 --- a/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Tokens/TokenBlacklistTests.cs +++ b/tests/Logitar.Identity.EFCore.SqlServer.IntegrationTests/Tokens/TokenBlacklistTests.cs @@ -1,142 +1,23 @@ using Logitar.Data; using Logitar.Data.SqlServer; -using Logitar.EventSourcing.EntityFrameworkCore.Relational; -using Logitar.Identity.Domain.Tokens; -using Logitar.Identity.EntityFrameworkCore.Relational; -using Logitar.Identity.EntityFrameworkCore.Relational.Entities; -using Microsoft.EntityFrameworkCore; +using Logitar.Identity.EntityFrameworkCore.Relational.Tokens; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace Logitar.Identity.EntityFrameworkCore.SqlServer.Tokens; [Trait(Traits.Category, Categories.Integration)] -public class TokenBlacklistTests : IAsyncLifetime +public class TokenBlacklistTests : TokenBlacklistTestsBase, IAsyncLifetime { - private readonly EventContext _eventContext; - private readonly IdentityContext _identityContext; - private readonly IServiceProvider _serviceProvider; - private readonly ITokenBlacklist _tokenBlacklist; - - public TokenBlacklistTests() - { - IConfiguration configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false) - .Build(); - - string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty) - .Replace("{Database}", nameof(TokenBlacklistTests)); - - _serviceProvider = new ServiceCollection() - .AddSingleton(configuration) - .AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString) - .BuildServiceProvider(); - - _eventContext = _serviceProvider.GetRequiredService(); - _identityContext = _serviceProvider.GetRequiredService(); - _tokenBlacklist = _serviceProvider.GetRequiredService(); - } - - public async Task InitializeAsync() + public TokenBlacklistTests() : base() { - await _eventContext.Database.MigrateAsync(); - await _identityContext.Database.MigrateAsync(); - - TableId[] tables = [IdentityDb.TokenBlacklist.Table]; - foreach (TableId table in tables) - { - ICommand command = SqlServerDeleteBuilder.From(table).Build(); - await _identityContext.Database.ExecuteSqlRawAsync(command.Text, command.Parameters.ToArray()); - } } - [Fact(DisplayName = "BlacklistAsync: it should blacklist identifiers with expiration.")] - public async Task BlacklistAsync_it_should_blacklist_identifiers_with_expiration() + protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - string duplicate = Guid.NewGuid().ToString(); - string[] tokenIds = [Guid.NewGuid().ToString(), duplicate, duplicate]; - DateTime expiresOn = DateTime.UtcNow.AddHours(1); - - await _tokenBlacklist.BlacklistAsync(tokenIds, expiresOn); - Dictionary entities = await _identityContext.TokenBlacklist.AsNoTracking() - .ToDictionaryAsync(x => x.TokenId, x => x); - Assert.Equal(2, entities.Count); - foreach (string tokenId in tokenIds) - { - Assert.True(entities.ContainsKey(tokenId)); - Assert.Equal(expiresOn, entities[tokenId].ExpiresOn); - } - } - - [Fact(DisplayName = "BlacklistAsync: it should blacklist identifiers without expiration.")] - public async Task BlacklistAsync_it_should_blacklist_identifiers_without_expiration() - { - string duplicate = Guid.NewGuid().ToString(); - string[] tokenIds = [Guid.NewGuid().ToString(), duplicate, duplicate]; - Dictionary entities; - - await _tokenBlacklist.BlacklistAsync(tokenIds); - entities = await _identityContext.TokenBlacklist.AsNoTracking().ToDictionaryAsync(x => x.TokenId, x => x); - foreach (string tokenId in tokenIds) - { - Assert.True(entities.ContainsKey(tokenId)); - Assert.Null(entities[tokenId].ExpiresOn); - } - - await _tokenBlacklist.BlacklistAsync(tokenIds, expiresOn: null); - entities = await _identityContext.TokenBlacklist.AsNoTracking().ToDictionaryAsync(x => x.TokenId, x => x); - foreach (string tokenId in tokenIds) - { - Assert.True(entities.ContainsKey(tokenId)); - Assert.Null(entities[tokenId].ExpiresOn); - } - } - - [Fact(DisplayName = "GetBlacklistedAsync: it should return empty when no ID is blacklisted.")] - public async Task GetBlacklistedAsync_it_should_return_empty_when_no_Id_is_blacklisted() - { - string[] tokenIds = [Guid.NewGuid().ToString(), Guid.NewGuid().ToString()]; - IEnumerable blacklistedIds = await _tokenBlacklist.GetBlacklistedAsync(tokenIds); - Assert.Empty(blacklistedIds); - } - - [Fact(DisplayName = "GetBlacklistedAsync: it should return only the blacklisted IDs.")] - public async Task GetBlacklistedAsync_it_should_return_only_the_blacklisted_Ids() - { - string blacklistedId = Guid.NewGuid().ToString(); - string otherId = Guid.NewGuid().ToString(); - - BlacklistedTokenEntity entity = new(blacklistedId); - _identityContext.TokenBlacklist.Add(entity); - await _identityContext.SaveChangesAsync(); - - string[] tokenIds = [blacklistedId, otherId]; - IEnumerable blacklistedIds = await _tokenBlacklist.GetBlacklistedAsync(tokenIds); - Assert.Equal([blacklistedId], blacklistedIds); - } - - [Fact(DisplayName = "PurgeAsync: it should remove only expired items.")] - public async Task PurgeAsync_it_should_remove_only_expired_items() - { - BlacklistedTokenEntity expired = new("expired") - { - ExpiresOn = DateTime.Now.AddDays(-1) - }; - BlacklistedTokenEntity notExpired = new("notExpired") - { - ExpiresOn = DateTime.Now.AddDays(1) - }; - BlacklistedTokenEntity noExpiration = new("noExpiration"); - _identityContext.TokenBlacklist.AddRange(expired, notExpired, noExpiration); - await _identityContext.SaveChangesAsync(); - - await _tokenBlacklist.PurgeAsync(); - - HashSet entities = [.. (await _identityContext.TokenBlacklist.AsNoTracking().Select(x => x.TokenId).ToArrayAsync())]; - Assert.Equal(2, entities.Count); - Assert.Contains(notExpired.TokenId, entities); - Assert.Contains(noExpiration.TokenId, entities); + string connectionString = (configuration.GetValue("SQLCONNSTR_Identity") ?? string.Empty).Replace("{Database}", GetType().Name); + services.AddLogitarIdentityWithEntityFrameworkCoreSqlServer(connectionString); } - public Task DisposeAsync() => Task.CompletedTask; + protected override IDeleteBuilder CreateDeleteBuilder(TableId table) => SqlServerDeleteBuilder.From(table); }