From 5d953a1d3dd03a85399942a41ae4373deb32b20b Mon Sep 17 00:00:00 2001 From: Thomas Hilzendegen Date: Thu, 9 Nov 2023 15:14:40 +0100 Subject: [PATCH] feat(server): use tenant name as key (normalized) --- .config/dotnet-tools.json | 2 +- .../Transport/ClientRequest.cs | 2 +- .../Transport/IClientRequest.cs | 4 +- .../Stores/RelayServerTenantStore.cs | 2 +- .../Persistence/IConnectionService.cs | 4 +- .../IConnectionStatisticsWriter.cs | 4 +- .../Persistence/IStatisticsService.cs | 4 +- .../Persistence/ITenantService.cs | 40 +-- .../Persistence/Models/ClientSecret.cs | 4 +- .../Persistence/Models/Config.cs | 4 +- .../Persistence/Models/Connection.cs | 4 +- .../Models/PersistenceModelExtensions.cs | 17 +- .../Persistence/Models/Request.cs | 4 +- .../Persistence/Models/Tenant.cs | 7 +- .../Transport/ConnectorRegistry.cs | 34 +-- .../Transport/IRelayClientRequestFactory.cs | 4 +- .../Transport/ITenantHandlerFactory.cs | 4 +- .../DataTransferObjects/Tenant.cs | 6 - .../Endpoints/DeleteTenantEndpoint.cs | 14 +- .../Endpoints/GetTenantEndpoint.cs | 65 ++++ .../Endpoints/GetTenantEndpoints.cs | 115 ------- .../Endpoints/PostTenantEndpoint.cs | 18 +- .../Endpoints/PutTenantEndpoint.cs | 14 +- .../EndpointRouteBuilderExtensions.cs | 9 +- .../Extensions/PersistenceModelsExtensions.cs | 16 +- ..._Add_Tenants_and_ClientSecrets.Designer.cs | 88 ------ ...429123022_Add_Tenants_and_ClientSecrets.cs | 66 ---- ...2_Add_NormalizedName_To_Tenant.Designer.cs | 96 ------ ...0810122742_Add_NormalizedName_To_Tenant.cs | 36 --- ...00_Add_Origins_and_Connections.Designer.cs | 162 ---------- ...01123122100_Add_Origins_and_Connections.cs | 73 ----- ...201124123535_Rename_Properties.Designer.cs | 163 ---------- .../20201124123535_Rename_Properties.cs | 50 --- ...201211141231_Add_Tenant_Config.Designer.cs | 195 ------------ .../20201211141231_Add_Tenant_Config.cs | 38 --- .../20210121141153_Add_Requests.Designer.cs | 266 ---------------- .../20210121141153_Add_Requests.cs | 55 ---- ...1006081453_UpgradeEfCore_6_0_4.Designer.cs | 286 ----------------- .../20221006081453_UpgradeEfCore_6_0_4.cs | 50 --- ...hange_LastActivity_to_LastSeen.Designer.cs | 286 ----------------- ...7164039_Change_LastActivity_to_LastSeen.cs | 25 -- ...30_Add_RequestOriginalBodySize.Designer.cs | 289 ------------------ ...21115122430_Add_RequestOriginalBodySize.cs | 26 -- ...1115140807_Add_ResponseOriginalBodySize.cs | 25 -- ....cs => 20231109135209_Initial.Designer.cs} | 78 +++-- .../ConfigurationDb/20231109135209_Initial.cs | 199 ++++++++++++ ...shot.cs => RelayDbContextModelSnapshot.cs} | 76 +++-- ...ence.EntityFrameworkCore.PostgreSql.csproj | 4 + ..._Add_Tenants_and_ClientSecrets.Designer.cs | 88 ------ ...429123135_Add_Tenants_and_ClientSecrets.cs | 66 ---- ...7_Add_NormalizedName_To_Tenant.Designer.cs | 96 ------ ...0810122747_Add_NormalizedName_To_Tenant.cs | 36 --- ...06_Add_Origins_and_Connections.Designer.cs | 162 ---------- ...01123122106_Add_Origins_and_Connections.cs | 73 ----- ...201124123541_Rename_Properties.Designer.cs | 163 ---------- .../20201124123541_Rename_Properties.cs | 72 ----- ...201211141236_Add_Tenant_Config.Designer.cs | 195 ------------ .../20201211141236_Add_Tenant_Config.cs | 38 --- .../20210121141157_Add_Requests.Designer.cs | 266 ---------------- .../20210121141157_Add_Requests.cs | 54 ---- ...hange_LastActivity_to_LastSeen.Designer.cs | 286 ----------------- ...7164043_Change_LastActivity_to_LastSeen.cs | 25 -- ...33_Add_RequestOriginalBodySize.Designer.cs | 289 ------------------ ...21115122433_Add_RequestOriginalBodySize.cs | 26 -- ...1115140811_Add_ResponseOriginalBodySize.cs | 25 -- ....cs => 20231109135212_Initial.Designer.cs} | 78 +++-- .../ConfigurationDb/20231109135212_Initial.cs | 198 ++++++++++++ ...shot.cs => RelayDbContextModelSnapshot.cs} | 76 +++-- ...tence.EntityFrameworkCore.SqlServer.csproj | 4 + .../ConnectionService.cs | 4 +- .../ModelBuilderExtensions.cs | 24 +- .../StatisticsService.cs | 9 +- .../TenantService.cs | 98 +++--- .../Constants.cs | 18 +- .../ServerTransport.cs | 8 +- .../TenantHandler.cs | 8 +- .../TenantHandlerFactory.cs | 4 +- .../TenantTransport.cs | 12 +- .../ConnectorHub.cs | 33 +- .../Controllers/AcknowledgeController.cs | 4 +- .../Diagnostics/RelayRequestLogger.cs | 12 +- .../Middleware/RelayContext.cs | 2 +- .../Middleware/RelayMiddleware.cs | 77 ++--- .../Services/ConnectionStatisticsWriter.cs | 4 +- .../Transport/InMemoryTenantHandlerFactory.cs | 2 +- .../Transport/RelayClientRequestFactory.cs | 4 +- .../Transport/RequestCoordinator.cs | 6 +- src/docker/docker-compose.yml | 2 +- 88 files changed, 892 insertions(+), 4788 deletions(-) create mode 100644 src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoint.cs delete mode 100644 src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoints.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.cs rename src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/{20221115140807_Add_ResponseOriginalBodySize.Designer.cs => 20231109135209_Initial.Designer.cs} (86%) create mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.cs rename src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/{RelayServerConfigurationDbContextModelSnapshot.cs => RelayDbContextModelSnapshot.cs} (86%) delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.Designer.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.cs delete mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.cs rename src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/{20221115140811_Add_ResponseOriginalBodySize.Designer.cs => 20231109135212_Initial.Designer.cs} (86%) create mode 100644 src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.cs rename src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/{RelayServerConfigurationDbContextModelSnapshot.cs => RelayDbContextModelSnapshot.cs} (86%) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 22ec38229..dbe78984a 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-ef": { - "version": "3.1.3", + "version": "7.0.13", "commands": [ "dotnet-ef" ] diff --git a/src/Thinktecture.Relay.Abstractions/Transport/ClientRequest.cs b/src/Thinktecture.Relay.Abstractions/Transport/ClientRequest.cs index e8971e33e..2c95405a4 100644 --- a/src/Thinktecture.Relay.Abstractions/Transport/ClientRequest.cs +++ b/src/Thinktecture.Relay.Abstractions/Transport/ClientRequest.cs @@ -25,7 +25,7 @@ public class ClientRequest : IClientRequest public string Target { get; set; } = default!; /// - public Guid TenantId { get; set; } + public string TenantName { get; set; } = default!; /// public string HttpMethod { get; set; } = default!; diff --git a/src/Thinktecture.Relay.Abstractions/Transport/IClientRequest.cs b/src/Thinktecture.Relay.Abstractions/Transport/IClientRequest.cs index 38d963bec..01f28ce94 100644 --- a/src/Thinktecture.Relay.Abstractions/Transport/IClientRequest.cs +++ b/src/Thinktecture.Relay.Abstractions/Transport/IClientRequest.cs @@ -41,9 +41,9 @@ public interface IClientRequest string Target { get; set; } /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// - Guid TenantId { get; set; } + string TenantName { get; set; } /// /// The HTTP method used by the requesting client. diff --git a/src/Thinktecture.Relay.IdentityServer/Stores/RelayServerTenantStore.cs b/src/Thinktecture.Relay.IdentityServer/Stores/RelayServerTenantStore.cs index 822bde5f0..081328572 100644 --- a/src/Thinktecture.Relay.IdentityServer/Stores/RelayServerTenantStore.cs +++ b/src/Thinktecture.Relay.IdentityServer/Stores/RelayServerTenantStore.cs @@ -26,7 +26,7 @@ public RelayServerTenantStore(ITenantService tenantService) /// async Task IClientStore.FindClientByIdAsync(string clientId) { - var tenant = await _tenantService.LoadTenantCompleteByNameAsync(clientId); + var tenant = await _tenantService.LoadTenantCompleteAsync(clientId); return tenant == null ? null : ConvertToClient(tenant); } diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionService.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionService.cs index dfd293c6d..edd396db7 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionService.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionService.cs @@ -11,7 +11,7 @@ public interface IConnectionService /// /// Returns true when a connection for the tenant is available; otherwise, false. /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// A representing the asynchronous operation, which wraps the result. - Task IsConnectionAvailableAsync(Guid tenantId); + Task IsConnectionAvailableAsync(string tenantName); } diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionStatisticsWriter.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionStatisticsWriter.cs index c1af515c6..05c671ddc 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionStatisticsWriter.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IConnectionStatisticsWriter.cs @@ -18,7 +18,7 @@ public interface IConnectionStatisticsWriter /// Sets the connection time of a connection. /// /// The connection id from the corresponding transport. - /// The unique id of the tenant. + /// The unique name of the tenant. /// The unique id of the origin. /// The optional remote ip address of the connection. /// @@ -26,7 +26,7 @@ public interface IConnectionStatisticsWriter /// . /// /// A representing the asynchronous operation. - Task SetConnectionTimeAsync(string connectionId, Guid tenantId, Guid originId, IPAddress? remoteIpAddress, + Task SetConnectionTimeAsync(string connectionId, string tenantName, Guid originId, IPAddress? remoteIpAddress, CancellationToken cancellationToken = default); /// diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IStatisticsService.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IStatisticsService.cs index fae9a1b08..61828a1aa 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/IStatisticsService.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/IStatisticsService.cs @@ -59,7 +59,7 @@ public interface IStatisticsService /// Sets the connection time of a connection. /// /// The connection id from the corresponding transport. - /// The unique id of the tenant. + /// The unique name of the tenant. /// The unique id of the origin. /// The optional remote ip address of the connection. /// @@ -67,7 +67,7 @@ public interface IStatisticsService /// . /// /// A representing the asynchronous operation. - Task SetConnectionTimeAsync(string connectionId, Guid tenantId, Guid originId, IPAddress? remoteIpAddress, + Task SetConnectionTimeAsync(string connectionId, string tenantName, Guid originId, IPAddress? remoteIpAddress, CancellationToken cancellationToken = default); /// diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/ITenantService.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/ITenantService.cs index 5f082826f..3e0a43615 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/ITenantService.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/ITenantService.cs @@ -12,9 +12,9 @@ namespace Thinktecture.Relay.Server.Persistence; public interface ITenantService { /// - /// Loads a by its name with all depending entities (connections, secrets, config). + /// Loads a with all depending entities (connections, secrets, config). /// - /// The name of the to load. + /// The name of the to load. /// The token to monitor for cancellation requests. The default value is /// . /// @@ -22,12 +22,12 @@ public interface ITenantService /// A representing the asynchronous operation, which wraps the or null if /// not found. /// - Task LoadTenantCompleteByNameAsync(string name, CancellationToken cancellationToken = default); + Task LoadTenantCompleteAsync(string tenantName, CancellationToken cancellationToken = default); /// - /// Loads a by its name together with its connections. + /// Loads a with some depending entities (secrets, config). /// - /// The name of the to load. + /// The name of the to load. /// The token to monitor for cancellation requests. The default value is /// . /// @@ -35,12 +35,12 @@ public interface ITenantService /// A representing the asynchronous operation, which wraps the or null if /// not found. /// - Task LoadTenantWithConnectionsByNameAsync(string name, CancellationToken cancellationToken = default); + Task LoadTenantAsync(string tenantName, CancellationToken cancellationToken = default); /// - /// Loads a by its name together with its config. + /// Loads a together with its connections. /// - /// The name of the to load. + /// The name of the to load. /// The token to monitor for cancellation requests. The default value is /// . /// @@ -48,12 +48,12 @@ public interface ITenantService /// A representing the asynchronous operation, which wraps the or null if /// not found. /// - Task LoadTenantWithConfigByNameAsync(string name, CancellationToken cancellationToken = default); + Task LoadTenantWithConnectionsAsync(string tenantName, CancellationToken cancellationToken = default); /// - /// Loads a by its id. + /// Loads a together with its config. /// - /// The id of the to load. + /// The name of the to load. /// The token to monitor for cancellation requests. The default value is /// . /// @@ -61,7 +61,7 @@ public interface ITenantService /// A representing the asynchronous operation, which wraps the or null if /// not found. /// - Task LoadTenantCompleteByIdAsync(Guid id, CancellationToken cancellationToken = default); + Task LoadTenantWithConfigAsync(string tenantName, CancellationToken cancellationToken = default); /// /// Loads all with paging. @@ -81,19 +81,19 @@ public interface ITenantService /// The token to monitor for cancellation requests. The default value is /// . /// - /// A representing the asynchronous operation, which wraps the id of the created tenant. - Task CreateTenantAsync(Tenant tenant, CancellationToken cancellationToken = default); + /// A representing the asynchronous operation. + Task CreateTenantAsync(Tenant tenant, CancellationToken cancellationToken = default); /// /// Updates an existing . /// - /// The id of the to update. + /// The name of the to update. /// The with the data to update. /// The token to monitor for cancellation requests. The default value is /// . /// /// A representing the asynchronous operation. - Task UpdateTenantAsync(Guid tenantId, Tenant tenant, CancellationToken cancellationToken = default); + Task UpdateTenantAsync(string tenantName, Tenant tenant, CancellationToken cancellationToken = default); // TODO fix these methods, these are preliminary @@ -110,17 +110,17 @@ public interface ITenantService /// /// Deletes a . /// - /// The unique id of the tenant. + /// The name of the to delete. /// The token to monitor for cancellation requests. The default value is /// . /// /// A representing the asynchronous operation, which wraps the success of the deletion. - Task DeleteTenantByIdAsync(Guid id, CancellationToken cancellationToken = default); + Task DeleteTenantAsync(string tenantName, CancellationToken cancellationToken = default); /// /// Loads an optional for a tenant /// - /// The unique id of the tenant. + /// The name of the to load the config for. /// The token to monitor for cancellation requests. The default value is /// . /// @@ -128,7 +128,7 @@ public interface ITenantService /// A representing the asynchronous operation, which wraps the or null if /// not found. /// - Task LoadTenantConfigAsync(Guid id, CancellationToken cancellationToken = default); + Task LoadTenantConfigAsync(string tenantName, CancellationToken cancellationToken = default); /// /// Normalizes the name of the tenant. diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/ClientSecret.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/ClientSecret.cs index caac3da66..75b3e4991 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/ClientSecret.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/ClientSecret.cs @@ -13,9 +13,9 @@ public class ClientSecret public Guid Id { get; set; } /// - /// The unique id of the this secret is for. + /// The unique name of the tenant. /// - public Guid TenantId { get; set; } + public string TenantName { get; set; } = default!; /// /// A SHA256 or SHA512 of the actual secret string. diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Config.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Config.cs index cc3f0f455..1432aecb5 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Config.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Config.cs @@ -9,9 +9,9 @@ namespace Thinktecture.Relay.Server.Persistence.Models; public class Config : ITenantConfig { /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// - public Guid TenantId { get; set; } + public string TenantName { get; set; } = default!; /// public TimeSpan? KeepAliveInterval { get; set; } diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Connection.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Connection.cs index fe87b43c9..39686cec7 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Connection.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Connection.cs @@ -14,9 +14,9 @@ public class Connection public string Id { get; set; } = default!; /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// - public Guid TenantId { get; set; } + public string TenantName { get; set; } = default!; /// /// The unique id of the relay server instance this connection is held to. diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/PersistenceModelExtensions.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/PersistenceModelExtensions.cs index f3d9bcdde..2b8263407 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/PersistenceModelExtensions.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/PersistenceModelExtensions.cs @@ -17,10 +17,8 @@ public static class PersistenceModelsExtensions public static void UpdateFrom(this ClientSecret instance, ClientSecret other) { if (instance.Id != other.Id) - { throw new InvalidOperationException( - $"Id of other secret: {other.Id} is not the same as this: {instance.Id}. Cannot update from other instance."); - } + $"Id of other secret ({other.Id}) is not the same as this ({instance.Id}). Cannot update from other instance."); instance.Created = other.Created; instance.Value = other.Value; @@ -47,26 +45,21 @@ public static void UpdateFrom(this Config instance, Config other) /// The source to copy the data over from to this instance. public static void UpdateFrom(this Tenant instance, Tenant other) { - if (instance.Id != other.Id) - { + if (instance.NormalizedName != other.NormalizedName) throw new InvalidOperationException( - $"Id of other tenant: {other.Id} is not the same as this: {instance.Id}. Cannot update from other instance."); - } - - instance.Name = other.Name; - instance.NormalizedName = other.NormalizedName; + $"Name of other tenant ({other.Name}) is not the same as this ({instance.Name}). Cannot update from other instance."); instance.DisplayName = other.DisplayName; instance.Description = other.Description; - // Copy over config if available + // copy over config if available if (other.Config != null) { instance.Config ??= new Config(); instance.Config.UpdateFrom(other.Config); } - // Copy over secrets when they are complete with values + // copy over secrets when they are complete with values if (other.ClientSecrets != null) { instance.ClientSecrets ??= new List(); diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Request.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Request.cs index 3a5e35d18..e0f828645 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Request.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Request.cs @@ -9,9 +9,9 @@ namespace Thinktecture.Relay.Server.Persistence.Models; public class Request { /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// - public Guid TenantId { get; set; } + public string TenantName { get; set; } = default!; /// /// The unique id of the request. diff --git a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Tenant.cs b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Tenant.cs index fee38529e..ca99fc3cf 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Tenant.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Persistence/Models/Tenant.cs @@ -10,12 +10,7 @@ namespace Thinktecture.Relay.Server.Persistence.Models; public class Tenant { /// - /// The unique id of the tenant. - /// - public Guid Id { get; set; } - - /// - /// The name of the tenant. Also used as ClientId for connector authentication. + /// The unique name of the tenant. /// /// The maximum length is 100 unicode characters. public string Name { get; set; } = default!; diff --git a/src/Thinktecture.Relay.Server.Abstractions/Transport/ConnectorRegistry.cs b/src/Thinktecture.Relay.Server.Abstractions/Transport/ConnectorRegistry.cs index 6bb8b8515..3e6381777 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Transport/ConnectorRegistry.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Transport/ConnectorRegistry.cs @@ -26,8 +26,8 @@ public partial class ConnectorRegistry private readonly RelayServerContext _relayServerContext; private readonly IServiceProvider _serviceProvider; - private readonly ConcurrentDictionary>> _tenants = - new ConcurrentDictionary>>(); + private readonly ConcurrentDictionary>> _tenants = + new ConcurrentDictionary>>(); /// /// Initializes a new instance of the class. @@ -50,24 +50,24 @@ public ConnectorRegistry(ILogger> logger, IServiceProvider /// Registers the connection. /// /// The unique id of the connection. - /// The unique id of the tenant. + /// The unique name of the tenant. /// The optional remote ip address of the connection. /// A representing the asynchronous operation. - public async Task RegisterAsync(string connectionId, Guid tenantId, IPAddress? remoteIpAddress = null) + public async Task RegisterAsync(string connectionId, string tenantName, IPAddress? remoteIpAddress = null) { _logger.LogDebug(22100, - "Registering connection {TransportConnectionId} for tenant {TenantId}", - connectionId, tenantId); + "Registering connection {TransportConnectionId} for tenant {TenantName}", + connectionId, tenantName); var registration = - ActivatorUtilities.CreateInstance(_serviceProvider, tenantId, connectionId); + ActivatorUtilities.CreateInstance(_serviceProvider, tenantName, connectionId); - var transports = _tenants.GetOrAdd(tenantId, _ => new ConcurrentDictionary>()); + var transports = _tenants.GetOrAdd(tenantName, _ => new ConcurrentDictionary>()); transports[connectionId] = registration.ConnectorTransport; _registrations[connectionId] = registration; - await _connectionStatisticsWriter.SetConnectionTimeAsync(connectionId, tenantId, _relayServerContext.OriginId, + await _connectionStatisticsWriter.SetConnectionTimeAsync(connectionId, tenantName, _relayServerContext.OriginId, remoteIpAddress); } @@ -80,10 +80,10 @@ await _connectionStatisticsWriter.SetConnectionTimeAsync(connectionId, tenantId, public async Task UnregisterAsync(string connectionId) { if (_registrations.TryRemove(connectionId, out var registration) && - _tenants.TryGetValue(registration.TenantId, out var connectors)) + _tenants.TryGetValue(registration.TenantName, out var connectors)) { - _logger.LogDebug(22101, "Unregistering connection {TransportConnectionId} for tenant {TenantId}", - connectionId, registration.TenantId); + _logger.LogDebug(22101, "Unregistering connection {TransportConnectionId} for tenant {TenantName}", + connectionId, registration.TenantName); connectors.TryRemove(connectionId, out _); } else @@ -157,7 +157,7 @@ public Task AcknowledgeRequestAsync(string connectionId, string acknowledgeId, /// A representing the asynchronous operation, which wraps the result. public async Task TryDeliverRequestAsync(T request, CancellationToken cancellationToken = default) { - if (!_tenants.TryGetValue(request.TenantId, out var transports)) return false; + if (!_tenants.TryGetValue(request.TenantName, out var transports)) return false; var snapshot = transports.ToArray(); if (snapshot.Length == 0) return false; @@ -173,11 +173,11 @@ public async Task TryDeliverRequestAsync(T request, CancellationToken canc // ReSharper disable once ClassNeverInstantiated.Local private class ConnectorRegistration : IDisposable { - public Guid TenantId { get; } + public string TenantName { get; } public IConnectorTransport ConnectorTransport { get; } public ITenantHandler TenantHandler { get; } - public ConnectorRegistration(Guid tenantId, string connectionId, + public ConnectorRegistration(string tenantName, string connectionId, IConnectorTransportFactory connectorTransportFactory, ITenantHandlerFactory tenantHandlerFactory) { @@ -185,9 +185,9 @@ public ConnectorRegistration(Guid tenantId, string connectionId, if (connectorTransportFactory == null) throw new ArgumentNullException(nameof(connectorTransportFactory)); if (tenantHandlerFactory == null) throw new ArgumentNullException(nameof(tenantHandlerFactory)); - TenantId = tenantId; + TenantName = tenantName; ConnectorTransport = connectorTransportFactory.Create(connectionId); - TenantHandler = tenantHandlerFactory.Create(tenantId, connectionId); + TenantHandler = tenantHandlerFactory.Create(tenantName, connectionId); } public void Dispose() diff --git a/src/Thinktecture.Relay.Server.Abstractions/Transport/IRelayClientRequestFactory.cs b/src/Thinktecture.Relay.Server.Abstractions/Transport/IRelayClientRequestFactory.cs index a9619f1a6..b3762680c 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Transport/IRelayClientRequestFactory.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Transport/IRelayClientRequestFactory.cs @@ -15,7 +15,7 @@ public interface IRelayClientRequestFactory /// /// Creates an instance of a class implementing . /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// The unique id of the request. /// The . /// @@ -26,6 +26,6 @@ public interface IRelayClientRequestFactory /// A representing the asynchronous operation, which wraps the creation of an instance /// implementing . /// - Task CreateAsync(Guid tenantId, Guid requestId, HttpRequest httpRequest, + Task CreateAsync(string tenantName, Guid requestId, HttpRequest httpRequest, CancellationToken cancellationToken = default); } diff --git a/src/Thinktecture.Relay.Server.Abstractions/Transport/ITenantHandlerFactory.cs b/src/Thinktecture.Relay.Server.Abstractions/Transport/ITenantHandlerFactory.cs index bb37fac65..094c6365d 100644 --- a/src/Thinktecture.Relay.Server.Abstractions/Transport/ITenantHandlerFactory.cs +++ b/src/Thinktecture.Relay.Server.Abstractions/Transport/ITenantHandlerFactory.cs @@ -10,8 +10,8 @@ public interface ITenantHandlerFactory /// /// Creates an instance of a class implementing . /// - /// The unique id of the tenant. + /// The unique name of the tenant. /// The unique id of the connection. /// An . - ITenantHandler Create(Guid tenantId, string connectionId); + ITenantHandler Create(string tenantName, string connectionId); } diff --git a/src/Thinktecture.Relay.Server.Management/DataTransferObjects/Tenant.cs b/src/Thinktecture.Relay.Server.Management/DataTransferObjects/Tenant.cs index 954359ad6..4cb8ffc91 100644 --- a/src/Thinktecture.Relay.Server.Management/DataTransferObjects/Tenant.cs +++ b/src/Thinktecture.Relay.Server.Management/DataTransferObjects/Tenant.cs @@ -8,12 +8,6 @@ namespace Thinktecture.Relay.Server.Management.DataTransferObjects; /// public class Tenant { - /// - /// Gets or sets the unique id of the tenant. - /// - /// a8cda2aa-4e8b-4506-ba87-f150906cddbe - public Guid Id { get; set; } - /// /// Gets or sets name of the tenant. Also used as ClientId for connector authentication. /// diff --git a/src/Thinktecture.Relay.Server.Management/Endpoints/DeleteTenantEndpoint.cs b/src/Thinktecture.Relay.Server.Management/Endpoints/DeleteTenantEndpoint.cs index 07e314b0f..3a2150e62 100644 --- a/src/Thinktecture.Relay.Server.Management/Endpoints/DeleteTenantEndpoint.cs +++ b/src/Thinktecture.Relay.Server.Management/Endpoints/DeleteTenantEndpoint.cs @@ -21,7 +21,7 @@ public static partial class EndpointRouteBuilderExtensions public static RouteHandlerBuilder MapDeleteTenant(this IEndpointRouteBuilder app, string pattern, string? policy) { var builder = app - .MapDelete($"{pattern}/{{tenantId:guid}}", DeleteTenantEndpoint.HandleRequestAsync) + .MapDelete($"{pattern}/{{tenantName}}", DeleteTenantEndpoint.HandleRequestAsync) .WithName("DeleteTenant") .WithDisplayName("Delete tenant") .Produces(StatusCodes.Status204NoContent) @@ -48,18 +48,14 @@ public static class DeleteTenantEndpoint /// /// Deletes a tenant from the persistence layer. /// - /// The Id of the tenant to delete. + /// The name of the tenant to delete. /// An instance of an to access the persistence. /// The token to monitor for cancellation requests. The default value is /// . /// /// 204, if deleted; otherwise, 404. - public static async Task HandleRequestAsync( - [FromRoute] Guid tenantId, - [FromServices] ITenantService service, - CancellationToken cancellationToken = default + public static async Task HandleRequestAsync([FromRoute] string tenantName, + [FromServices] ITenantService service, CancellationToken cancellationToken = default ) - => await service.DeleteTenantByIdAsync(tenantId, cancellationToken) - ? Results.NoContent() - : Results.NotFound(); + => await service.DeleteTenantAsync(tenantName, cancellationToken) ? Results.NoContent() : Results.NotFound(); } diff --git a/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoint.cs b/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoint.cs new file mode 100644 index 000000000..0afedef7e --- /dev/null +++ b/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoint.cs @@ -0,0 +1,65 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; +using Thinktecture.Relay.Server.Management.DataTransferObjects; +using Thinktecture.Relay.Server.Management.Extensions; +using Thinktecture.Relay.Server.Persistence; + +namespace Thinktecture.Relay.Server.Management.Endpoints; + +public static partial class EndpointRouteBuilderExtensions +{ + /// + /// Maps the endpoint to retrieve a tenant. + /// + /// The web application to add the endpoint to. + /// The url pattern for this endpoint. + /// Optional; The authorization policy to apply to this endpoint. + /// The with the configured endpoint. + public static RouteHandlerBuilder MapGetTenant(this IEndpointRouteBuilder app, string pattern, string? policy) + { + var builder = app + .MapGet($"{pattern}/{{tenantName}}", GetTenantEndpoint.HandleRequestAsync) + .WithName("GetSingleTenant") + .WithDisplayName("Get single tenant") + .Produces() + .Produces(StatusCodes.Status404NotFound) + ; + + if (!String.IsNullOrWhiteSpace(policy)) + { + builder.RequireAuthorization(policy) + .Produces(StatusCodes.Status401Unauthorized) + .Produces(StatusCodes.Status403Forbidden) + ; + } + + return builder; + } +} + +/// +/// Provides an endpoint handler. +/// +public static class GetTenantEndpoint +{ + /// + /// Retrieves a single tenant. + /// + /// The name of the tenant to load. + /// An instance of an to access the persistence. + /// The token to monitor for cancellation requests. The default value is + /// . + /// + /// The tenant, if found; otherwise, 404. + public static async Task HandleRequestAsync([FromRoute] string tenantName, + [FromServices] ITenantService service, CancellationToken cancellationToken = default + ) + => await service.LoadTenantAsync(tenantName, cancellationToken) is { } tenant + ? Results.Ok(tenant.ToModel()) + : Results.NotFound(); +} diff --git a/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoints.cs b/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoints.cs deleted file mode 100644 index 6a32f1fcf..000000000 --- a/src/Thinktecture.Relay.Server.Management/Endpoints/GetTenantEndpoints.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Routing; -using Thinktecture.Relay.Server.Management.DataTransferObjects; -using Thinktecture.Relay.Server.Management.Extensions; -using Thinktecture.Relay.Server.Persistence; - -namespace Thinktecture.Relay.Server.Management.Endpoints; - -public static partial class EndpointRouteBuilderExtensions -{ - /// - /// Maps the endpoint to retrieve a tenant by id. - /// - /// The web application to add the endpoint to. - /// The url pattern for this endpoint. - /// Optional; The authorization policy to apply to this endpoint. - /// The with the configured endpoint. - public static RouteHandlerBuilder MapGetTenantById(this IEndpointRouteBuilder app, string pattern, string? policy) - { - var builder = app - .MapGet($"{pattern}/{{tenantId:Guid}}", GetTenantEndpoints.HandleRequestByIdAsync) - .WithName("GetSingleTenantById") - .WithDisplayName("Get single tenant by id") - .Produces() - .Produces(StatusCodes.Status404NotFound) - ; - - if (!String.IsNullOrWhiteSpace(policy)) - { - builder.RequireAuthorization(policy) - .Produces(StatusCodes.Status401Unauthorized) - .Produces(StatusCodes.Status403Forbidden) - ; - } - - return builder; - } - - /// - /// Maps the endpoint to retrieve a tenant by name. - /// - /// The web application to add the endpoint to. - /// The url pattern for this endpoint. - /// Optional; The authorization policy to apply to this endpoint. - /// The with the configured endpoint. - public static RouteHandlerBuilder MapGetTenantByName(this IEndpointRouteBuilder app, string pattern, string? policy) - { - var builder = app - .MapGet($"{pattern}/{{tenantName}}", GetTenantEndpoints.HandleRequestByNameAsync) - .WithName("GetSingleTenantByName") - .WithDisplayName("Get single tenant by name") - .Produces() - .Produces(StatusCodes.Status404NotFound) - ; - - if (!String.IsNullOrWhiteSpace(policy)) - { - builder.RequireAuthorization(policy) - .Produces(StatusCodes.Status401Unauthorized) - .Produces(StatusCodes.Status403Forbidden) - ; - } - - return builder; - } -} - -/// -/// Provides an endpoint handler. -/// -public static class GetTenantEndpoints -{ - /// - /// Retrieves a single tenant identified by its id. - /// - /// The id of the tenant to load. - /// An instance of an to access the persistence. - /// The token to monitor for cancellation requests. The default value is - /// . - /// - /// The tenant, if found; otherwise, 404. - public static async Task HandleRequestByIdAsync( - [FromRoute] Guid tenantId, - [FromServices] ITenantService service, - CancellationToken cancellationToken = default - ) - => await service.LoadTenantCompleteByIdAsync(tenantId, cancellationToken) - is { } tenant - ? Results.Ok(tenant.ToModel()) - : Results.NotFound(); - - /// - /// Retrieves a single tenant identified by its name - /// - /// The name of the tenant to load. - /// An instance of an to access the persistence. - /// The token to monitor for cancellation requests. The default value is - /// . - /// - /// The tenant, if found; otherwise, 404. - public static async Task HandleRequestByNameAsync( - [FromRoute] string tenantName, - [FromServices] ITenantService service, - CancellationToken cancellationToken = default - ) - => await service.LoadTenantCompleteByNameAsync(tenantName, cancellationToken) - is { } tenant - ? Results.Ok(tenant.ToModel()) - : Results.NotFound(); -} diff --git a/src/Thinktecture.Relay.Server.Management/Endpoints/PostTenantEndpoint.cs b/src/Thinktecture.Relay.Server.Management/Endpoints/PostTenantEndpoint.cs index bf2182ff3..2d6a56f50 100644 --- a/src/Thinktecture.Relay.Server.Management/Endpoints/PostTenantEndpoint.cs +++ b/src/Thinktecture.Relay.Server.Management/Endpoints/PostTenantEndpoint.cs @@ -56,15 +56,11 @@ public static class PostTenantEndpoint /// The token to monitor for cancellation requests. The default value is /// . /// - /// The tenant, if found; otherwise, 404. - public static async Task HandleRequestAsync( - [FromBody] Tenant tenant, - [FromServices] ITenantService service, - HttpRequest request, - CancellationToken cancellationToken = default - ) - => await service.CreateTenantAsync(tenant.ToEntity(), cancellationToken) - is { } id - ? Results.Created($"{request.Scheme}://{request.Host}{request.Path}/{id}", new IdResult(id)) - : Results.BadRequest(); + /// 202, if created. + public static async Task HandleRequestAsync([FromBody] Tenant tenant, [FromServices] ITenantService service, + HttpRequest request, CancellationToken cancellationToken = default) + { + await service.CreateTenantAsync(tenant.ToEntity(), cancellationToken); + return Results.Accepted(); + } } diff --git a/src/Thinktecture.Relay.Server.Management/Endpoints/PutTenantEndpoint.cs b/src/Thinktecture.Relay.Server.Management/Endpoints/PutTenantEndpoint.cs index 16a120401..2d7bb6feb 100644 --- a/src/Thinktecture.Relay.Server.Management/Endpoints/PutTenantEndpoint.cs +++ b/src/Thinktecture.Relay.Server.Management/Endpoints/PutTenantEndpoint.cs @@ -23,7 +23,7 @@ public static partial class EndpointRouteBuilderExtensions public static RouteHandlerBuilder MapPutTenant(this IEndpointRouteBuilder app, string pattern, string? policy) { var builder = app - .MapPut($"{pattern}/{{tenantId:guid}}", PutTenantEndpoint.HandleRequestAsync) + .MapPut($"{pattern}/{{tenantName}}", PutTenantEndpoint.HandleRequestAsync) .WithName("PutTenant") .WithDisplayName("Put tenant") .Produces(StatusCodes.Status202Accepted) @@ -48,22 +48,22 @@ public static RouteHandlerBuilder MapPutTenant(this IEndpointRouteBuilder app, s public static class PutTenantEndpoint { /// - /// Stores a tenant to the persistence layer. + /// Updates a tenant in the persistence layer. /// - /// The Id of the tenant to update. - /// The tenant data to store. + /// The name of the tenant to update. + /// The tenant data to update. /// An instance of an to access the persistence. /// The token to monitor for cancellation requests. The default value is /// . /// - /// Accepted, if found; otherwise, 404. + /// 202, if updated; otherwise, 404. public static async Task HandleRequestAsync( - [FromRoute] Guid tenantId, + [FromRoute] string tenantName, [FromBody] Tenant tenant, [FromServices] ITenantService service, CancellationToken cancellationToken = default ) - => await service.UpdateTenantAsync(tenantId, tenant.ToEntity(), cancellationToken) + => await service.UpdateTenantAsync(tenantName, tenant.ToEntity(), cancellationToken) ? Results.Accepted() : Results.NotFound(); } diff --git a/src/Thinktecture.Relay.Server.Management/Extensions/EndpointRouteBuilderExtensions.cs b/src/Thinktecture.Relay.Server.Management/Extensions/EndpointRouteBuilderExtensions.cs index 2bd5dcb8f..4c3aa7e8c 100644 --- a/src/Thinktecture.Relay.Server.Management/Extensions/EndpointRouteBuilderExtensions.cs +++ b/src/Thinktecture.Relay.Server.Management/Extensions/EndpointRouteBuilderExtensions.cs @@ -12,16 +12,13 @@ public static class EndpointRouteBuilderExtensions /// Adds the RelayServer management api endpoints with an optional path. /// /// The web application to register the endpoints with. - /// The base path under which the endpoints should be mapped. - /// Defaults to /api/management - public static void UseRelayServerManagementEndpoints(this IEndpointRouteBuilder app, - string basePath = "/api/management") + /// The base path under which the endpoints should be mapped (defaults to /management). + public static void UseRelayServerManagementEndpoints(this IEndpointRouteBuilder app, string basePath = "/management") { var endpointPath = $"{basePath}/tenants"; app.MapGetTenantsPaged(endpointPath, ManagementApiPolicyNames.Read); - app.MapGetTenantById(endpointPath, ManagementApiPolicyNames.Read); - app.MapGetTenantByName(endpointPath, ManagementApiPolicyNames.Read); + app.MapGetTenant(endpointPath, ManagementApiPolicyNames.Read); app.MapPostTenant(endpointPath, ManagementApiPolicyNames.Write); app.MapPutTenant(endpointPath, ManagementApiPolicyNames.Write); app.MapDeleteTenant(endpointPath, ManagementApiPolicyNames.Write); diff --git a/src/Thinktecture.Relay.Server.Management/Extensions/PersistenceModelsExtensions.cs b/src/Thinktecture.Relay.Server.Management/Extensions/PersistenceModelsExtensions.cs index 9de91c1cb..82fc53f04 100644 --- a/src/Thinktecture.Relay.Server.Management/Extensions/PersistenceModelsExtensions.cs +++ b/src/Thinktecture.Relay.Server.Management/Extensions/PersistenceModelsExtensions.cs @@ -27,7 +27,6 @@ public static TenantModel ToModel(this TenantEntity tenant) => new TenantModel() { // main tenant properties - Id = tenant.Id, Name = tenant.Name, DisplayName = tenant.DisplayName, Description = tenant.Description, @@ -40,11 +39,12 @@ public static TenantModel ToModel(this TenantEntity tenant) // credential property Credentials = tenant.ClientSecrets?.Select(s => new TenantCredential() - { - Id = s.Id, - Created = s.Created, - Expiration = s.Expiration, - }).ToArray() ?? Array.Empty(), + { + Id = s.Id, + Created = s.Created, + Expiration = s.Expiration, + }).ToArray() ?? + Array.Empty(), }; /// @@ -73,7 +73,6 @@ public static TenantEntity ToEntity(this TenantModel tenant) return new TenantEntity() { - Id = tenant.Id, Name = tenant.Name, DisplayName = tenant.DisplayName, Description = tenant.Description, @@ -97,8 +96,7 @@ public static TenantEntity ToEntity(this TenantModel tenant) /// /// The tenants to convert. /// The converted tenants. - public static IEnumerable ToModels( - this IEnumerable tenants) + public static IEnumerable ToModels(this IEnumerable tenants) => tenants.Select(ToModel); /// diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.Designer.cs deleted file mode 100644 index 69a6a5b2e..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.Designer.cs +++ /dev/null @@ -1,88 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20200429123022_Add_Tenants_and_ClientSecrets")] - partial class Add_Tenants_and_ClientSecrets - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.3") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.cs deleted file mode 100644 index 31e90b733..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200429123022_Add_Tenants_and_ClientSecrets.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_Tenants_and_ClientSecrets : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Tenants", - columns: table => new - { - Id = table.Column(nullable: false), - Name = table.Column(maxLength: 100, nullable: false), - DisplayName = table.Column(maxLength: 200, nullable: true), - Description = table.Column(maxLength: 1000, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Tenants", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ClientSecrets", - columns: table => new - { - Id = table.Column(nullable: false), - TenantId = table.Column(nullable: false), - Value = table.Column(maxLength: 4000, nullable: false), - Expiration = table.Column(nullable: true), - Created = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ClientSecrets", x => x.Id); - table.ForeignKey( - name: "FK_ClientSecrets_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ClientSecrets_TenantId", - table: "ClientSecrets", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_Tenants_Name", - table: "Tenants", - column: "Name", - unique: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ClientSecrets"); - - migrationBuilder.DropTable( - name: "Tenants"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.Designer.cs deleted file mode 100644 index cde3796d7..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.Designer.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20200810122742_Add_NormalizedName_To_Tenant")] - partial class Add_NormalizedName_To_Tenant - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.3") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.cs deleted file mode 100644 index d59ab2cef..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20200810122742_Add_NormalizedName_To_Tenant.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_NormalizedName_To_Tenant : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "NormalizedName", - table: "Tenants", - maxLength: 100, - nullable: false, - defaultValue: ""); - - migrationBuilder.Sql("UPDATE \"Tenants\" SET \"NormalizedName\" = UPPER(\"Name\")"); - - migrationBuilder.CreateIndex( - name: "IX_Tenants_NormalizedName", - table: "Tenants", - column: "NormalizedName", - unique: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Tenants_NormalizedName", - table: "Tenants"); - - migrationBuilder.DropColumn( - name: "NormalizedName", - table: "Tenants"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.Designer.cs deleted file mode 100644 index 5b588f3d1..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.Designer.cs +++ /dev/null @@ -1,162 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201123122100_Add_Origins_and_Connections")] - partial class Add_Origins_and_Connections - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastActivityTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("HeartbeatTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", "Origin") - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.cs deleted file mode 100644 index ad0f56acd..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201123122100_Add_Origins_and_Connections.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_Origins_and_Connections : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Origins", - columns: table => new - { - Id = table.Column(nullable: false), - StartTime = table.Column(nullable: false), - ShutdownTime = table.Column(nullable: true), - HeartbeatTime = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Origins", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Connections", - columns: table => new - { - Id = table.Column(nullable: false), - TenantId = table.Column(nullable: false), - OriginId = table.Column(nullable: false), - ConnectTime = table.Column(nullable: false), - DisconnectTime = table.Column(nullable: true), - LastActivityTime = table.Column(nullable: true), - RemoteIpAddress = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Connections", x => x.Id); - table.ForeignKey( - name: "FK_Connections_Origins_OriginId", - column: x => x.OriginId, - principalTable: "Origins", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Connections_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Connections_OriginId", - table: "Connections", - column: "OriginId"); - - migrationBuilder.CreateIndex( - name: "IX_Connections_TenantId", - table: "Connections", - column: "TenantId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Connections"); - - migrationBuilder.DropTable( - name: "Origins"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.Designer.cs deleted file mode 100644 index ee1cc40eb..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.Designer.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201124123535_Rename_Properties")] - partial class Rename_Properties - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastActivityTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", "Origin") - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.cs deleted file mode 100644 index fcd8603ec..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201124123535_Rename_Properties.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Rename_Properties : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "HeartbeatTime", - newName: "LastSeenTime", - table: "Origins"); - - migrationBuilder.RenameColumn( - name: "StartTime", - newName: "StartupTime", - table: "Origins"); - - migrationBuilder.AlterColumn( - name: "Id", - table: "Connections", - maxLength: 100, - nullable: false, - oldClrType: typeof(string), - oldType: "text"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastSeenTime", - newName: "HeartbeatTime", - table: "Origins"); - - migrationBuilder.RenameColumn( - name: "StartupTime", - newName: "StartTime", - table: "Origins"); - - migrationBuilder.AlterColumn( - name: "Id", - table: "Connections", - type: "text", - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 100); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.Designer.cs deleted file mode 100644 index fe53ea507..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.Designer.cs +++ /dev/null @@ -1,195 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201211141231_Add_Tenant_Config")] - partial class Add_Tenant_Config - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("EnableTracing") - .HasColumnType("boolean"); - - b.Property("KeepAliveInterval") - .HasColumnType("interval"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("interval"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("interval"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastActivityTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.cs deleted file mode 100644 index bd64d862b..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20201211141231_Add_Tenant_Config.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_Tenant_Config : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Configs", - columns: table => new - { - TenantId = table.Column(nullable: false), - KeepAliveInterval = table.Column(nullable: true), - EnableTracing = table.Column(nullable: true), - ReconnectMinimumDelay = table.Column(nullable: true), - ReconnectMaximumDelay = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Configs", x => x.TenantId); - table.ForeignKey( - name: "FK_Configs_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Configs"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.Designer.cs deleted file mode 100644 index c18690ada..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.Designer.cs +++ /dev/null @@ -1,266 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20210121141153_Add_Requests")] - partial class Add_Requests - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp without time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp without time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasColumnType("character varying(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("EnableTracing") - .HasColumnType("boolean"); - - b.Property("KeepAliveInterval") - .HasColumnType("interval"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("interval"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("interval"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastActivityTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Aborted") - .HasColumnType("boolean"); - - b.Property("Errored") - .HasColumnType("boolean"); - - b.Property("Expired") - .HasColumnType("boolean"); - - b.Property("Failed") - .HasColumnType("boolean"); - - b.Property("HttpMethod") - .IsRequired() - .HasColumnType("character varying(10)") - .HasMaxLength(10); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("timestamp with time zone"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uuid"); - - b.Property("RequestUrl") - .IsRequired() - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasColumnType("character varying(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("character varying(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("character varying(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.cs deleted file mode 100644 index 0c5176da7..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20210121141153_Add_Requests.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_Requests : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Requests", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - TenantId = table.Column(nullable: false), - RequestId = table.Column(nullable: false), - RequestDate = table.Column(nullable: false), - RequestDuration = table.Column(nullable: false), - RequestUrl = table.Column(maxLength: 1000, nullable: false), - Target = table.Column(maxLength: 100, nullable: false), - HttpMethod = table.Column(maxLength: 10, nullable: false), - RequestBodySize = table.Column(nullable: false), - HttpStatusCode = table.Column(nullable: true), - ResponseBodySize = table.Column(nullable: true), - Aborted = table.Column(nullable: false), - Failed = table.Column(nullable: false), - Expired = table.Column(nullable: false), - Errored = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Requests", x => x.Id); - table.ForeignKey( - name: "FK_Requests_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Requests_TenantId", - table: "Requests", - column: "TenantId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.Designer.cs deleted file mode 100644 index 6d610611f..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.Designer.cs +++ /dev/null @@ -1,286 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20221006081453_UpgradeEfCore_6_0_4")] - partial class UpgradeEfCore_6_0_4 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp with time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(4000) - .HasColumnType("character varying(4000)"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("EnableTracing") - .HasColumnType("boolean"); - - b.Property("KeepAliveInterval") - .HasColumnType("interval"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("interval"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("interval"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastActivityTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Aborted") - .HasColumnType("boolean"); - - b.Property("Errored") - .HasColumnType("boolean"); - - b.Property("Expired") - .HasColumnType("boolean"); - - b.Property("Failed") - .HasColumnType("boolean"); - - b.Property("HttpMethod") - .IsRequired() - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("timestamp with time zone"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uuid"); - - b.Property("RequestUrl") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DisplayName") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Navigation("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Navigation("ClientSecrets"); - - b.Navigation("Config"); - - b.Navigation("Connections"); - - b.Navigation("Requests"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.cs deleted file mode 100644 index c9c68245d..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221006081453_UpgradeEfCore_6_0_4.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class UpgradeEfCore_6_0_4 : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Expiration", - table: "ClientSecrets", - type: "timestamp with time zone", - nullable: true, - oldClrType: typeof(DateTime), - oldType: "timestamp without time zone", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "Created", - table: "ClientSecrets", - type: "timestamp with time zone", - nullable: false, - oldClrType: typeof(DateTime), - oldType: "timestamp without time zone"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Expiration", - table: "ClientSecrets", - type: "timestamp without time zone", - nullable: true, - oldClrType: typeof(DateTime), - oldType: "timestamp with time zone", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "Created", - table: "ClientSecrets", - type: "timestamp without time zone", - nullable: false, - oldClrType: typeof(DateTime), - oldType: "timestamp with time zone"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.Designer.cs deleted file mode 100644 index a2641a4c9..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.Designer.cs +++ /dev/null @@ -1,286 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20221107164039_Change_LastActivity_to_LastSeen")] - partial class Change_LastActivity_to_LastSeen - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp with time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(4000) - .HasColumnType("character varying(4000)"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("EnableTracing") - .HasColumnType("boolean"); - - b.Property("KeepAliveInterval") - .HasColumnType("interval"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("interval"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("interval"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Aborted") - .HasColumnType("boolean"); - - b.Property("Errored") - .HasColumnType("boolean"); - - b.Property("Expired") - .HasColumnType("boolean"); - - b.Property("Failed") - .HasColumnType("boolean"); - - b.Property("HttpMethod") - .IsRequired() - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("timestamp with time zone"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uuid"); - - b.Property("RequestUrl") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DisplayName") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Navigation("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Navigation("ClientSecrets"); - - b.Navigation("Config"); - - b.Navigation("Connections"); - - b.Navigation("Requests"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.cs deleted file mode 100644 index c277e8edf..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221107164039_Change_LastActivity_to_LastSeen.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Change_LastActivity_to_LastSeen : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastActivityTime", - table: "Connections", - newName: "LastSeenTime"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastSeenTime", - table: "Connections", - newName: "LastActivityTime"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.Designer.cs deleted file mode 100644 index 0171808d1..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.Designer.cs +++ /dev/null @@ -1,289 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20221115122430_Add_RequestOriginalBodySize")] - partial class Add_RequestOriginalBodySize - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("Expiration") - .HasColumnType("timestamp with time zone"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(4000) - .HasColumnType("character varying(4000)"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uuid"); - - b.Property("EnableTracing") - .HasColumnType("boolean"); - - b.Property("KeepAliveInterval") - .HasColumnType("interval"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("interval"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("interval"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ConnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("DisconnectTime") - .HasColumnType("timestamp with time zone"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("OriginId") - .HasColumnType("uuid"); - - b.Property("RemoteIpAddress") - .HasColumnType("text"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("LastSeenTime") - .HasColumnType("timestamp with time zone"); - - b.Property("ShutdownTime") - .HasColumnType("timestamp with time zone"); - - b.Property("StartupTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Aborted") - .HasColumnType("boolean"); - - b.Property("Errored") - .HasColumnType("boolean"); - - b.Property("Expired") - .HasColumnType("boolean"); - - b.Property("Failed") - .HasColumnType("boolean"); - - b.Property("HttpMethod") - .IsRequired() - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("HttpStatusCode") - .HasColumnType("integer"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("timestamp with time zone"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uuid"); - - b.Property("RequestOriginalBodySize") - .HasColumnType("bigint"); - - b.Property("RequestUrl") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TenantId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("character varying(1000)"); - - b.Property("DisplayName") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Navigation("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Navigation("ClientSecrets"); - - b.Navigation("Config"); - - b.Navigation("Connections"); - - b.Navigation("Requests"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.cs deleted file mode 100644 index 6a5b531fa..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115122430_Add_RequestOriginalBodySize.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_RequestOriginalBodySize : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "RequestOriginalBodySize", - table: "Requests", - type: "bigint", - nullable: false, - defaultValue: 0L); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "RequestOriginalBodySize", - table: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.cs deleted file mode 100644 index db0cfc04a..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb -{ - public partial class Add_ResponseOriginalBodySize : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ResponseOriginalBodySize", - table: "Requests", - type: "bigint", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "ResponseOriginalBodySize", - table: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.Designer.cs similarity index 86% rename from src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.Designer.cs rename to src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.Designer.cs index baeb0d1c7..10b5534eb 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20221115140807_Add_ResponseOriginalBodySize.Designer.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.Designer.cs @@ -12,14 +12,14 @@ namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb { [DbContext(typeof(RelayDbContext))] - [Migration("20221115140807_Add_ResponseOriginalBodySize")] - partial class Add_ResponseOriginalBodySize + [Migration("20231109135209_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("ProductVersion", "6.0.21") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -36,8 +36,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Expiration") .HasColumnType("timestamp with time zone"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.Property("Value") .IsRequired() @@ -46,15 +47,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("ClientSecrets"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => { - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .HasColumnType("text"); b.Property("EnableTracing") .HasColumnType("boolean"); @@ -68,7 +69,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("ReconnectMinimumDelay") .HasColumnType("interval"); - b.HasKey("TenantId"); + b.HasKey("TenantName"); b.ToTable("Configs"); }); @@ -94,14 +95,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("RemoteIpAddress") .HasColumnType("text"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.HasKey("Id"); b.HasIndex("OriginId"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Connections"); }); @@ -184,21 +186,25 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("character varying(100)"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Requests"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + b.Property("NormalizedName") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ConfigTenantName") + .HasColumnType("text"); b.Property("Description") .HasMaxLength(1000) @@ -213,19 +219,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("character varying(100)"); - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); + b.HasKey("NormalizedName"); - b.HasKey("Id"); + b.HasIndex("ConfigTenantName"); b.HasIndex("Name") .IsUnique(); - b.HasIndex("NormalizedName") - .IsUnique(); - b.ToTable("Tenants"); }); @@ -233,16 +233,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -257,7 +248,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Connections") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -266,11 +257,20 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Requests") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => + { + b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Config", "Config") + .WithMany() + .HasForeignKey("ConfigTenantName"); + + b.Navigation("Config"); + }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => { b.Navigation("Connections"); @@ -280,8 +280,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Navigation("ClientSecrets"); - b.Navigation("Config"); - b.Navigation("Connections"); b.Navigation("Requests"); diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.cs new file mode 100644 index 000000000..5dcb53646 --- /dev/null +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/20231109135209_Initial.cs @@ -0,0 +1,199 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Configs", + columns: table => new + { + TenantName = table.Column(type: "text", nullable: false), + KeepAliveInterval = table.Column(type: "interval", nullable: true), + EnableTracing = table.Column(type: "boolean", nullable: true), + ReconnectMinimumDelay = table.Column(type: "interval", nullable: true), + ReconnectMaximumDelay = table.Column(type: "interval", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Configs", x => x.TenantName); + }); + + migrationBuilder.CreateTable( + name: "Origins", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + StartupTime = table.Column(type: "timestamp with time zone", nullable: false), + ShutdownTime = table.Column(type: "timestamp with time zone", nullable: true), + LastSeenTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Origins", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tenants", + columns: table => new + { + NormalizedName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + DisplayName = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), + ConfigTenantName = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Tenants", x => x.NormalizedName); + table.ForeignKey( + name: "FK_Tenants_Configs_ConfigTenantName", + column: x => x.ConfigTenantName, + principalTable: "Configs", + principalColumn: "TenantName"); + }); + + migrationBuilder.CreateTable( + name: "ClientSecrets", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + TenantName = table.Column(type: "character varying(100)", nullable: false), + Value = table.Column(type: "character varying(4000)", maxLength: 4000, nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Expiration = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ClientSecrets", x => x.Id); + table.ForeignKey( + name: "FK_ClientSecrets_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Connections", + columns: table => new + { + Id = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + TenantName = table.Column(type: "character varying(100)", nullable: false), + OriginId = table.Column(type: "uuid", nullable: false), + ConnectTime = table.Column(type: "timestamp with time zone", nullable: false), + DisconnectTime = table.Column(type: "timestamp with time zone", nullable: true), + LastSeenTime = table.Column(type: "timestamp with time zone", nullable: true), + RemoteIpAddress = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Connections", x => x.Id); + table.ForeignKey( + name: "FK_Connections_Origins_OriginId", + column: x => x.OriginId, + principalTable: "Origins", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Connections_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Requests", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + TenantName = table.Column(type: "character varying(100)", nullable: false), + RequestId = table.Column(type: "uuid", nullable: false), + RequestDate = table.Column(type: "timestamp with time zone", nullable: false), + RequestDuration = table.Column(type: "bigint", nullable: false), + RequestUrl = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: false), + Target = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + HttpMethod = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + RequestOriginalBodySize = table.Column(type: "bigint", nullable: false), + RequestBodySize = table.Column(type: "bigint", nullable: false), + HttpStatusCode = table.Column(type: "integer", nullable: true), + ResponseOriginalBodySize = table.Column(type: "bigint", nullable: true), + ResponseBodySize = table.Column(type: "bigint", nullable: true), + Aborted = table.Column(type: "boolean", nullable: false), + Failed = table.Column(type: "boolean", nullable: false), + Expired = table.Column(type: "boolean", nullable: false), + Errored = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Requests", x => x.Id); + table.ForeignKey( + name: "FK_Requests_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ClientSecrets_TenantName", + table: "ClientSecrets", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Connections_OriginId", + table: "Connections", + column: "OriginId"); + + migrationBuilder.CreateIndex( + name: "IX_Connections_TenantName", + table: "Connections", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Requests_TenantName", + table: "Requests", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_ConfigTenantName", + table: "Tenants", + column: "ConfigTenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_Name", + table: "Tenants", + column: "Name", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ClientSecrets"); + + migrationBuilder.DropTable( + name: "Connections"); + + migrationBuilder.DropTable( + name: "Requests"); + + migrationBuilder.DropTable( + name: "Origins"); + + migrationBuilder.DropTable( + name: "Tenants"); + + migrationBuilder.DropTable( + name: "Configs"); + } + } +} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs similarity index 86% rename from src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs rename to src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs index 98d261a89..5bbe4b615 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs @@ -11,13 +11,13 @@ namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.Migrations.ConfigurationDb { [DbContext(typeof(RelayDbContext))] - partial class RelayServerConfigurationDbContextModelSnapshot : ModelSnapshot + partial class RelayDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("ProductVersion", "6.0.21") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -34,8 +34,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Expiration") .HasColumnType("timestamp with time zone"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.Property("Value") .IsRequired() @@ -44,15 +45,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("ClientSecrets"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => { - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .HasColumnType("text"); b.Property("EnableTracing") .HasColumnType("boolean"); @@ -66,7 +67,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("ReconnectMinimumDelay") .HasColumnType("interval"); - b.HasKey("TenantId"); + b.HasKey("TenantName"); b.ToTable("Configs"); }); @@ -92,14 +93,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("RemoteIpAddress") .HasColumnType("text"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.HasKey("Id"); b.HasIndex("OriginId"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Connections"); }); @@ -182,21 +184,25 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("character varying(100)"); - b.Property("TenantId") - .HasColumnType("uuid"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("character varying(100)"); b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Requests"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + b.Property("NormalizedName") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ConfigTenantName") + .HasColumnType("text"); b.Property("Description") .HasMaxLength(1000) @@ -211,19 +217,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("character varying(100)"); - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); + b.HasKey("NormalizedName"); - b.HasKey("Id"); + b.HasIndex("ConfigTenantName"); b.HasIndex("Name") .IsUnique(); - b.HasIndex("NormalizedName") - .IsUnique(); - b.ToTable("Tenants"); }); @@ -231,16 +231,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -255,7 +246,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Connections") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -264,11 +255,20 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Requests") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => + { + b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Config", "Config") + .WithMany() + .HasForeignKey("ConfigTenantName"); + + b.Navigation("Config"); + }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => { b.Navigation("Connections"); @@ -278,8 +278,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Navigation("ClientSecrets"); - b.Navigation("Config"); - b.Navigation("Connections"); b.Navigation("Requests"); diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.csproj b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.csproj index 2440797ca..9de632af0 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.csproj +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.PostgreSql.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.Designer.cs deleted file mode 100644 index e64dbfc78..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.Designer.cs +++ /dev/null @@ -1,88 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20200429123135_Add_Tenants_and_ClientSecrets")] - partial class Add_Tenants_and_ClientSecrets - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.Entities.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.cs deleted file mode 100644 index 22f013d10..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200429123135_Add_Tenants_and_ClientSecrets.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_Tenants_and_ClientSecrets : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Tenants", - columns: table => new - { - Id = table.Column(nullable: false), - Name = table.Column(maxLength: 100, nullable: false), - DisplayName = table.Column(maxLength: 200, nullable: true), - Description = table.Column(maxLength: 1000, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Tenants", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "ClientSecrets", - columns: table => new - { - Id = table.Column(nullable: false), - TenantId = table.Column(nullable: false), - Value = table.Column(maxLength: 4000, nullable: false), - Expiration = table.Column(nullable: true), - Created = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ClientSecrets", x => x.Id); - table.ForeignKey( - name: "FK_ClientSecrets_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_ClientSecrets_TenantId", - table: "ClientSecrets", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_Tenants_Name", - table: "Tenants", - column: "Name", - unique: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ClientSecrets"); - - migrationBuilder.DropTable( - name: "Tenants"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.Designer.cs deleted file mode 100644 index 6b0740352..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.Designer.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20200810122747_Add_NormalizedName_To_Tenant")] - partial class Add_NormalizedName_To_Tenant - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.cs deleted file mode 100644 index af0939433..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20200810122747_Add_NormalizedName_To_Tenant.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_NormalizedName_To_Tenant : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "NormalizedName", - table: "Tenants", - maxLength: 100, - nullable: false, - defaultValue: ""); - - migrationBuilder.Sql("UPDATE [Tenants] SET [NormalizedName] = UPPER([Name])"); - - migrationBuilder.CreateIndex( - name: "IX_Tenants_NormalizedName", - table: "Tenants", - column: "NormalizedName", - unique: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_Tenants_NormalizedName", - table: "Tenants"); - - migrationBuilder.DropColumn( - name: "NormalizedName", - table: "Tenants"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.Designer.cs deleted file mode 100644 index 7ad02c86d..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.Designer.cs +++ /dev/null @@ -1,162 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201123122106_Add_Origins_and_Connections")] - partial class Add_Origins_and_Connections - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastActivityTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("HeartbeatTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", "Origin") - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.cs deleted file mode 100644 index a3709fb57..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201123122106_Add_Origins_and_Connections.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_Origins_and_Connections : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Origins", - columns: table => new - { - Id = table.Column(nullable: false), - StartTime = table.Column(nullable: false), - ShutdownTime = table.Column(nullable: true), - HeartbeatTime = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Origins", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Connections", - columns: table => new - { - Id = table.Column(nullable: false), - TenantId = table.Column(nullable: false), - OriginId = table.Column(nullable: false), - ConnectTime = table.Column(nullable: false), - DisconnectTime = table.Column(nullable: true), - LastActivityTime = table.Column(nullable: true), - RemoteIpAddress = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Connections", x => x.Id); - table.ForeignKey( - name: "FK_Connections_Origins_OriginId", - column: x => x.OriginId, - principalTable: "Origins", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Connections_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Connections_OriginId", - table: "Connections", - column: "OriginId"); - - migrationBuilder.CreateIndex( - name: "IX_Connections_TenantId", - table: "Connections", - column: "TenantId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Connections"); - - migrationBuilder.DropTable( - name: "Origins"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.Designer.cs deleted file mode 100644 index 9abafd0f7..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.Designer.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201124123541_Rename_Properties")] - partial class Rename_Properties - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastActivityTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartupTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", "Origin") - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", "Tenant") - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.cs deleted file mode 100644 index 7e4c3609c..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201124123541_Rename_Properties.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Rename_Properties : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "HeartbeatTime", - newName: "LastSeenTime", - table: "Origins"); - - migrationBuilder.RenameColumn( - name: "StartTime", - newName: "StartupTime", - table: "Origins"); - - // manual insertion - migrationBuilder.DropPrimaryKey( - name: "PK_Connections", - table: "Connections"); - - migrationBuilder.AlterColumn( - name: "Id", - table: "Connections", - maxLength: 100, - nullable: false, - oldClrType: typeof(string), - oldType: "nvarchar(450)"); - - // manual insertion - migrationBuilder.AddPrimaryKey( - name: "PK_Connections", - table: "Connections", - column: "Id"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastSeenTime", - newName: "HeartbeatTime", - table: "Origins"); - - migrationBuilder.RenameColumn( - name: "StartupTime", - newName: "StartTime", - table: "Origins"); - - // manual insertion - migrationBuilder.DropPrimaryKey( - name: "PK_Connections", - table: "Connections"); - - migrationBuilder.AlterColumn( - name: "Id", - table: "Connections", - type: "nvarchar(450)", - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 100); - - // manual insertion - migrationBuilder.AddPrimaryKey( - name: "PK_Connections", - table: "Connections", - column: "Id"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.Designer.cs deleted file mode 100644 index 46f1da719..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.Designer.cs +++ /dev/null @@ -1,195 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20201211141236_Add_Tenant_Config")] - partial class Add_Tenant_Config - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("EnableTracing") - .HasColumnType("bit"); - - b.Property("KeepAliveInterval") - .HasColumnType("time"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("time"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("time"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastActivityTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartupTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.cs deleted file mode 100644 index 892e3c5d5..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20201211141236_Add_Tenant_Config.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_Tenant_Config : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Configs", - columns: table => new - { - TenantId = table.Column(nullable: false), - KeepAliveInterval = table.Column(nullable: true), - EnableTracing = table.Column(nullable: true), - ReconnectMinimumDelay = table.Column(nullable: true), - ReconnectMaximumDelay = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Configs", x => x.TenantId); - table.ForeignKey( - name: "FK_Configs_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Configs"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.Designer.cs deleted file mode 100644 index d4c187c75..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.Designer.cs +++ /dev/null @@ -1,266 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20210121141157_Add_Requests")] - partial class Add_Requests - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.7") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasColumnType("nvarchar(4000)") - .HasMaxLength(4000); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("EnableTracing") - .HasColumnType("bit"); - - b.Property("KeepAliveInterval") - .HasColumnType("time"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("time"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("time"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastActivityTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartupTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("Aborted") - .HasColumnType("bit"); - - b.Property("Errored") - .HasColumnType("bit"); - - b.Property("Expired") - .HasColumnType("bit"); - - b.Property("Failed") - .HasColumnType("bit"); - - b.Property("HttpMethod") - .IsRequired() - .HasColumnType("nvarchar(10)") - .HasMaxLength(10); - - b.Property("HttpStatusCode") - .HasColumnType("int"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("datetimeoffset"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uniqueidentifier"); - - b.Property("RequestUrl") - .IsRequired() - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasColumnType("nvarchar(1000)") - .HasMaxLength(1000); - - b.Property("DisplayName") - .HasColumnType("nvarchar(200)") - .HasMaxLength(200); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.Property("NormalizedName") - .IsRequired() - .HasColumnType("nvarchar(100)") - .HasMaxLength(100); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.cs deleted file mode 100644 index ccef43977..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20210121141157_Add_Requests.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_Requests : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Requests", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - TenantId = table.Column(nullable: false), - RequestId = table.Column(nullable: false), - RequestDate = table.Column(nullable: false), - RequestDuration = table.Column(nullable: false), - RequestUrl = table.Column(maxLength: 1000, nullable: false), - Target = table.Column(maxLength: 100, nullable: false), - HttpMethod = table.Column(maxLength: 10, nullable: false), - RequestBodySize = table.Column(nullable: false), - HttpStatusCode = table.Column(nullable: true), - ResponseBodySize = table.Column(nullable: true), - Aborted = table.Column(nullable: false), - Failed = table.Column(nullable: false), - Expired = table.Column(nullable: false), - Errored = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Requests", x => x.Id); - table.ForeignKey( - name: "FK_Requests_Tenants_TenantId", - column: x => x.TenantId, - principalTable: "Tenants", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Requests_TenantId", - table: "Requests", - column: "TenantId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.Designer.cs deleted file mode 100644 index 692132440..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.Designer.cs +++ /dev/null @@ -1,286 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20221107164043_Change_LastActivity_to_LastSeen")] - partial class Change_LastActivity_to_LastSeen - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(4000) - .HasColumnType("nvarchar(4000)"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("EnableTracing") - .HasColumnType("bit"); - - b.Property("KeepAliveInterval") - .HasColumnType("time"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("time"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("time"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartupTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Aborted") - .HasColumnType("bit"); - - b.Property("Errored") - .HasColumnType("bit"); - - b.Property("Expired") - .HasColumnType("bit"); - - b.Property("Failed") - .HasColumnType("bit"); - - b.Property("HttpMethod") - .IsRequired() - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("HttpStatusCode") - .HasColumnType("int"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("datetimeoffset"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uniqueidentifier"); - - b.Property("RequestUrl") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("DisplayName") - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Navigation("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Navigation("ClientSecrets"); - - b.Navigation("Config"); - - b.Navigation("Connections"); - - b.Navigation("Requests"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.cs deleted file mode 100644 index dd3805b57..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221107164043_Change_LastActivity_to_LastSeen.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Change_LastActivity_to_LastSeen : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastActivityTime", - table: "Connections", - newName: "LastSeenTime"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.RenameColumn( - name: "LastSeenTime", - table: "Connections", - newName: "LastActivityTime"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.Designer.cs deleted file mode 100644 index b4cebf3ba..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.Designer.cs +++ /dev/null @@ -1,289 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - [DbContext(typeof(RelayDbContext))] - [Migration("20221115122433_Add_RequestOriginalBodySize")] - partial class Add_RequestOriginalBodySize - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Expiration") - .HasColumnType("datetime2"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("Value") - .IsRequired() - .HasMaxLength(4000) - .HasColumnType("nvarchar(4000)"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("ClientSecrets"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("EnableTracing") - .HasColumnType("bit"); - - b.Property("KeepAliveInterval") - .HasColumnType("time"); - - b.Property("ReconnectMaximumDelay") - .HasColumnType("time"); - - b.Property("ReconnectMinimumDelay") - .HasColumnType("time"); - - b.HasKey("TenantId"); - - b.ToTable("Configs"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.Property("Id") - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("ConnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("DisconnectTime") - .HasColumnType("datetimeoffset"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("OriginId") - .HasColumnType("uniqueidentifier"); - - b.Property("RemoteIpAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("OriginId"); - - b.HasIndex("TenantId"); - - b.ToTable("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("LastSeenTime") - .HasColumnType("datetimeoffset"); - - b.Property("ShutdownTime") - .HasColumnType("datetimeoffset"); - - b.Property("StartupTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("Origins"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Aborted") - .HasColumnType("bit"); - - b.Property("Errored") - .HasColumnType("bit"); - - b.Property("Expired") - .HasColumnType("bit"); - - b.Property("Failed") - .HasColumnType("bit"); - - b.Property("HttpMethod") - .IsRequired() - .HasMaxLength(10) - .HasColumnType("nvarchar(10)"); - - b.Property("HttpStatusCode") - .HasColumnType("int"); - - b.Property("RequestBodySize") - .HasColumnType("bigint"); - - b.Property("RequestDate") - .HasColumnType("datetimeoffset"); - - b.Property("RequestDuration") - .HasColumnType("bigint"); - - b.Property("RequestId") - .HasColumnType("uniqueidentifier"); - - b.Property("RequestOriginalBodySize") - .HasColumnType("bigint"); - - b.Property("RequestUrl") - .IsRequired() - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("ResponseBodySize") - .HasColumnType("bigint"); - - b.Property("Target") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("TenantId"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Description") - .HasMaxLength(1000) - .HasColumnType("nvarchar(1000)"); - - b.Property("DisplayName") - .HasMaxLength(200) - .HasColumnType("nvarchar(200)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.HasIndex("NormalizedName") - .IsUnique(); - - b.ToTable("Tenants"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.ClientSecret", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Connection", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Origin", null) - .WithMany("Connections") - .HasForeignKey("OriginId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Connections") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Request", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithMany("Requests") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => - { - b.Navigation("Connections"); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => - { - b.Navigation("ClientSecrets"); - - b.Navigation("Config"); - - b.Navigation("Connections"); - - b.Navigation("Requests"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.cs deleted file mode 100644 index 668e683b1..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115122433_Add_RequestOriginalBodySize.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_RequestOriginalBodySize : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "RequestOriginalBodySize", - table: "Requests", - type: "bigint", - nullable: false, - defaultValue: 0L); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "RequestOriginalBodySize", - table: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.cs deleted file mode 100644 index d7bb019f2..000000000 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb -{ - public partial class Add_ResponseOriginalBodySize : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ResponseOriginalBodySize", - table: "Requests", - type: "bigint", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "ResponseOriginalBodySize", - table: "Requests"); - } - } -} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.Designer.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.Designer.cs similarity index 86% rename from src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.Designer.cs rename to src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.Designer.cs index e1b750e10..a8ce4cb8c 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20221115140811_Add_ResponseOriginalBodySize.Designer.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.Designer.cs @@ -12,14 +12,14 @@ namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb { [DbContext(typeof(RelayDbContext))] - [Migration("20221115140811_Add_ResponseOriginalBodySize")] - partial class Add_ResponseOriginalBodySize + [Migration("20231109135212_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("ProductVersion", "6.0.21") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); @@ -36,8 +36,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Expiration") .HasColumnType("datetime2"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.Property("Value") .IsRequired() @@ -46,15 +47,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("ClientSecrets"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .HasColumnType("nvarchar(450)"); b.Property("EnableTracing") .HasColumnType("bit"); @@ -68,7 +69,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("ReconnectMinimumDelay") .HasColumnType("time"); - b.HasKey("TenantId"); + b.HasKey("TenantName"); b.ToTable("Configs"); }); @@ -94,14 +95,15 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("RemoteIpAddress") .HasColumnType("nvarchar(max)"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.HasKey("Id"); b.HasIndex("OriginId"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Connections"); }); @@ -184,21 +186,25 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Requests"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + b.Property("NormalizedName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ConfigTenantName") + .HasColumnType("nvarchar(450)"); b.Property("Description") .HasMaxLength(1000) @@ -213,19 +219,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); + b.HasKey("NormalizedName"); - b.HasKey("Id"); + b.HasIndex("ConfigTenantName"); b.HasIndex("Name") .IsUnique(); - b.HasIndex("NormalizedName") - .IsUnique(); - b.ToTable("Tenants"); }); @@ -233,16 +233,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -257,7 +248,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Connections") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -266,11 +257,20 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Requests") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => + { + b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Config", "Config") + .WithMany() + .HasForeignKey("ConfigTenantName"); + + b.Navigation("Config"); + }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => { b.Navigation("Connections"); @@ -280,8 +280,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Navigation("ClientSecrets"); - b.Navigation("Config"); - b.Navigation("Connections"); b.Navigation("Requests"); diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.cs new file mode 100644 index 000000000..d93e5a16d --- /dev/null +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/20231109135212_Initial.cs @@ -0,0 +1,198 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Configs", + columns: table => new + { + TenantName = table.Column(type: "nvarchar(450)", nullable: false), + KeepAliveInterval = table.Column(type: "time", nullable: true), + EnableTracing = table.Column(type: "bit", nullable: true), + ReconnectMinimumDelay = table.Column(type: "time", nullable: true), + ReconnectMaximumDelay = table.Column(type: "time", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Configs", x => x.TenantName); + }); + + migrationBuilder.CreateTable( + name: "Origins", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + StartupTime = table.Column(type: "datetimeoffset", nullable: false), + ShutdownTime = table.Column(type: "datetimeoffset", nullable: true), + LastSeenTime = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Origins", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tenants", + columns: table => new + { + NormalizedName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + DisplayName = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Description = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: true), + ConfigTenantName = table.Column(type: "nvarchar(450)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Tenants", x => x.NormalizedName); + table.ForeignKey( + name: "FK_Tenants_Configs_ConfigTenantName", + column: x => x.ConfigTenantName, + principalTable: "Configs", + principalColumn: "TenantName"); + }); + + migrationBuilder.CreateTable( + name: "ClientSecrets", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + TenantName = table.Column(type: "nvarchar(100)", nullable: false), + Value = table.Column(type: "nvarchar(4000)", maxLength: 4000, nullable: false), + Created = table.Column(type: "datetime2", nullable: false), + Expiration = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ClientSecrets", x => x.Id); + table.ForeignKey( + name: "FK_ClientSecrets_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Connections", + columns: table => new + { + Id = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + TenantName = table.Column(type: "nvarchar(100)", nullable: false), + OriginId = table.Column(type: "uniqueidentifier", nullable: false), + ConnectTime = table.Column(type: "datetimeoffset", nullable: false), + DisconnectTime = table.Column(type: "datetimeoffset", nullable: true), + LastSeenTime = table.Column(type: "datetimeoffset", nullable: true), + RemoteIpAddress = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Connections", x => x.Id); + table.ForeignKey( + name: "FK_Connections_Origins_OriginId", + column: x => x.OriginId, + principalTable: "Origins", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Connections_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Requests", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TenantName = table.Column(type: "nvarchar(100)", nullable: false), + RequestId = table.Column(type: "uniqueidentifier", nullable: false), + RequestDate = table.Column(type: "datetimeoffset", nullable: false), + RequestDuration = table.Column(type: "bigint", nullable: false), + RequestUrl = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: false), + Target = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + HttpMethod = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + RequestOriginalBodySize = table.Column(type: "bigint", nullable: false), + RequestBodySize = table.Column(type: "bigint", nullable: false), + HttpStatusCode = table.Column(type: "int", nullable: true), + ResponseOriginalBodySize = table.Column(type: "bigint", nullable: true), + ResponseBodySize = table.Column(type: "bigint", nullable: true), + Aborted = table.Column(type: "bit", nullable: false), + Failed = table.Column(type: "bit", nullable: false), + Expired = table.Column(type: "bit", nullable: false), + Errored = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Requests", x => x.Id); + table.ForeignKey( + name: "FK_Requests_Tenants_TenantName", + column: x => x.TenantName, + principalTable: "Tenants", + principalColumn: "NormalizedName", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ClientSecrets_TenantName", + table: "ClientSecrets", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Connections_OriginId", + table: "Connections", + column: "OriginId"); + + migrationBuilder.CreateIndex( + name: "IX_Connections_TenantName", + table: "Connections", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Requests_TenantName", + table: "Requests", + column: "TenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_ConfigTenantName", + table: "Tenants", + column: "ConfigTenantName"); + + migrationBuilder.CreateIndex( + name: "IX_Tenants_Name", + table: "Tenants", + column: "Name", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ClientSecrets"); + + migrationBuilder.DropTable( + name: "Connections"); + + migrationBuilder.DropTable( + name: "Requests"); + + migrationBuilder.DropTable( + name: "Origins"); + + migrationBuilder.DropTable( + name: "Tenants"); + + migrationBuilder.DropTable( + name: "Configs"); + } + } +} diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs similarity index 86% rename from src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs rename to src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs index e6ac283f6..298d69a61 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayServerConfigurationDbContextModelSnapshot.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Migrations/ConfigurationDb/RelayDbContextModelSnapshot.cs @@ -11,13 +11,13 @@ namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.Migrations.ConfigurationDb { [DbContext(typeof(RelayDbContext))] - partial class RelayServerConfigurationDbContextModelSnapshot : ModelSnapshot + partial class RelayDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") + .HasAnnotation("ProductVersion", "6.0.21") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); @@ -34,8 +34,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Expiration") .HasColumnType("datetime2"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.Property("Value") .IsRequired() @@ -44,15 +45,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("ClientSecrets"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => { - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .HasColumnType("nvarchar(450)"); b.Property("EnableTracing") .HasColumnType("bit"); @@ -66,7 +67,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("ReconnectMinimumDelay") .HasColumnType("time"); - b.HasKey("TenantId"); + b.HasKey("TenantName"); b.ToTable("Configs"); }); @@ -92,14 +93,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("RemoteIpAddress") .HasColumnType("nvarchar(max)"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.HasKey("Id"); b.HasIndex("OriginId"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Connections"); }); @@ -182,21 +184,25 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("TenantId") - .HasColumnType("uniqueidentifier"); + b.Property("TenantName") + .IsRequired() + .HasColumnType("nvarchar(100)"); b.HasKey("Id"); - b.HasIndex("TenantId"); + b.HasIndex("TenantName"); b.ToTable("Requests"); }); modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + b.Property("NormalizedName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ConfigTenantName") + .HasColumnType("nvarchar(450)"); b.Property("Description") .HasMaxLength(1000) @@ -211,19 +217,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasMaxLength(100) .HasColumnType("nvarchar(100)"); - b.Property("NormalizedName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); + b.HasKey("NormalizedName"); - b.HasKey("Id"); + b.HasIndex("ConfigTenantName"); b.HasIndex("Name") .IsUnique(); - b.HasIndex("NormalizedName") - .IsUnique(); - b.ToTable("Tenants"); }); @@ -231,16 +231,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("ClientSecrets") - .HasForeignKey("TenantId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Config", b => - { - b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) - .WithOne("Config") - .HasForeignKey("Thinktecture.Relay.Server.Persistence.Models.Config", "TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -255,7 +246,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Connections") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); @@ -264,11 +255,20 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Tenant", null) .WithMany("Requests") - .HasForeignKey("TenantId") + .HasForeignKey("TenantName") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Tenant", b => + { + b.HasOne("Thinktecture.Relay.Server.Persistence.Models.Config", "Config") + .WithMany() + .HasForeignKey("ConfigTenantName"); + + b.Navigation("Config"); + }); + modelBuilder.Entity("Thinktecture.Relay.Server.Persistence.Models.Origin", b => { b.Navigation("Connections"); @@ -278,8 +278,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Navigation("ClientSecrets"); - b.Navigation("Config"); - b.Navigation("Connections"); b.Navigation("Requests"); diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.csproj b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.csproj index 726707e1f..d23eb5d48 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.csproj +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore.SqlServer.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ConnectionService.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ConnectionService.cs index 6e86cb0ba..f41fff8a6 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ConnectionService.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ConnectionService.cs @@ -17,6 +17,6 @@ public ConnectionService(RelayDbContext dbContext) => _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); /// - public Task IsConnectionAvailableAsync(Guid tenantId) - => _dbContext.Connections.AnyAsync(c => c.TenantId == tenantId); + public Task IsConnectionAvailableAsync(string tenantName) + => _dbContext.Connections.AnyAsync(c => c.TenantName == tenantName); } diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ModelBuilderExtensions.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ModelBuilderExtensions.cs index 33d7ce9b7..3bb66778e 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ModelBuilderExtensions.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/ModelBuilderExtensions.cs @@ -27,16 +27,17 @@ private static ModelBuilder ConfigureTenant(this ModelBuilder modelBuilder) => modelBuilder.Entity(builder => { builder - .HasKey(e => e.Id); + .HasKey(e => e.NormalizedName); builder - .Property(e => e.Name) + .Property(e => e.NormalizedName) .HasMaxLength(100) .IsRequired(); builder - .HasIndex(e => e.Name) - .IsUnique(); + .Property(e => e.Name) + .HasMaxLength(100) + .IsRequired(); builder .Property(e => e.DisplayName) @@ -49,28 +50,23 @@ private static ModelBuilder ConfigureTenant(this ModelBuilder modelBuilder) builder .HasMany(e => e.ClientSecrets) .WithOne() - .HasForeignKey(e => e.TenantId) + .HasForeignKey(e => e.TenantName) .OnDelete(DeleteBehavior.Cascade); builder - .Property(e => e.NormalizedName) - .HasMaxLength(100) - .IsRequired(); - - builder - .HasIndex(e => e.NormalizedName) + .HasIndex(e => e.Name) .IsUnique(); builder .HasMany(e => e.Connections) .WithOne() - .HasForeignKey(e => e.TenantId) + .HasForeignKey(e => e.TenantName) .OnDelete(DeleteBehavior.Cascade); builder .HasMany(e => e.Requests) .WithOne() - .HasForeignKey(e => e.TenantId) + .HasForeignKey(e => e.TenantName) .OnDelete(DeleteBehavior.Cascade); }); @@ -118,7 +114,7 @@ private static ModelBuilder ConfigureConfig(this ModelBuilder modelBuilder) => modelBuilder.Entity(builder => { builder - .HasKey(e => e.TenantId); + .HasKey(e => e.TenantName); }); private static ModelBuilder ConfigureRequest(this ModelBuilder modelBuilder) diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/StatisticsService.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/StatisticsService.cs index 01ff50ccb..a0e3a27aa 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/StatisticsService.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/StatisticsService.cs @@ -14,6 +14,7 @@ namespace Thinktecture.Relay.Server.Persistence.EntityFrameworkCore; public partial class StatisticsService : IStatisticsService { private readonly RelayDbContext _dbContext; + private readonly ITenantService _tenantService; private readonly ILogger _logger; /// @@ -21,10 +22,12 @@ public partial class StatisticsService : IStatisticsService /// /// An . /// The Entity Framework Core database context. - public StatisticsService(ILogger logger, RelayDbContext dbContext) + /// An . + public StatisticsService(ILogger logger, RelayDbContext dbContext, ITenantService tenantService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); + _tenantService = tenantService ?? throw new ArgumentNullException(nameof(tenantService)); } /// @@ -131,7 +134,7 @@ public async Task CleanUpOriginsAsync(TimeSpan maxAge, CancellationToken cancell } /// - public async Task SetConnectionTimeAsync(string connectionId, Guid tenantId, Guid originId, + public async Task SetConnectionTimeAsync(string connectionId, string tenantName, Guid originId, IPAddress? remoteIpAddress, CancellationToken cancellationToken = default) { @@ -145,7 +148,7 @@ public async Task SetConnectionTimeAsync(string connectionId, Guid tenantId, Gui { Id = connectionId, ConnectTime = DateTimeOffset.UtcNow, - TenantId = tenantId, + TenantName = _tenantService.NormalizeName(tenantName), OriginId = originId, RemoteIpAddress = remoteIpAddress?.ToString(), }); diff --git a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/TenantService.cs b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/TenantService.cs index 7ba84e40d..0d2f8b5d4 100644 --- a/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/TenantService.cs +++ b/src/Thinktecture.Relay.Server.Persistence.EntityFrameworkCore/TenantService.cs @@ -21,9 +21,9 @@ public TenantService(RelayDbContext dbContext) => _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); /// - public async Task LoadTenantCompleteByNameAsync(string name, CancellationToken cancellationToken) + public async Task LoadTenantCompleteAsync(string tenantName, CancellationToken cancellationToken) { - var normalizedName = NormalizeName(name); + var normalizedName = NormalizeName(tenantName); return await _dbContext.Tenants .Include(t => t.ClientSecrets) @@ -34,10 +34,22 @@ public TenantService(RelayDbContext dbContext) } /// - public async Task LoadTenantWithConnectionsByNameAsync(string name, + public async Task LoadTenantAsync(string tenantName, CancellationToken cancellationToken) + { + var normalizedName = NormalizeName(tenantName); + + return await _dbContext.Tenants + .Include(t => t.ClientSecrets) + .Include(t => t.Config) + .AsNoTracking() + .SingleOrDefaultAsync(t => t.NormalizedName == normalizedName, cancellationToken: cancellationToken); + } + + /// + public async Task LoadTenantWithConnectionsAsync(string tenantName, CancellationToken cancellationToken = default) { - var normalizedName = NormalizeName(name); + var normalizedName = NormalizeName(tenantName); return await _dbContext.Tenants .Include(t => t.Connections) @@ -46,10 +58,10 @@ public TenantService(RelayDbContext dbContext) } /// - public async Task LoadTenantWithConfigByNameAsync(string name, + public async Task LoadTenantWithConfigAsync(string tenantName, CancellationToken cancellationToken = default) { - var normalizedName = NormalizeName(name); + var normalizedName = NormalizeName(tenantName); return await _dbContext.Tenants .Include(t => t.Config) @@ -67,62 +79,38 @@ public async Task> LoadAllTenantsPagedAsync(int skip, int take, Can .ToPagedResultAsync(skip, take, cancellationToken); /// - public async Task LoadTenantCompleteByIdAsync(Guid id, CancellationToken cancellationToken) - => await _dbContext.Tenants - .Include(t => t.ClientSecrets) - .Include(t => t.Connections) - .Include(t => t.Config) - .AsNoTracking() - .SingleOrDefaultAsync(t => t.Id == id, cancellationToken: cancellationToken); - - /// - public async Task CreateTenantAsync(Tenant tenant, CancellationToken cancellationToken) + public async Task CreateTenantAsync(Tenant tenant, CancellationToken cancellationToken) { - if (await _dbContext.Tenants.AnyAsync(t => t.Id == tenant.Id, cancellationToken)) - { - throw new InvalidOperationException( - $"Tenant with id {tenant.Id} does already exist and cannot be created."); - } + tenant.NormalizedName = NormalizeName(tenant.Name); - if (tenant.Id == Guid.Empty) - { - tenant.Id = Guid.NewGuid(); - } + if (await _dbContext.Tenants.AnyAsync(t => t.NormalizedName == tenant.NormalizedName, cancellationToken)) + throw new InvalidOperationException($"Tenant {tenant.Name} does already exist and cannot be created."); var newTenant = new Tenant() { - Id = tenant.Id, + Name = tenant.Name, + NormalizedName = tenant.NormalizedName, }; - tenant.NormalizedName = NormalizeName(tenant.Name); newTenant.UpdateFrom(tenant); // ReSharper disable once MethodHasAsyncOverload _dbContext.Tenants.Add(newTenant); await _dbContext.SaveChangesAsync(cancellationToken); - - return newTenant.Id; } /// - public async Task UpdateTenantAsync(Guid tenantId, Tenant tenant, CancellationToken cancellationToken) + public async Task UpdateTenantAsync(string tenantName, Tenant tenant, CancellationToken cancellationToken) { + tenant.NormalizedName = NormalizeName(tenantName); + var existingTenant = await _dbContext.Tenants .Include(t => t.Config) .Include(t => t.ClientSecrets) - .SingleOrDefaultAsync(t => t.Id == tenantId, cancellationToken: cancellationToken); + .SingleOrDefaultAsync(t => t.NormalizedName == tenant.NormalizedName, cancellationToken: cancellationToken); - if (existingTenant == null) - { - return false; - } - - if (tenant.Id == Guid.Empty) - { - tenant.Id = tenantId; - } + if (existingTenant == null) return false; - tenant.NormalizedName = tenant.Name.ToUpperInvariant(); existingTenant.UpdateFrom(tenant); await _dbContext.SaveChangesAsync(cancellationToken); @@ -130,9 +118,9 @@ public async Task UpdateTenantAsync(Guid tenantId, Tenant tenant, Cancella } /// - public async Task DeleteTenantByIdAsync(Guid id, CancellationToken cancellationToken) + public async Task DeleteTenantAsync(string tenantName, CancellationToken cancellationToken) { - var tenant = new Tenant() { Id = id, }; + var tenant = new Tenant() { NormalizedName = NormalizeName(tenantName) }; _dbContext.Attach(tenant); _dbContext.Tenants.Remove(tenant); @@ -149,37 +137,37 @@ public async Task DeleteTenantByIdAsync(Guid id, CancellationToken cancell } /// - public async Task LoadTenantConfigAsync(Guid id, CancellationToken cancellationToken) - => await _dbContext.Configs + public async Task LoadTenantConfigAsync(string tenantName, CancellationToken cancellationToken) + { + var normalizedName = NormalizeName(tenantName); + + return await _dbContext.Configs .AsNoTracking() - .SingleOrDefaultAsync(c => c.TenantId == id, cancellationToken: cancellationToken); + .SingleOrDefaultAsync(c => c.TenantName == normalizedName, cancellationToken: cancellationToken); + } /// public async Task CreateClientSecretAsync(ClientSecret clientSecret, CancellationToken cancellationToken) { if (String.IsNullOrWhiteSpace(clientSecret.Value)) - { throw new InvalidOperationException("Client secret needs a value."); - } if (_dbContext.ClientSecrets.Any(cs => cs.Id == clientSecret.Id)) - { throw new InvalidOperationException( $"Client secret with id {clientSecret.Id} does already exist and cannot be created."); - } - if (!_dbContext.Tenants.Any(t => t.Id == clientSecret.TenantId)) - { + var normalizeName = NormalizeName(clientSecret.TenantName); + + if (!_dbContext.Tenants.Any(t => t.NormalizedName == normalizeName)) throw new InvalidOperationException( - $"Client secret cannot be created because tenant with id {clientSecret.TenantId} does not exist."); - } + $"Client secret cannot be created because tenant {clientSecret.TenantName} does not exist."); if (clientSecret.Id == Guid.Empty) { clientSecret.Id = Guid.NewGuid(); } - var newSecret = new ClientSecret() { Id = clientSecret.Id, TenantId = clientSecret.TenantId, }; + var newSecret = new ClientSecret() { Id = clientSecret.Id, TenantName = normalizeName, }; newSecret.UpdateFrom(clientSecret); _dbContext.ClientSecrets.Add(newSecret); diff --git a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/Constants.cs b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/Constants.cs index 311c6c130..de70ca121 100644 --- a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/Constants.cs +++ b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/Constants.cs @@ -5,20 +5,20 @@ internal static class Constants public const string ExchangeName = "RelayServer"; /// - /// The prefix (including trailing white-space) for request queues. + /// The prefix for request queues. /// - /// Should be followed by a tenant id. - public const string RequestQueuePrefix = "Requests "; + /// Should be followed by a space and the tenant name. + public const string RequestQueuePrefix = "Requests"; /// - /// The prefix (including trailing white-space) for response queues. + /// The prefix for response queues. /// - /// Should be followed by an origin id. - public const string ResponseQueuePrefix = "Responses "; + /// Should be followed by a space and the origin id. + public const string ResponseQueuePrefix = "Responses"; /// - /// The prefix (including trailing white-space) for acknowledge queues. + /// The prefix for acknowledge queues. /// - /// Should be followed by an origin id. - public const string AcknowledgeQueuePrefix = "Acknowledges "; + /// Should be followed by a space and the origin id. + public const string AcknowledgeQueuePrefix = "Acknowledges"; } diff --git a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/ServerTransport.cs b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/ServerTransport.cs index ce6959959..3ea6c487b 100644 --- a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/ServerTransport.cs +++ b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/ServerTransport.cs @@ -58,12 +58,12 @@ public ServerTransport(ILogger> logger, _responseConsumeModel = modelFactory.Create("response handler"); _responseConsumer = - _responseConsumeModel.ConsumeQueue(_logger, $"{Constants.ResponseQueuePrefix}{relayServerContext.OriginId}"); + _responseConsumeModel.ConsumeQueue(_logger, $"{Constants.ResponseQueuePrefix} {relayServerContext.OriginId}"); _responseConsumer.Received += ResponseConsumerReceived; _acknowledgeConsumeModel = modelFactory.Create("acknowledge handler"); _acknowledgeConsumer = - _acknowledgeConsumeModel.ConsumeQueue(_logger, $"{Constants.AcknowledgeQueuePrefix}{relayServerContext.OriginId}"); + _acknowledgeConsumeModel.ConsumeQueue(_logger, $"{Constants.AcknowledgeQueuePrefix} {relayServerContext.OriginId}"); _acknowledgeConsumer.Received += AcknowledgeConsumerReceived; } @@ -83,7 +83,7 @@ public void Dispose() /// public async Task DispatchResponseAsync(TResponse response) { - await _responseDispatchModel.PublishJsonAsync($"{Constants.ResponseQueuePrefix}{response.RequestOriginId}", + await _responseDispatchModel.PublishJsonAsync($"{Constants.ResponseQueuePrefix} {response.RequestOriginId}", response, durable: false, persistent: false); @@ -94,7 +94,7 @@ await _responseDispatchModel.PublishJsonAsync($"{Constants.ResponseQueuePrefix}{ public async Task DispatchAcknowledgeAsync(TAcknowledge request) { _logger.LogTrace("Dispatching acknowledge {@AcknowledgeRequest}", request); - await _acknowledgeDispatchModel.PublishJsonAsync($"{Constants.AcknowledgeQueuePrefix}{request.OriginId}", request, + await _acknowledgeDispatchModel.PublishJsonAsync($"{Constants.AcknowledgeQueuePrefix} {request.OriginId}", request, durable: false, persistent: false); LogDispatchedAcknowledge(request.RequestId, request.OriginId); diff --git a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandler.cs b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandler.cs index e1c57a87b..664326cdf 100644 --- a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandler.cs +++ b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandler.cs @@ -30,13 +30,13 @@ public partial class TenantHandler : ITenantHandler, IDi /// Initializes a new instance of the class. /// /// An . - /// The unique id of the tenant. + /// The unique name of the tenant. /// The unique id of the connection. /// The . /// The . /// The . /// An . - public TenantHandler(ILogger> logger, Guid tenantId, string connectionId, + public TenantHandler(ILogger> logger, string tenantName, string connectionId, ConnectorRegistry connectorRegistry, ModelFactory modelFactory, RelayServerContext relayServerContext, IAcknowledgeCoordinator acknowledgeCoordinator) { @@ -48,9 +48,9 @@ public TenantHandler(ILogger> logger, Guid _connectionId = connectionId; if (modelFactory == null) throw new ArgumentNullException(nameof(modelFactory)); - _model = modelFactory.Create($"tenant handler for {tenantId} of connection {connectionId}", true); + _model = modelFactory.Create($"tenant handler for {tenantName} of connection {connectionId}", true); - _consumer = _model.ConsumeQueue(_logger, $"{Constants.RequestQueuePrefix}{tenantId}", autoDelete: false, autoAck: false); + _consumer = _model.ConsumeQueue(_logger, $"{Constants.RequestQueuePrefix} {tenantName}", autoDelete: false, autoAck: false); _consumer.Received += ConsumerReceived; } diff --git a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandlerFactory.cs b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandlerFactory.cs index 0725223fb..157dd7e8a 100644 --- a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandlerFactory.cs +++ b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantHandlerFactory.cs @@ -21,7 +21,7 @@ public TenantHandlerFactory(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider; /// - public ITenantHandler Create(Guid tenantId, string connectionId) - => ActivatorUtilities.CreateInstance>(_serviceProvider, tenantId, + public ITenantHandler Create(string tenantName, string connectionId) + => ActivatorUtilities.CreateInstance>(_serviceProvider, tenantName, connectionId); } diff --git a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantTransport.cs b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantTransport.cs index 89b903374..ffc21f992 100644 --- a/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantTransport.cs +++ b/src/Thinktecture.Relay.Server.Protocols.RabbitMq/TenantTransport.cs @@ -41,22 +41,22 @@ public TenantTransport(ILogger> logger, } // ReSharper disable once PartialMethodWithSinglePart; Justification: Source generator - [LoggerMessage(25400, LogLevel.Trace, "Published request {RelayRequestId} to tenant {TenantId}")] - partial void LogPublishedRequest(Guid relayRequestId, Guid tenantId); + [LoggerMessage(25400, LogLevel.Trace, "Published request {RelayRequestId} to tenant {TenantName}")] + partial void LogPublishedRequest(Guid relayRequestId, string tenantName); /// public async Task TransportAsync(TRequest request) { try { - await _model.PublishJsonAsync($"{Constants.RequestQueuePrefix}{request.TenantId}", request, autoDelete: false); - LogPublishedRequest(request.RequestId, request.TenantId); + await _model.PublishJsonAsync($"{Constants.RequestQueuePrefix} {request.TenantName}", request, autoDelete: false); + LogPublishedRequest(request.RequestId, request.TenantName); } catch (RabbitMQClientException ex) { _logger.LogError(25401, ex, - "An error occured while dispatching request {RelayRequestId} to tenant {TenantId} queue", - request.RequestId, request.TenantId); + "An error occured while dispatching request {RelayRequestId} to tenant {TenantName} queue", + request.RequestId, request.TenantName); throw new TransportException(ex); } } diff --git a/src/Thinktecture.Relay.Server.Protocols.SignalR/ConnectorHub.cs b/src/Thinktecture.Relay.Server.Protocols.SignalR/ConnectorHub.cs index def70956e..5924f5a44 100644 --- a/src/Thinktecture.Relay.Server.Protocols.SignalR/ConnectorHub.cs +++ b/src/Thinktecture.Relay.Server.Protocols.SignalR/ConnectorHub.cs @@ -93,7 +93,7 @@ public override async Task OnConnectedAsync() return; } - var tenant = await _tenantService.LoadTenantWithConfigByNameAsync(tenantName); + var tenant = await _tenantService.LoadTenantWithConfigAsync(tenantName); if (tenant == null) { if (_relayServerOptions.EnableAutomaticTenantCreation) @@ -107,8 +107,7 @@ public override async Task OnConnectedAsync() await _tenantService.CreateTenantAsync(tenant); - _logger.LogInformation(26107, - "Incoming connection {TransportConnectionId} created tenant {TenantName}", + _logger.LogInformation(26107, "Incoming connection {TransportConnectionId} created tenant {TenantName}", Context.ConnectionId, tenantName); } else @@ -120,11 +119,37 @@ public override async Task OnConnectedAsync() return; } } + else if (_relayServerOptions.EnableAutomaticTenantCreation) + { + var displayName = Context.User.GetTenantDisplayName(); + var description = Context.User.GetTenantDescription(); + + var needsUpdate = false; + + if (displayName != null && tenant.DisplayName != displayName) + { + tenant.DisplayName = displayName; + needsUpdate = true; + } + + if (description != null && tenant.Description != description) + { + tenant.Description = description; + needsUpdate = true; + } + + if (needsUpdate) + { + _logger.LogInformation(26107, "Incoming connection {TransportConnectionId} updated tenant {TenantName}", + Context.ConnectionId, tenantName); + await _tenantService.UpdateTenantAsync(tenantName, tenant); + } + } _logger.LogDebug(26101, "Incoming connection {TransportConnectionId} for tenant {@Tenant}", Context.ConnectionId, tenant); - await _connectorRegistry.RegisterAsync(Context.ConnectionId, tenant.Id, + await _connectorRegistry.RegisterAsync(Context.ConnectionId, tenant.Name, Context.GetHttpContext()?.Connection.RemoteIpAddress); if (tenant.Config != null) diff --git a/src/Thinktecture.Relay.Server/Controllers/AcknowledgeController.cs b/src/Thinktecture.Relay.Server/Controllers/AcknowledgeController.cs index 4112cd491..fe25b9d4f 100644 --- a/src/Thinktecture.Relay.Server/Controllers/AcknowledgeController.cs +++ b/src/Thinktecture.Relay.Server/Controllers/AcknowledgeController.cs @@ -22,7 +22,7 @@ public AcknowledgeController(ILogger logger) => _logger = logger ?? throw new ArgumentNullException(nameof(logger)); [LoggerMessage(20100, LogLevel.Debug, "Received acknowledgement for request {RelayRequestId} on origin {OriginId}")] - partial void LogAcknowledgementReceived(Guid originId, Guid relayRequestId); + partial void LogAcknowledgementReceived(Guid relayRequestId, Guid originId); /// /// @@ -35,7 +35,7 @@ public AcknowledgeController(ILogger logger) public async Task AcknowledgeAsync([FromRoute] Guid originId, [FromRoute] Guid requestId, [FromServices] IAcknowledgeDispatcher acknowledgeDispatcher) { - LogAcknowledgementReceived(originId, requestId); + LogAcknowledgementReceived(requestId, originId); await acknowledgeDispatcher.DispatchAsync(new AcknowledgeRequest() { OriginId = originId, RequestId = requestId, RemoveRequestBodyContent = true }); diff --git a/src/Thinktecture.Relay.Server/Diagnostics/RelayRequestLogger.cs b/src/Thinktecture.Relay.Server/Diagnostics/RelayRequestLogger.cs index d7915a91e..ba4cfe15c 100644 --- a/src/Thinktecture.Relay.Server/Diagnostics/RelayRequestLogger.cs +++ b/src/Thinktecture.Relay.Server/Diagnostics/RelayRequestLogger.cs @@ -17,6 +17,7 @@ public partial class RelayRequestLogger : IRelayRequestLogg private readonly ILogger> _logger; private readonly RelayServerOptions _relayServerOptions; private readonly IRequestService _requestService; + private readonly ITenantService _tenantService; /// /// Initializes a new instance of the class. @@ -24,13 +25,16 @@ public partial class RelayRequestLogger : IRelayRequestLogg /// An instance of an . /// An . /// An . - public RelayRequestLogger(ILogger> logger, - IRequestService requestService, IOptions relayServerOptions) + /// An . + public RelayRequestLogger(ILogger> logger, IRequestService requestService, + IOptions relayServerOptions, ITenantService tenantService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _requestService = requestService ?? throw new ArgumentNullException(nameof(requestService)); + _tenantService = tenantService ?? throw new ArgumentNullException(nameof(tenantService)); + if (relayServerOptions == null) throw new ArgumentNullException(nameof(relayServerOptions)); - _requestService = requestService ?? throw new ArgumentNullException(nameof(requestService)); _relayServerOptions = relayServerOptions.Value; } @@ -114,7 +118,7 @@ public async Task LogErrorAsync(IRelayContext relayContext) private Request CreateRequest(IRelayContext relayContext) => new Request() { - TenantId = relayContext.ClientRequest.TenantId, + TenantName = _tenantService.NormalizeName(relayContext.ClientRequest.TenantName), RequestId = relayContext.RequestId, RequestDate = relayContext.RequestStart, RequestDuration = (long)(DateTime.UtcNow - relayContext.RequestStart).TotalMilliseconds, diff --git a/src/Thinktecture.Relay.Server/Middleware/RelayContext.cs b/src/Thinktecture.Relay.Server/Middleware/RelayContext.cs index 27327d5ab..967098e76 100644 --- a/src/Thinktecture.Relay.Server/Middleware/RelayContext.cs +++ b/src/Thinktecture.Relay.Server/Middleware/RelayContext.cs @@ -31,7 +31,7 @@ public class RelayContext : IRelayContext - public bool ConnectorAvailable => _connectionService.IsConnectionAvailableAsync(ClientRequest.TenantId) + public bool ConnectorAvailable => _connectionService.IsConnectionAvailableAsync(ClientRequest.TenantName) .GetAwaiter().GetResult(); /// diff --git a/src/Thinktecture.Relay.Server/Middleware/RelayMiddleware.cs b/src/Thinktecture.Relay.Server/Middleware/RelayMiddleware.cs index e242cd339..e5f816469 100644 --- a/src/Thinktecture.Relay.Server/Middleware/RelayMiddleware.cs +++ b/src/Thinktecture.Relay.Server/Middleware/RelayMiddleware.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -14,6 +15,7 @@ using Thinktecture.Relay.Server.Diagnostics; using Thinktecture.Relay.Server.Interceptor; using Thinktecture.Relay.Server.Persistence; +using Thinktecture.Relay.Server.Persistence.Models; using Thinktecture.Relay.Server.Transport; using Thinktecture.Relay.Transport; @@ -133,15 +135,18 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) return; } - var tenant = await LoadTenantStateByNameAsync(tenantName); - if (tenant == null) + var tenantState = await LoadTenantStateByNameAsync(tenantName); + if (tenantState.Unknown) { LogUnknownTenant(tenantName, context.Request.Path, context.Request.QueryString); await next.Invoke(context); return; } - if (_relayServerOptions.RequireActiveConnection && !tenant.Value.HasActiveConnections) + // ensure the correct casing (ignore it from url starting from here) + tenantName = tenantState.TenantName; + + if (_relayServerOptions.RequireActiveConnection && !tenantState.HasActiveConnections) { LogNoActiveConnection(tenantName); context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; @@ -162,7 +167,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) await context.Request.Body.DrainAsync(cts.Token); _relayContext.ClientRequest = - await _requestFactory.CreateAsync(tenant.Value.Id, _relayContext.RequestId, context.Request, cts.Token); + await _requestFactory.CreateAsync(tenantName, _relayContext.RequestId, context.Request, cts.Token); if (_logger.IsEnabled(LogLevel.Trace)) _logRequestParsed(_logger, _relayContext.ClientRequest, null); @@ -293,7 +298,7 @@ private async Task WaitForConnectorResponseAsync(CancellationToken cancellationT partial void LogExecutingResponseInterceptors(Guid relayRequestId); [LoggerMessage(20612, LogLevel.Trace, "Executing interceptor {Interceptor} for request {RelayRequestId}")] - partial void LogExecutingResponseInterceptor(string? interceptor, Guid? relayRequestId); + partial void LogExecutingResponseInterceptor(string? interceptor, Guid relayRequestId); private async Task InterceptTargetResponseAsync(CancellationToken cancellationToken) { @@ -368,56 +373,58 @@ private Task WriteErrorResponse(HttpStatusCode httpStatusCode, HttpResponse resp => _responseWriter.WriteAsync(_relayContext.ClientRequest.CreateResponse(httpStatusCode), response, cancellationToken); - private async Task LoadTenantStateByNameAsync(string name, CancellationToken cancellationToken = default) + private async Task LoadTenantStateByNameAsync(string name, + CancellationToken cancellationToken = default) { var cacheKey = $"tenant_state_{_tenantService.NormalizeName(name)}"; var cachedData = await _cache.GetAsync(cacheKey, cancellationToken); - if (cachedData != null) return TenantState.FromByteArray(cachedData); + if (cachedData != null) return TenantState.FromSpan(cachedData); - var tenant = await _tenantService.LoadTenantWithConnectionsByNameAsync(name, cancellationToken); - var result = tenant == null - ? (TenantState?)null - : new TenantState(tenant.Id, tenant.Connections?.Any(c => c.DisconnectTime == null) == true); + var tenant = await _tenantService.LoadTenantWithConnectionsAsync(name, cancellationToken); + var state = TenantState.FromTenant(tenant); var cacheEntryOptions = new DistributedCacheEntryOptions() .SetAbsoluteExpiration(_relayServerOptions.TenantInfoCacheDuration); + await _cache.SetAsync(cacheKey, TenantState.AsSpan(state).ToArray(), cacheEntryOptions, cancellationToken); - cachedData = TenantState.ToByteArray(result); - await _cache.SetAsync(cacheKey, cachedData, cacheEntryOptions, cancellationToken); - - return result; + return state; } - private readonly struct TenantState + private record TenantState { - public Guid Id { get; } + public bool Unknown { get; private init; } - public bool HasActiveConnections { get; } + public bool HasActiveConnections { get; private init; } - public TenantState(Guid id, bool hasActiveConnections) - { - Id = id; - HasActiveConnections = hasActiveConnections; - } + public string TenantName { get; private init; } = string.Empty; - public static TenantState? FromByteArray(byte[] buffer) + public static TenantState FromTenant(Tenant? tenant) { - // bytes 0 is null marker, 1-17 are guid, 18 is HasActiveConnections - if (buffer[0] == byte.MinValue) return null; + if (tenant == null) return new TenantState() { Unknown = true }; - return new TenantState(new Guid(new Span(buffer, 1, 16)), buffer[17] == byte.MaxValue); + return new TenantState + { + TenantName = tenant.Name, + HasActiveConnections = tenant.Connections?.Any(c => c.DisconnectTime == null) ?? false + }; } - public static byte[] ToByteArray(TenantState? tenantInfo) - { - // bytes 0 is null marker, 1-17 are guid, 18 is HasActiveConnections - var buffer = new byte[18]; + public static TenantState FromSpan(Span span) + => new TenantState() + { + Unknown = span[0] == byte.MaxValue, + HasActiveConnections = span[1] == byte.MaxValue, + TenantName = Encoding.Unicode.GetString(span[2..]), + }; - if (tenantInfo == null) return buffer; + public static Span AsSpan(TenantState tenantState) + { + var tenantName = Encoding.Unicode.GetBytes(tenantState.TenantName); - buffer[0] = byte.MaxValue; - tenantInfo.Value.Id.TryWriteBytes(new Span(buffer, 1, 16)); - buffer[17] = tenantInfo.Value.HasActiveConnections ? byte.MaxValue : byte.MinValue; + var buffer = new byte[2 + tenantName.Length]; + buffer[0] = tenantState.Unknown ? byte.MaxValue : byte.MinValue; + buffer[1] = tenantState.HasActiveConnections ? byte.MaxValue : byte.MinValue; + tenantName.CopyTo(buffer, 2); return buffer; } diff --git a/src/Thinktecture.Relay.Server/Services/ConnectionStatisticsWriter.cs b/src/Thinktecture.Relay.Server/Services/ConnectionStatisticsWriter.cs index 6d0477891..b73748105 100644 --- a/src/Thinktecture.Relay.Server/Services/ConnectionStatisticsWriter.cs +++ b/src/Thinktecture.Relay.Server/Services/ConnectionStatisticsWriter.cs @@ -23,13 +23,13 @@ public ConnectionStatisticsWriter(IServiceScopeFactory serviceProvider) => _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); /// - public async Task SetConnectionTimeAsync(string connectionId, Guid tenantId, Guid originId, + public async Task SetConnectionTimeAsync(string connectionId, string tenantName, Guid originId, IPAddress? remoteIpAddress, CancellationToken cancellationToken = default) { using var scope = _serviceProvider.CreateScope(); await scope.ServiceProvider.GetRequiredService() - .SetConnectionTimeAsync(connectionId, tenantId, originId, remoteIpAddress, cancellationToken); + .SetConnectionTimeAsync(connectionId, tenantName, originId, remoteIpAddress, cancellationToken); } /// diff --git a/src/Thinktecture.Relay.Server/Transport/InMemoryTenantHandlerFactory.cs b/src/Thinktecture.Relay.Server/Transport/InMemoryTenantHandlerFactory.cs index e393861ab..64bedd3c9 100644 --- a/src/Thinktecture.Relay.Server/Transport/InMemoryTenantHandlerFactory.cs +++ b/src/Thinktecture.Relay.Server/Transport/InMemoryTenantHandlerFactory.cs @@ -4,6 +4,6 @@ namespace Thinktecture.Relay.Server.Transport; internal class InMemoryTenantHandlerFactory : ITenantHandlerFactory { - public ITenantHandler Create(Guid tenantId, string connectionId) + public ITenantHandler Create(string tenantName, string connectionId) => InMemoryTenantHandler.Noop; } diff --git a/src/Thinktecture.Relay.Server/Transport/RelayClientRequestFactory.cs b/src/Thinktecture.Relay.Server/Transport/RelayClientRequestFactory.cs index 558e7217f..cf0a95722 100644 --- a/src/Thinktecture.Relay.Server/Transport/RelayClientRequestFactory.cs +++ b/src/Thinktecture.Relay.Server/Transport/RelayClientRequestFactory.cs @@ -30,7 +30,7 @@ public RelayClientRequestFactory(RelayServerContext relayServerContext, } /// - public Task CreateAsync(Guid tenantId, Guid requestId, HttpRequest httpRequest, + public Task CreateAsync(string tenantName, Guid requestId, HttpRequest httpRequest, CancellationToken cancellationToken = default) { var parts = httpRequest.Path.Value?.Split('/').Skip(1).ToArray() ?? Array.Empty(); @@ -40,7 +40,7 @@ public Task CreateAsync(Guid tenantId, Guid requestId, HttpRequest httpReques RequestId = requestId, RequestOriginId = _relayServerContext.OriginId, Target = parts.Length > 1 ? parts[1] : string.Empty, - TenantId = tenantId, + TenantName = tenantName, HttpMethod = httpRequest.Method, Url = $"{string.Join("/", parts.Skip(2))}{httpRequest.QueryString}", HttpHeaders = httpRequest.Headers.ToDictionary(h => h.Key, h => h.Value.ToArray(), StringComparer.OrdinalIgnoreCase), diff --git a/src/Thinktecture.Relay.Server/Transport/RequestCoordinator.cs b/src/Thinktecture.Relay.Server/Transport/RequestCoordinator.cs index 4af6437c9..321973e08 100644 --- a/src/Thinktecture.Relay.Server/Transport/RequestCoordinator.cs +++ b/src/Thinktecture.Relay.Server/Transport/RequestCoordinator.cs @@ -24,13 +24,13 @@ public RequestCoordinator(ILogger> logger, ITenantTranspor _tenantTransport = tenantTransport ?? throw new ArgumentNullException(nameof(tenantTransport)); } - [LoggerMessage(21300, LogLevel.Debug, "Redirecting request {RelayRequestId} to transport for tenant {TenantId}")] - partial void LogRedirect(Guid relayRequestId, Guid tenantId); + [LoggerMessage(21300, LogLevel.Debug, "Redirecting request {RelayRequestId} to transport for tenant {TenantName}")] + partial void LogRedirect(Guid relayRequestId, string tenantName); /// public async Task ProcessRequestAsync(T request, CancellationToken cancellationToken = default) { - LogRedirect(request.RequestId, request.TenantId); + LogRedirect(request.RequestId, request.TenantName); await _tenantTransport.TransportAsync(request); } } diff --git a/src/docker/docker-compose.yml b/src/docker/docker-compose.yml index dbf7aebfc..cf7901456 100644 --- a/src/docker/docker-compose.yml +++ b/src/docker/docker-compose.yml @@ -76,7 +76,7 @@ services: depends_on: - relay_server_migrations - relay_management - command: [ "sh", "-c", "sleep 5 && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"TT-Api-Key: write-key\" --data-raw '{\"id\": \"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa\", \"name\": \"TestTenant1\", \"credentials\": [{ \"id\": \"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1\", \"plainTextValue\": \"\" }]}' http://relay_management:5000/api/management/tenants && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"TT-Api-Key: write-key\" --data-raw '{\"id\": \"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb\", \"name\": \"TestTenant2\", \"credentials\": [{ \"id\": \"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbb1\", \"plainTextValue\": \"\" }]}' http://relay_management:5000/api/management/tenants" ] + command: [ "sh", "-c", "sleep 5 && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"TT-Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant1\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay_management:5000/management/tenants && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"TT-Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant2\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay_management:5000/management/tenants" ] relay_identityserver: <<: *defaults image: relay_identityserver