feat(m9/T24a): guarded move-data-connection-between-sites command + handler

This commit is contained in:
Joseph Doherty
2026-06-18 11:20:58 -04:00
parent e6191ec55a
commit 48111b50fd
5 changed files with 299 additions and 3 deletions
@@ -70,13 +70,26 @@ public interface ISiteRepository
/// <returns>A task that represents the asynchronous operation.</returns>
Task DeleteDataConnectionAsync(int id, CancellationToken cancellationToken = default);
// Instances (for deletion constraint checks)
// Instances (for deletion / move constraint checks)
/// <summary>Retrieves all instances deployed to a site.</summary>
/// <param name="siteId">The site primary key to filter by.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to a read-only list of <see cref="Instance"/> entities for the given site.</returns>
Task<IReadOnlyList<Instance>> GetInstancesBySiteIdAsync(int siteId, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the distinct instances that have at least one
/// <see cref="InstanceConnectionBinding"/> referencing the given data
/// connection. Used as the primary data-integrity guard for moving a
/// connection between sites: a bound connection cannot leave its site
/// without orphaning the (site-scoped) binding, so the move handler rejects
/// the move and names the returned instances as blockers.
/// </summary>
/// <param name="dataConnectionId">The data connection primary key.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to the distinct referencing <see cref="Instance"/> entities (empty when none).</returns>
Task<IReadOnlyList<Instance>> GetInstancesReferencingDataConnectionAsync(int dataConnectionId, CancellationToken cancellationToken = default);
/// <summary>Saves all pending changes to the database.</summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to the number of state entries written to the database.</returns>
@@ -5,3 +5,18 @@ public record GetDataConnectionCommand(int DataConnectionId);
public record CreateDataConnectionCommand(int SiteId, string Name, string Protocol, string? PrimaryConfiguration, string? BackupConfiguration = null, int FailoverRetryCount = 3);
public record UpdateDataConnectionCommand(int DataConnectionId, string Name, string Protocol, string? PrimaryConfiguration, string? BackupConfiguration = null, int FailoverRetryCount = 3);
public record DeleteDataConnectionCommand(int DataConnectionId);
/// <summary>
/// Moves a data connection from its current site to <paramref name="TargetSiteId"/>.
/// Designer-gated and heavily guarded (see the handler): the target site must
/// exist, the target site must not already own a connection with the same name,
/// and NO <see cref="Entities.Instances.InstanceConnectionBinding"/> may reference
/// the connection (instances are site-scoped, so a bound connection cannot leave
/// its site without orphaning the binding). Name-based native-alarm-source
/// references (template <c>ConnectionName</c> / instance
/// <c>ConnectionNameOverride</c>) are also checked and the move is blocked rather
/// than silently creating an ambiguous/orphaned state. No auto-rewrite is performed.
/// </summary>
/// <param name="DataConnectionId">Primary key of the connection to move.</param>
/// <param name="TargetSiteId">Primary key of the destination site.</param>
public record MoveDataConnectionCommand(int DataConnectionId, int TargetSiteId);