From 3bb25bd77fc46e3cb1b81fab1b8e23c397bd4d6a Mon Sep 17 00:00:00 2001 From: Francis Pion Date: Mon, 4 Mar 2024 22:38:59 -0500 Subject: [PATCH] Created a PostgreSQL project. (#56) * Created a PostgreSQL project. * Deleted existing migrations. * Completed migrations and integration tests. --- Identity.sln | 22 +- docker-compose.yml | 13 +- src/Logitar.Identity.Demo/DatabaseProvider.cs | 7 + .../DatabaseProviderNotSupportedException.cs | 15 + .../Logitar.Identity.Demo.csproj | 9 + .../Logitar.Identity.Demo.http | 6 - src/Logitar.Identity.Demo/Startup.cs | 20 +- .../appsettings.Development.json | 1 + .../secrets.example.json | 3 + .../DependencyInjectionExtensions.cs | 20 + .../LICENSE | 21 + ...tity.EntityFrameworkCore.PostgreSQL.csproj | 62 ++ ...5022651_LogitarIdentity_1_0_0.Designer.cs} | 296 +++--- .../20240305022651_LogitarIdentity_1_0_0.cs | 882 +++++++++++++++++ .../IdentityContextModelSnapshot.cs} | 356 ++++--- .../PostgresHelper.cs | 10 + .../README.md | 31 + .../logitar.png | Bin 0 -> 21718 bytes .../Entities/UserEntity.cs | 4 +- ...0240105181804_InitialMigration.Designer.cs | 189 ---- .../20240105181804_InitialMigration.cs | 173 ---- ...5224604_AddUserPasswordColumns.Designer.cs | 209 ---- .../20240105224604_AddUserPasswordColumns.cs | 89 -- ...230509_AddSessionSecretColumns.Designer.cs | 218 ----- .../20240105230509_AddSessionSecretColumns.cs | 49 - ...0240106003527_CreateActorTable.Designer.cs | 268 ----- .../20240106003527_CreateActorTable.cs | 65 -- ...20240106175723_AddedUserClaims.Designer.cs | 376 ------- .../20240106175723_AddedUserClaims.cs | 389 -------- ...6184348_AddedSessionSigningOut.Designer.cs | 387 -------- .../20240106184348_AddedSessionSigningOut.cs | 58 -- ...34_AddedCustomAttributeColumns.Designer.cs | 395 -------- ...40110223034_AddedCustomAttributeColumns.cs | 38 - ...0110234318_AddUserPhoneColumns.Designer.cs | 435 -------- .../20240110234318_AddUserPhoneColumns.cs | 158 --- ...11000426_AddUserAddressColumns.Designer.cs | 487 --------- .../20240111000426_AddUserAddressColumns.cs | 198 ---- ...330_CreateCustomAttributeTable.Designer.cs | 531 ---------- ...240111021330_CreateCustomAttributeTable.cs | 59 -- ...20240111040937_CreateRoleTable.Designer.cs | 670 ------------- .../20240111040937_CreateRoleTable.cs | 147 --- ...0111044308_CreateUserRoleTable.Designer.cs | 700 ------------- .../20240111044308_CreateUserRoleTable.cs | 50 - ...40111164057_CreateApiKeyTables.Designer.cs | 815 --------------- .../20240111164057_CreateApiKeyTables.cs | 130 --- ...55_AlterUserPhoneColumnLengths.Designer.cs | 815 --------------- ...40112010955_AlterUserPhoneColumnLengths.cs | 62 -- ...0240121052425_CreateTokenBlacklistTable.cs | 47 - ...240122000544_CreateOneTimePasswordTable.cs | 103 -- ...05022614_LogitarIdentity_1_0_0.Designer.cs | 925 ++++++++++++++++++ .../20240305022614_LogitarIdentity_1_0_0.cs | 884 +++++++++++++++++ .../IdentityContextModelSnapshot.cs | 1 - ....EFCore.PostgreSQL.IntegrationTests.csproj | 53 + .../Repositories/ApiKeyRepositoryTests.cs | 23 + .../OneTimePasswordRepositoryTests.cs | 23 + .../Repositories/RoleRepositoryTests.cs | 23 + .../Repositories/SessionRepositoryTests.cs | 23 + .../Repositories/UserRepositoryTests.cs | 23 + .../Tokens/TokenBlacklistTests.cs | 23 + .../appsettings.json | 3 + .../AssertApiKeys.cs | 11 +- .../AssertOneTimePasswords.cs | 8 +- .../AssertRoles.cs | 6 +- .../AssertSessions.cs | 6 +- .../AssertUsers.cs | 11 +- .../Assertions.cs | 8 +- ....EFCore.Relational.IntegrationTests.csproj | 44 + .../Repositories/ApiKeyRepositoryTestsBase.cs | 233 +++++ .../OneTimePasswordRepositoryTestsBase.cs | 183 ++++ .../Repositories/RepositoryTests.cs | 19 +- .../Repositories/RoleRepositoryTestsBase.cs | 245 +++++ .../SessionRepositoryTestsBase.cs | 225 +++++ .../Repositories/UserRepositoryTestsBase.cs | 319 ++++++ .../Tokens/TokenBlacklistTestsBase.cs | 138 +++ ...y.EFCore.SqlServer.IntegrationTests.csproj | 3 +- .../Repositories/ApiKeyRepositoryTests.cs | 227 +---- .../OneTimePasswordRepositoryTests.cs | 177 +--- .../Repositories/RoleRepositoryTests.cs | 239 +---- .../Repositories/SessionRepositoryTests.cs | 220 +---- .../Repositories/UserRepositoryTests.cs | 313 +----- .../Tokens/TokenBlacklistTests.cs | 133 +-- 81 files changed, 4943 insertions(+), 9917 deletions(-) create mode 100644 src/Logitar.Identity.Demo/DatabaseProvider.cs create mode 100644 src/Logitar.Identity.Demo/DatabaseProviderNotSupportedException.cs delete mode 100644 src/Logitar.Identity.Demo/Logitar.Identity.Demo.http create mode 100644 src/Logitar.Identity.Demo/secrets.example.json create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/DependencyInjectionExtensions.cs create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/LICENSE create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Logitar.Identity.EntityFrameworkCore.PostgreSQL.csproj rename src/{Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.Designer.cs => Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.Designer.cs} (72%) create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/20240305022651_LogitarIdentity_1_0_0.cs rename src/{Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.Designer.cs => Logitar.Identity.EntityFrameworkCore.PostgreSQL/Migrations/IdentityContextModelSnapshot.cs} (65%) create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/PostgresHelper.cs create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/README.md create mode 100644 src/Logitar.Identity.EntityFrameworkCore.PostgreSQL/logitar.png delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105181804_InitialMigration.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105224604_AddUserPasswordColumns.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240105230509_AddSessionSecretColumns.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106003527_CreateActorTable.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106175723_AddedUserClaims.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240106184348_AddedSessionSigningOut.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110223034_AddedCustomAttributeColumns.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240110234318_AddUserPhoneColumns.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111000426_AddUserAddressColumns.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111021330_CreateCustomAttributeTable.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111040937_CreateRoleTable.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111044308_CreateUserRoleTable.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240111164057_CreateApiKeyTables.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.Designer.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240112010955_AlterUserPhoneColumnLengths.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240121052425_CreateTokenBlacklistTable.cs delete mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240122000544_CreateOneTimePasswordTable.cs create mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.Designer.cs create mode 100644 src/Logitar.Identity.EntityFrameworkCore.SqlServer/Migrations/20240305022614_LogitarIdentity_1_0_0.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests.csproj create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/ApiKeyRepositoryTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/OneTimePasswordRepositoryTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/RoleRepositoryTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/SessionRepositoryTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Repositories/UserRepositoryTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/Tokens/TokenBlacklistTests.cs create mode 100644 tests/Logitar.Identity.EFCore.PostgreSQL.IntegrationTests/appsettings.json rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/AssertApiKeys.cs (83%) rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/AssertOneTimePasswords.cs (89%) rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/AssertRoles.cs (91%) rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/AssertSessions.cs (93%) rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/AssertUsers.cs (95%) rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/Assertions.cs (70%) create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Logitar.Identity.EFCore.Relational.IntegrationTests.csproj create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/ApiKeyRepositoryTestsBase.cs create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/OneTimePasswordRepositoryTestsBase.cs rename tests/{Logitar.Identity.EFCore.SqlServer.IntegrationTests => Logitar.Identity.EFCore.Relational.IntegrationTests}/Repositories/RepositoryTests.cs (62%) create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/RoleRepositoryTestsBase.cs create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/SessionRepositoryTestsBase.cs create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Repositories/UserRepositoryTestsBase.cs create mode 100644 tests/Logitar.Identity.EFCore.Relational.IntegrationTests/Tokens/TokenBlacklistTestsBase.cs 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 0000000000000000000000000000000000000000..5b031f488834788deaef9120d1a5695503601c98 GIT binary patch literal 21718 zcmXtg1z42N7w)$UOLsR2{OAs8SsIm;7LgVa1%yQ!7Laa`mhO;7kVd4tL^`FrbGe`Y zdoRz!v+Oc6-^`ga=bSm`eK%A~Lj@m)1_uBD{HLmlF8}}v{s{%JFu<2Hx5*pu1>ITx zsV)}y2 zXwB!~WRrFvO#=W-z*9vzUAM1$3$6_&dMUC;hfSBZ_3UCTi=UZQkyLm>ta4pJAI=Ib zRV`Qyi+&cZ8N%ZNwu&t2V>Tkls8ub>0>b_f{RqwS6X^&c!g}=R{=%t$@$fL3^h?}& zhUdtl=Qr=+%TsCToQ=KnAzsfG&wV{~MKYut!>LYg z$pT?i08p$3*>04HEAb>dSKnnC)(?4LMK>0N87oyQO>l;8T^j;K)CIJ%BBVR5XB7_b?Q67oI6x-XF@nUMlhV_!#H9>L|Q?`&IB4RY)-&YXanj3!DpIHA_3wuU|Q2 zkuZzi&zf<-A4QDw73?$EhPM?ZDlGh1vokuytG0Zd%+_KjEjFMECQ0y`$OYky3* z5`4N*hnom58`fF~NY6p;iIG#utzP)ykeqC=y(DzO>v*@$uo>?fY~P!&zA3>&%%n$X z`?fq^$)TFJ#T|%*c`IdV#SmPi+qQ=;4fEv zG{S()V{g^x^WNJ1dqlew=9I|7Ngo>?!dw0HM;8a)g*`zWb5Aig)BHfq{66TtENko@7w|3UK*YUE!aO1k@lq<_zm5Ob+8i8R zZrb$f5$}36$C;+z(0!{o+*>%$eXv8}6NfxbZv}8)Qp@|005&!Ur=q7W_WF!(XtUMt z)spUnQIs08TRT5$DbkD3$Kz2K8j+XWY~qrwB#ySBA)uu}MS6ogk^iDda($!K22aM+N6)x3aU;EVBINWvg%i6J0&LGwMUkPm8XS{Sg)a5_cxOX;c6<`vz^31*q3tI zhsXQ79u?bk3QnXkRXTpU>D#Qj!e?`Tq_$avF7N!oceJ32vm#F0G)6lXU3$;eMboWS zizRy-ijke6K4d>`mv?7`gqsEsL?u2v00*M+I!ElS@6tndOwEJU*C6ef-=WJD7}RGX zbnZ!N#uvzKCf$WAi+K5bT0U`8&!&Uw)>GdLZ{J}YYEbr3$h!t_|QlI)3@ zx3aa&%v(Ss)9plG>c|MCbaG;XMZy5svrNO(F|>mKsx7IGe^Q=^`8e^Tl(DO$B4*mP zuWH7ALaxZ863A-b+KASi@QcFlC9F*abp;_~wI@=3SSW5pI9A_(wx>7CNsFA4hU!-6Pv5N1L~;|MrU%aUGSxA&-PTNExN_3?o|xQv90Vq5 z{+mgGV2t)!JL4_aMlH~{2CW*PT zj^niW_ym}Y&jK_B1dm4fK zvH64g*RpKiA6JO|!&@b3$%m@FJG(&I(MuyC_zo-6y;FOYujnrBB-)A2!o`o3R?KXg zHxH3t%d%+sWwe_-d?>@QeIs)v_DrAqAC#q6!QU~&cwqy#g$>dwxVneqAB=8YS6I2h zEq=6J5KUJRV6v+zjkXI~`PZ{LZ)uqA-4~+I*m(Gb&E4^IasM zCJxWE2+Mdc1koW%wdIo!8jJXGsfW+^&ZL}Hfjtlh1H`@rK76BgoB{p2j+a)w_rXMgWsLXL z&o3FE6Y(m(V7TIci>^>YPOQ4inw8y!AgX?P@|Ni%8MF6y&L{X}DCmGIu`b6VyKv%? zy(HEQ=vD61|EGO54;ojk_p+4pt4RbZJI@1=QrNKztF@H94uDswCN(zT~ay@Y?-Y(pCI*?m`{dGQ05VC%mj*TKL(;SWJhUQ)H;YIlW_ zi7^gSQF{NunhW+XIoZ4XS9uq%J`!QplL->yYi)cK&ntTMSAhc&CU+kBrJ0dKz=;-E z@BCnsr#PIjJzy_LA24VR(dtB;=AYKOK6oEXEJVknIGExfaXo1Ey_?Ec-f$n2?IQDA zJb9Pa!QLlUl2|Dn&@AQcPDZ<_jC;)UgqVMDPnGO z(LoYjDLPtDR9Vb>-EDu@iwd+#s};rMLR{;vwTdJ0&=)m;tC#BZ<#SpLcTa^zRLJ?y zj~cPI26saUqOhp@bO5F-y1QkzbZ9Yl%|7wc((b<#v!Mpc;UsfM8J@hzU;1d*rJo}`}t}x&I z*jw7K1v5hXYiOXn8^pU`;!5f)MJsLcYix&@GS87^0w-xiSFvqzzzb(c)w|H;s-vc) z6au-GH7t0-1U@D2XlvB1h2Yte5W!mpJ4uYOm8ZBd8KigJa;e<(FRezR{FI6^x=o;^ zv?@SJ^1I(-UJuc0qt`467^&Z0v8bOB&bk~SIx@^ExNVtSo^312NwF^Xs=p%FS}+83 zYtEbO<$Xp`ul3M{JcPuVl&Z1<^2wn-DwWeNsn1H$-e1dT4R-%ocz7p?5!e%#DT0&w z#BHT7b$1q6s(T>bqDVQV8Vb*At&-ui|-8Z_M<|JLzB z_MyfQfdcOWKQB>aDmd$6&_&^n*N+A3YIoWR&b3-P5Lh^vxJa%%TD}`9CvP3~O^)D* zjCOoqj#gd2yEpA~40|r|J&i$F$K#M1qk^?d0 zE|}AIr#&$x@E!E_bc*@&TC8;x(XjpJ&U*6J;kXndyF^Z{zgJs&A8@1`BEemNQp*tU z-4(xEXT-iRG=EC>mF#WThZ_#@pV)qSL9R<&IfN$j1wV$r9Z7Q^P^nCc& znlhw*hzO20vxx_eq!Gwl(47$EpyB~aK5saQr3`B&D&oAQvzCNuH%wxl&;t1Hdf<>3>~obC z-F_9Og7p6W=68jmT!m@;K8#NHRc_gQLzW%I?7F0&NPeTG5^i{Ckj99!CEMxAA8{=t zdZ%ww=}J%ldT`8}Hgib@qd3m2))`Qxx3+*7Um_&s;5msfP%jF$S41i38TIwh;Ubek z1$~XYL*C!sqs1g1BabrVM7s|$oaBa9DVf|YY(uk*3N7Xm9E9loxjLat8zQntN)y!m zas7Y`g_;GkPzM;v)MGgF7Nf=WU^;&bbL!QjgN1;uQLuoP4@GtoP?fCB&b!v``k*_3 z6AeMNnw9_6fY7a>`4*bpCOC-E`zuGm;1Ravmo){#U;fj>w7NRetkdwjD;RG^GUaI? zkBuAp^-7E`SOl%_l*VJX8c*YTUD`S>|B4c&Lsf}Oq9vl{Bi*?VDE(50--g*Y9|`Sm zhbUEW4RvSghU{epj-Rxj*%mdNCVDWr>)Kj%d?l??UxX}UvMD6z;dC%kWFFi)Q7A@} ztIB)7cm4GsD#Y8C_+yDLdDu<-cU0d_s*;02f&(Bv|06j%e3jy=LGN{)&~k3W-sZ#c z{5|MO1n94NNo;%ba@7i%s-J^?*vl56d|~E@pXCjCW%mok`eDG-TnLFh+v+H}oRQo9 z0tjyE`#?VBn;@)zFY@!Pbxk!edZCo5-|L&z?DYh>6w*J$QQ*sJv-sk?P;a|Cd@)}J zQ$KB3o4__5UF4TVDpb4nMIm4h7+c)Z!w;epObeN-;j@X~1nHO&ji1cvy)Nl7rS7M5 zn$79RV>Jiv$RDWf8&_(|!KZYElNn0<)O6*t3S1Mf?`@V+drD!UrNxSGwSlIp@AK`BtzFnnIeJ+|$opDq2!@qZ?tRJawIpkh6%L{9BaIAO zexK5Ia_bjdiqvy`(_&+*93K#kmQ2_F_j|}H1?yjm>q2r!#-MqkedF2R*%nuN3xRt% z3yB2Q+BGHf3fAaO6 z(epYV?h!7(^sBTZF?(l*t?R#a2U&I__rg|c>31;oO1g3q-bwR$bNV^L>8<(ljW_~D zg!z{4gCs0=;cfw0pIcj2LGl8Vbq@J6-tQL;1k?XH@ajDmoCvYt{`Bm!S&3f8z`L2+ zUlBRdM;cpdioU#&#b?M_n&@!FWfSN)!-}jg&XpbSI4Eqn=rWxa4cEZSP9NQFjMk7Z zcPQVcv$mzO?(Fza@q+t3M8x3QWj>dvclUEFiBXAEjpY!GO2VXOOR>WHc-p1%*4E`r z1y~FsVuN{;&B)0tWyPeNYZ8tPbgYSM2;3@$12IcXVsScfUW|4xoDxn z^1?@7ntxj%6~^jtqmK`aPuxE&RjYe%QbKv4F`?4I%b`Vc(j=ug0P&Bx_kbGt*ua!4 zABMV9P)_{wpA#hS)rDICD-kJZ{pew*ptOHh^$ zU_Y?;qvUr&(Jb%2M|(oRLGxM;A(boM&45Qi398$;X6vPiYeq+kDAFEvC4zTB%eyd>RofR`lVIA8?Y)pm=tn# zNrFEym+Wy4?N>sKq-qc$+r=_R7Y)Amw;Jtqsmo%a<4`3Eyzfo6_AmhdbfSBu2{b!GyBSL%txKxCLZ(+}Nsw-v{ z{rb^MUa|+#oyRK50GNyHIFf=?jMERMj~53N6g?dD&b{}&U#hl#~-Fa|)2@i@3sA>(MP z5Mj(BiG$9EcC1skR=GVJj;K{q$!#UZ=c;^0_Yher=U++V% zU`W#~??VRst3&;c7r@G4Yz4}1bk5D*`Fh@6`@5J$6z(LoiL07!dRR2t0lKb;VOp~N zQIVMpZF@zIon}s>N(E^bFVZ>KxtpGzxQ@EvPcxJ%3}rs{+}m`Rxa$Q#`tz-VZgjk` zz6?!wovAA0a6#>E7350kR>hV^S?(o!iiVtS`nWSt_|y9Q$1S9dJ6XDO!tZrDM@{uL z2hBv?^C$z;2a@r>Qo5D1#Pdw2`sIYhk*YIGKfXNGFg>SqMfGbwFK|!2Iw61`q7$t* z6`pImpaA4ud31NqDJGMPdI1ZOUIqLU=2!h|QRO!xG&yrLh8y4hK(~Sbek1fVjpM)c zakd%D!=~;&bqEw3&lG~EwBgePEcXCDWtU(%BJcKf;8)x&Z1Pw7Fb{V)@qpbZcLuGs zCkva#_7Nj9PVf@`)h)zku(u*M8J(>Div~kP>edW!5LPA;J5sV*NdEdSvEO2Z|7Dxg z#tsg<#h=o5ufb;=8hfSk8*+_yA@S^TLZGHDlx269mDMdpE#rF+bj?%|z@(UbH-lJ(=pZ40#!{rum7othrKO(l;we86Z%a zqtw8hcP6{hfWKK|G>x{0p+-K=KYVeocZiZqdKe8pl=B@a&9!&^qsSB=1)Dc4(`5~- z2U8r^asB0jSDtW8|2|`GAb))4cEH7}l2aFh0)iODPWSOK-_KY7pW`+>T7DPb+lO&O3Z9N>qjRHq*di zFxM6Bthei`H!kDf?{rD=(U9+ccO2HM$&Ei}32YH^t&9DS_`5m8jC#Rqacp+sK6yJb zdf*Z78giqmz>;VxYBDrG9;MuW2y?RY9}td6)E<56r1mK~w0nEh;yB|+0og)ySN16; zU`3^vZhG(%_4B_rjh)BOWet(_|43w;pZj1v^)2Q zxn=jNs|>8*htR>JPx=?`h1f(axvrMSA{ruN0`xC=B-2v0d)o#OpR4nK+%m=z&zfGh zq7E9&s_~Ngy@c^6vMYhg5RWcjq4aDX4XA1X7!sD4BxD?HCUXJp&~|1X;QfoiE=$b? zHJJwgFTG4{Kc^4}RJyg9?Y&h%B^EC5d@F!51FwQAyfcMW&qfle{Q+G4{I&7B4ih{Go^Dd%oZ90eHq zyE@@+bzUzUuV|2;b$gO<@kax*kGq3_P5oe6p^r-hS*KK*kSZFd<<`dauK`|7NV}1Z9f- zfB<^$i<@?2`(rFLQf*O560KkQntfaS}7DUZ{UAp}aEejRo29DG$Z&tr30 zA9k&I47aAibx%QXjmX;{G+?fEzTo~gQzSi?=U=8Zg8si}ihtv70+f)1SNA~BaTpT~ zj;XQro9`2dn3vthuO?o3hi_y3C5Zxvx&kiHP<{cPFvIC7f19W-3Wl_8mF)rb z;}{*zj1wlVk`kr0YY0#kj9RMMaM0oc;DQD92gvZ#eS!a#2F>p1*LaP5#Zd#~x~l4?X#}(&{W8{~rqw z!&ut})hJ*hjRy0AAtjOh{8ru7V$_jGr(*f{8;K*hj@ZD2O2z?2Z=qF3m~rk~o;U;G z^=*zrQNOyt(lr|VrQ(xf`h$w|gG*5=^_-VBwf9cPc;M~@6paxBEjH%4kL&N0k(%vZ zn}h%(#Ed2!#hEYd`!6b4+y5!Z6m??8vUPNVcOEx3X_*|MVevj95#(u^yW2 zAk>+SbtKs0aNK2HPx=m$)n+QL@yHabCNivuZ&EaT(M&*2n$5iNIOM5fm5xJ+`3KW8 zHsDZX3ZE~*-|5QAOWN*e8`nAA@N9Xx$3@89xMY(p^Di8kN3(2+z$D} zA9tKCk-ouQi2{HM!qXdwd-}WIYJ`O}(NHD^&QK1Y2r}TNC6Es}o%+^Od{U)|W%7}$ z*Eq$&IhuAfCQ5Qxb$}*59%%?6(iR^a44?`A2nZ?9GEk&2Y)mQe0T$z(f5Uwy)pr`p zs$5Mw*?52u4zlu{%bZN>S4kl%OROaChAV?xGx4r(#{~(N$4G7PN`C^(nn|7e$+}#{`b>0ph^!)5t+IBGXp$ zoP`rx_B=PwWZutGP)9J1V!lEof6$eO)%V?zw~3Csv2`rCgoKd5ST5z=|Au*zH*_k_ z{Uz#Uw_4oMV$4$T{lR@|fU1X@;x(nO#G6X3raP2f=a5Cz$-F;K=2uV@{GvwPL@All zN{A+KO5}!Kaso4|Jdpyowr`IQ3=jqs5!hs!Dr1X8H@YA5$uivI2aRRSc$7#aEI$zH zy!y_~ltb13d`x#j=yKSnPoz!Tuhgt3uYDhCw4PD5S_A6UcDl)-QL5a#Wgf=ilpIO? zn75y>$>?>>3UjYma85`ioV!|8XJw!ZcgMD~b*G#Y68+;~DaYbXDLQkB6I#j}36zdZ zf#udAWmG`CTNA%W2@s!6GWG;A`;B>y{_2v+)V2Pr`+%9qzLQ72VB<0ATHWUM0+`Rr zx5cxXbOYUL5zX~WcHx>>7mqW-SIZxs;r|a}M{$U3Q!cHb0ihY9s9>1a{EuLG%HP)zZ-iH$f9LV^+SKIzx0l0h9rU ze$@cgi*m|8=TxI}p_D@@j<3uHb;`(J@DS@bscE7^sO6{juqvABlj(9PlL&~WL zRvsXty6v?1-3w&)X=QLA3!w75j`mO0-=n~|Lx^WRMCR6Sn;q@xZQEaEG7P^DX~k%`8rQ<1sT00R<2|JqOvldhVXf8qm`IJu<)W zmB*7MZto8SbJw!LH~AIrrYcuIIIPBPCFMZqgjw7gA}vab;*();!IMhofg}B=>o-W5 z?2IF7P0vigsnd|U^d%Sc^;s&?LP>x_KA;O+z5R;m$dTUktn+v0R8;`| zwDYx+*+bNdZ+Q$_<0X1#a87RHG~)A1Fh*b^4jmzsl`5m$r8d9c@Pubh6Tqs9*$?zd!v*Y*>e`Hy3Tzq+5J{Q-9r!-?1*Op zG5gZJX|(DbmiI@e61_-5Tec^^Zpq!JsJ|qnpa*`YeaPUGK6pmyq(Jblgx`J_ejvk zzNpZeQ&G8ak(auV_BFO5)xEQ#4??s?gD$fI`Ig?2I6Xsua zb^*&Q%qP5CQa^N>cG@H z6)0bko&{Ubk2TBhFQ_@+=lA)LX$E?2i^x^SFAM%(FW>p=V|_AsCTMo?670?`HGgO# zTgZID!0mSxATSh*sjk9d97ztmx-o=>-7&m;{so3K|M%n`akG8_-!gJMip{T&=1 z(G%YPk`_{AC$B_%ALH&4SwK3PEn^`GfZ?VBGj;SrCC-o8m)Of}enD&#oNx1XjGrwj zR7dY%Ob~~_kmSEy{$;5t&h6}(vuf4M*hy6ENrc|zZQ^Qe{hE0z2?a+95WfV2h3`MJ zw$aD_0TL#V=;6pej`3if9!OG2Hyk*YfSN%lfX9wHvO@IPuTm?%g(3l@E{%{6#;7>X zS5h-!2#tyY8(4I)oiN`zl5V)F*(Unclp=a}yOg9-W%gkCrT`*j-?&Y-arGpIn;x^w zvp(TUB%jqDf+-d%bdEgYSf;uPujQ2mD-x?8+b>k}zULZ> z_ah=6P2C*0ML9dV08COSp_3th8Wl8NFBN=%YLD|?m?V^JRD|u1G#THRY;qL*KQEXW z_Qx0h3*~o`^wEfjBR}`w7qDo7co*Y_6ViW5j;0^-HcuRChTjSmS3NWmC&spc{$f;g zJ&ZruXv*;(RF8OoeANg%G?wL8a7H6)ZDY$>+3lz$MUlAV-hh$F*t|H}j#UieQ=ja& zWxmfv$58m8_hnVA0_`?o#h&RCJHYYQ5c|gclk5%DRh&%1_p`jM{TJF|U z9}GjsLVD3aB#w4nf!)$Q&iTD2_YoUFjfKql>0o+d5Qu6&{%X9g=X%FmBK^Ji2NXWH z^c%g{GpWQ2zA{1yM^f(FCqdRtb&m-ghE^-YPovt@Sfze$FLo}oi9rJ@a9Yxzk)I$< z(Z8nN9zV)?7J}jndjr<4+ujT$OQ-}f9zjtsttN!QCJxw+=G4Br0FPDz41PcL`gWC3e0Axw`%;tUdY5LuRNSyL$eXBqE4iz$ZqCrN>oEwj^K zQwKeM-kOnnHKAmV^LJ*aT817~t`?<(GQOYNME;K5QnV?+WXq0(qC;2p|8LTt!KN+( zJ{1XU$vhWUU0=-3c~0&|4}H0v6;=v-ehKuJ?RwnH@-0N)W!>YZIUkF+$As`?k28GQ zG<~OBfww$!K}G%wMrm-fAMVS`RiBlNiv8;TTyH<{wdeo6%s}uNG zXNT^FG$BEt=E& zYX`hhn!MW@H5PZj;}Q?;P3+T^$MgVGhdFM4qKXX^KLT1;ms@d0B`2c1JOAs37|N;N zZ9LtR9rz2g&;hm>DOx6tYp$M4{%JAM^TAvG0OZ{JmmUx{VaJw5>)upV&S5K-JFEw< z5NYF&Wrlu!qKpeC_`KA8$_i;#*Yhb0SZHby4R@HV3*S`yYW}Ot2bSg9Rso5;zAWwk zv9qGP_MGCCSe$TK*VB8$vCCqP*^-dMBm&HS5fB`vs2`uHG7(h+5xCG2dP%lfyebW@ zEK~99%~?S!H+bQ&;TqK{qlb*%QuxAYaWsqiT>uTybjt19-WHkjD8;u2&H@=Vv~5$S_Wb)gyY^?Th93FggQ_7}61zFmkI zg{prQoc}g)j|3+qGM+0{;Chl~QN~$q6#mO1zJ~Okx|uOc;&l)*f3Qb|F%~V)X@8d> zgFMOJe-5Gxz`U;>umzS>aPD)q=|-|~uET0N+eA(h=`Twf-cJ^xiPm{PCQhgTSbZs6 zay5LWyKuZ%c0NTbW}E)@Ong~qKU)F?c6j6w1L9G?FwZuj>6?6p$4@0ZUDgLqtS;&^ z;9R6PB?0g=*Axx7;-{PZTJHju9p%4+OXLeMZdpEp4YUSa3>%CmD%>OiHfaRMuk^`* zk`s?kVg|}C@>TPo8nY>5tB#Ue^`KZ?$()oLaxMy_yxx8ci0sxXMrfkKdYcpM(qY_7 zJPdEJD)HLa*iJdj8lycKni3&6vv`B-yE@CaQT$?S5#(+4JLnwKZ6wTx;hih+*=c<0 z1Q3rAvL}dj9!UX=NV;W>=#^YagVly-OJmM3H%jE&X#w0finEJEU=;?*+&}b}k*w?5 zANBOWKjHb`1nz^n5-`)r?tS|)Z}(H`uy!Jf?^m|gqnx6xhrYr0h1+B!|3MQB${VIl zDxHeO7sa(@Xk$!SO7hjhyjb_Y^py|;GC1DU5Iu6@G-q#$os56;Vtn8kLhz? zIdzw)fLp;IpZ+=xzEswJ381&O&S*a*$(h!W=tlxsg`VW8FI$0*$$oye=#U-P>_zoq zZi606opgm5FtESbeR74>+)4^!CC1@m%bEaP>CQ9eu+%M_6i=VMVO-gU)m=WobzA1S z$|FIy?>LKuWW^~t4*AB8LAnAIxa3s zIEZ5Nfp||HgY&H7EqJ7L9D74M991z$D^DH3{G7s7& z8~ZcO=c_Vp7Z!Q3Q$t%G|$zZ*U>MGH?nN*ZI#w68f~SA8=)&i?L~+y2}S z+*XJ4OFRG!rGz}WX(* z{NPD!SzUa?{-N5|;T@)IEjC&Ud&;mN>&HhrAoxr)o%IzD;12?l!nUTy6YmWsIE$pe zmeaGW<~d3s1gXFemdp*ucsT#ENcXT!yFdIqEFxUT)`4TBz#hB*A}73MWJ$NYbvcF%$5`O zEy;G^0EAx!1;gNYPuZMIPbh$@1POkI zLUgX$G-pUi$t2$u$`xEntT}{8M`$xGJ4$fM;=xriJ-4x#Bf_e~XlmPx4W@Z1~bZ2+%BhECO zU!YeQ8e*{*|LW3|9s~(tr+9a=$MpYN#e2O!-x&`LT~%Fo1ylAK{|}B5lDEq*0_Lm( zJH|@@<}gymFij9G)&U~el&mgXxMOVpypvRssCDMgy5N7!l+)IvKAR}>RuUZs?oUFj znuj1=59-*Zt(Vt7bTyYY=O6f~!vdmZz5Z(##p)6%D+cCQ7ch~`^;m4xnLJ6`GwC4s zrxKi4uJ*O-qu8(x)I84qA8Sc;V)~iPD%YQN1qxbVZeRCNiu*v;q*#|_^{^S^=n`1T zC#FyR85`X@e`;Adf`v~B;*I`eH}&Kl$Ja~-5fc0JL)d?d2#=`1%7HDdk!9gEf6O7Na)sBQ&nL?=wB{r z8XNB{S>vNsUt|B1r2*{UTct;K?NBBToMpO{L>V(lEG1A8B4cN!A25Z~X~82G{Amx` zoU=_8Y%py&vq|V^=Yr6^5-qYLU{e{Is8F3dSxVNB8v`X3fUdK_lJfoGzgmOO2TR&3 zLRCc8Tzg&^o=8-=S@kb%-~3$Z7w*K$z>&(?D$c|s4i6sSUCiLn#dC#$Ig2V0foa11 z?+9BnX6(FO?xya8o_$`&pLs8DnhcnA2pjs$PA1DWifRnsSiAGs;DgW0UH?^j7~8#3 z0Rn0g54`gg0^U!Ge6Jq4bcN7M`S+2q(@Sy5qL++U$Uwpfdn33lKEA<%MZ@6u@iSsx zP?yNGe~V-IW4q~vWRlEYF!u9OyLf^n-`aNOTCO{h++U$RpxeeLocPd-z!Ul>6w-7L z$?+7835lR}^6cA;?+&HQHyiz?XjcrCAB2~U4VTe}E|G<(S2rWi@^-}`mCPr`wJSOW zIx$AzLcji7XvuYi;T~ZOBL_YGdveH2HhrHIFWJh|vHl9nCL4xt@7FSIA~WzZ&;;cD z3uB(~Q1tzVcRf}42}Ls1RG?}m>%SVztUM;(-sjmTHjDq=ha_!JtTk!!L(`LHTyCF$ zZjWhq#d;6wgT*r9KOjWd_LCdKh zB92*@fAm($9&G9~IKQ=Lt-RoP!a9+3-v>g4(QttqsTAjXOs(lNBnUHo(FPXI;}op? zAAgcuW`#Dy5K7;xy3kYT@&I!Wbc1*JJ+N-I(mP4frxkJ30}f*8{(B(*Btu0bMTl@a zs8DT_D(+D3(jL?6IU9`aMf=rvvvNHu^bC}<%N}7C&YoM|nJdoEhLi;QpSm^cx5=&2 zc9O7}Ko}qst@=CZW7QFGfoUPz!+5v@ zd~U#o23e)!|3m+SJJHhzI^wEz%E0&FL|!Yt@m@pbsqiDyDt!|j%Nae)D9bpYipXMi zrpmrAw;6clry|*xK&6ARz%)tWS>0b=y9NdYxh0p#)Diyqp6>>RKTh zKjQ>1ShjXQe=@2zaV)@2cGMM^egSC8(#;>af58dJ-;-(b%?dB z78Ey5QvC<`~&1=snD~x0(Xv6kMc%yo#DlXA`|gKyWc81)%#FG|jkq=C$`tuoA+Bhg$k3*mpH_WmxTpZ#Vg&E{_># z);%$6U?Mh%$-L!O`#L$u53M&mO`TwOLJB~HM`-hgP}L;-UL~Z&be4m|p#$%xj~}v= z3MxT)TdhguhYWX-27m4aEH%l;$#zp1fvY4Snd`&SjfQH%$f3cu!@v77GX42vn_+#r*j841a~AXRAa;`4ivVW6C4@dXif8bqN@`7{OE0 zYAuP?1)fqGL5aUN&Uxl%b-ybJjtE-`s6?a%D?j21JkC0WhPg|Dfp`sXgF;HTI%X=` ztZep;JMe@_IB@|4oOe-z+%@p=D3OLg?R5R80(4!`rAvgJcN=K2Sto@s2>QZah*l?(;!H5*XEJnOR+&*FRg^ zs-N)<%aWJ6giBqv|Kap^;cd^$#g=2?^Y3E#z*T>Rb9*~QM>?c-MyT~nG>b(? z8sPufNaxaJs;-i~1KL+8yL0OgIia;E`Nl=m&@QIOGf!CZ%NJtTSL0Gg&+rf`Qq+~n zm^a+gd+f1LHduqYQyt0mqZct!&{mpY;#pD>%)XkUWA?HEza zcyF?6<3@R!&)ojYTq@EM+5Nk}d~A+bEsvXmQKF?U~F7sZ7iBbS$ zlK;~kpGnWMOuDVx(H2dGCOkEQ_v!jGo0yFOeZ)$}mW7z{xsv;zSt=60TVEVjKdtJ4 zBAFjKm$xaTs)8&H#qdG0n2^wJ>UqwPPOQDxACRzwf0pugBpkN!qPK3+VJ&#IagWhe+0epCEOEA`j$AU-2A;eDd7ONFzy8a$ z8Wxj+d@Z9Ld5E~UG=WuYr4Azu1L+Xcq#*P<|EZ^3+W-aR73Gm~gW=C;vvG_6l!A8s zN9g{bZDE2OT^%q#`VLheyT?@HaF-(zAxT_(V^UB<7t2-aEQUC|h;^M*VJ5$O_6}W# zi_11AuFcq`fwpz{&8Ft}Wh}r*K?C)h0*FU+!j`5`2bVuD_tW{F{J~tPBL`WSMQffP zBy;#UQ0i}Z9-=_9>WJRye-bk)uRnF(=G)(K{*K1DVn8fSjCwzc#L&7czJp?4vVKBY zu|xqe3E;BCfMoCvan*R?>Pzy3)g@@`A;~}8zc$lbgqDN zQQw$9`dG~9ivtGkDZ@^Rt(g0NTpUH1{OPZIU+1{CPbWR2mGZ3y2@$;>m?~(qi2Fds zsg73ujsXKVANvptkL&6<$11gv#SfBL+7fQAIe%g###mEF0f0>E z-}eGc`|1dNBh_9ylPcAu)MeaS#9TOM73htBWd~NCiABv0{PaCsrNLjy+q+4N0*9Zx0%i+G%3 z!Gkjak_ebUid+dx;VWNGA$;G*>6UMC7TVB`xWp}zezJRDx}N901Nl`YajYtB6rp+d zo+md9wa)e1WC-!F7S)0$Ap1m{>L2qu?w`F&DX{)@NbIQPOF6m(#%lC&ubJZc)~fMK zp78)h@A?MHZ%JOH7|u7>*@hELn{)XCW1eu8p+lj`t-4B+ z(xTvGk3k9EkDpkJYk)W!uuQe(H+SYd@hIfyKMHupU}HIDaU(kz^b_I&r)TUS2}rsz zwgmh(gA(l30{wr*u_z$9@Mp?{E-ARW52L>xQlsF4**BPA0WGH;ihSq))oF;uk!0RE zDd?njaPR=+QE=dZbNR%oQ}u@|1n-5>KbV&;*m>V^VZVSS<}cmD|LNw+|DpcA|7*sQ zRF(|hiD>LT6Ec>JGJ{blHOiDFsU)RD44OuaWG|w(of%6prYK1aLPccDzExvi3Xx%k zY~QQz=ZEj#@cm^TugAUjoO|v)=XuWSHTRwajt(QTL4a`&gEDf_kH>9Az=0G(5=d$! zJA9Txx`Hg~(~DOV+G4ZZYTPN_;5Xokf&G_D99k|ImFJ)>7p$fMZe&D6xP$9pNMyDQ z&`(4JLl6`mKq8qY|6jYdcfukbK2}=8qu1~|hMrpItr*2cQhzoWpEua&rMhkJl(~lz zb)sEy^+g)=?Z^9xd<$3%_x{0{f z=^CTg23xNTd(uW{^FLI}wP!{Cfbf@$yoPE>YMRmsqHr(k$^FmOsdLe)^gVi)x<&!R zP>_d7Ea9VwR_?t&C#2+p*-_U>Wd^?TJwGiBkpAI=CDpbB!}SX|iQh=dz&^rdM0{fx zl`4WPX&bvka2)YRO%MijyS#w}{V&*yIQbbqu=LBAZN!2zbn?%XGuGh>e+wSSj5LPUnZ`*t zsv|;8O>7qrcN#|A2L{Uwn_E#G+d&470~{L)Y+Z_z#hU=kc3*ioNmfG$gH0Lt-{JVPh*I!8x^A@wb z>Awxk;fUhl%~Jo(gWl;&a`n}NZdd*0T8+QD)lYKRhA@ZI!l(1`IUC*)=Pxl%M=mI0 zqbz0OI>PWu&veDaWxXZ&_ndLCu(B|<$@%xKu4KWVwB5q$&#ph$x3)5WlKk|vw!fR| zTi)eWKTkI|n&)O&mvG;ME?S10=fryaFVW*Yf!M?zBRXZG-_6twSCZcuZt4a_nZj_c zWwcehshtdcY1W`f224#De8ClsD?5sOvT62!cH(90w&mvL(u6bk{&tOAE;S+v+S;Ou zvlJook%MZCbe8I*lsElUXlwA#h|%S*1s(++Sw4{YWxz;+HMNV`=<=N)GD{dCP6x_jqn z?$+zKrW9%vUTuRC-oASEO7Rq@dVw7q+IqiRF)I7n(T-(Si=)A&*%YcKlK>IOSEc0p zf`;CHTPUT>jkb}sE7N`K5$1GSDy{q^vAB&)HOYoD^_x+~WnS|h#=LWB{VZfhGbi1Y z;9`StMRuIYi#41yE^(bstYFROXsSVs(3O>yqV_9`?lvm|;^c&RcD=uj_=>;H%K6gX zcRAhezNXvYf{#Q^Y%i>Oty&#i$&7eo>h_+gt*T*QeKU3WU7N|@IbYAD^_)+)t2~2W zwo=#_v|aM4$J7^od+Xt7K$5yB1}1vCzRHU&l(VPM8Ed2|lwIA4D!+i0a97vc)Co50 zZ?t|cjkFn3vw=K&RJhrJ1JY<3^zd>@%F}gQ+r^nS`@das7gQ?AmYuq!-L@xEb1z>V zY4H@!5cq3eSn_vQjawz?pFh1_8FE}EAM*mp4+cCS4hGiZQk%Rtu z6IiWfpJ*Ac6tBDcw$)tS=Sp73snw1z%PQM{2E(Zi+Gxv8+YVjH$@H>@$TOrIqJZQbhVoV!EIm97f-=L@z+;yfh%%QxOLBa%!j-3>4ucteC7-vxbbTe*+}SaHso1M$ue>+ay-3$A4>odssFYJAOj4m zNUlF?+e1a#fTkx;o`}}nUc-TriHBk~Z%_9-ZXN(CvjDquO3BD+Y#_@eQwAw5_bBam z=oVgcpiFOvg0pT)@+<1T1ELuM&(koov9XWn28M>@!z8K9Yk;!DUdwp8ec~EN@&*48 z$y^g7b9^mlTL0x&Y0M67Auyn4Y;4THY3AyP+D2ZR{j2g?%QZb~(sYl{+YSFMe0qsM z?w5ugcTA@AeP@kpp*<1K>G+I47CFb1693~+&=ZoyfkKYLa0SWsqeCCw``g_zvcCDL zR;5-6Q|C-1dPFruMBu+{TwH3PuiNVv(<1sTgUpoAwJU01^0J-3=@gHjBw9C#2tP1| zLA22ydGuT6n&tM^gBr*irjsW76Hm;Fdeb*QO|+yLHp$-6s=+LeiTUvJd*!MoEftRtU5osNu$};;ducSa+6BCP^B#??NS-B&48p3zqqI zAbh}6EDj4$Hk{l)ZE%adoCLJ6{}r%6onj08t?e0nmkfO=Ehv!;KA|nUbeDH`)<9~B zg7%cYCO|G7+6sGsgW;T<{emOds*G>w1`CiJdlh9XV5yRSdZTJMh!(m0w^VADHap zl~40lFSGHLYhF_*TtDzoa&zl%A}msK|0BP_Q0AyyFFy?@k}zJfnIr_%6>Eij{d(=| zte;t)i2?v@asdK|cEJj{1JCZzbWbzmmMUrIzn}5t-~VEHyBIt`07K4Zo;!?%7L71v^w$R8lS~PN<8=Ub){XA z*%s%=@Cl8lp&{R+FbFQQIre2n zixXGN7HyHKDN1t-N(b@)j}K3kT+-~hWzT8GH;bAHysB?R8AB(xNTSnaHGD4g$cIfA z8cShd1b;B4wlwQylHp7GxND4&@|j_wiwfFcN;_E=77R`Nqf?&|KmKPNxbAXb^ucEdFUz&&t=p)jP) zAAdC9SPCbxVpy1(!j`ysh$;beAa;#5Zd`csc!dTpkwb9a7N8^FztJrg0t-;xqPgnk zf2AdEYKLnJ2$X)WUw=9h&Td@5YRdxB$Nz9v5?T}dZ_l7yN1B`j4yEfAS2W5B4N-uY zW|z4!y+;ysvpcHxO}?{q%Woz^t1bQga`nf-2r>bp?tiUfIVgKf^T3S@rIkc#eR1yQ zojoB?r8WY(7}3o38*aaX$J+HAMn4%nwi-fLG8PM&~WW=va|tpFuiNCFgo7UA{bxcjN01D%1M? ztK6hgn~FArL1Ar;VYt%gFOE&5M#?&!07)Fn$-H0I1~cCSU-Tsj5C9OhpK{q%oKtBo z?UcsyQ@wK(@`S}p#_q?d{pRw^4O~wI#~X?QstxO7e|6>*P1r3Oxq9?kQdqK%hevlm zj_%iDznQ$RCG|wOMqz8&r95s%Z_LA^@&|4xUu02^Dre@oSNP4bhGL_w1v0M%?11c) z*_4)~z<0eZSof>X)~Y>p7456D_W!&vUuKTJH)>63tq!6VL5K%%=mm1FdZKDJqiaL| z%i4g>gn3+Jd1S8AXPy&kEw*9d_+Y79{iy30+-m|TOoLPCf6vwI+w35nJCksFv1>^<&L7gg%z_OI;!3Z4K>?9RN~K1{(A|OlillVf@i}(Kr=u+rT literal 0 HcmV?d00001 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); }