fix(deployment): instance delete fully removes the record
Deleting an instance only undeployed it from the site and set the state to NotDeployed, leaving an orphan record that could never be removed — the state-transition matrix rejected delete from NotDeployed. Delete now removes the instance record entirely (deployment history, snapshot, attribute/alarm overrides, and connection bindings go with it), and is permitted from any state.
This commit is contained in:
@@ -189,6 +189,27 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task DeleteInstanceAsync(int instanceId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// DeploymentRecords have a Restrict FK to Instance — remove them
|
||||
// explicitly first. The snapshot, overrides, and connection bindings
|
||||
// are configured with cascade delete and go with the instance.
|
||||
var records = await _dbContext.DeploymentRecords
|
||||
.Where(d => d.InstanceId == instanceId)
|
||||
.ToListAsync(cancellationToken);
|
||||
if (records.Count > 0)
|
||||
{
|
||||
_dbContext.DeploymentRecords.RemoveRange(records);
|
||||
}
|
||||
|
||||
var instance = await _dbContext.Set<Instance>()
|
||||
.FirstOrDefaultAsync(i => i.Id == instanceId, cancellationToken);
|
||||
if (instance != null)
|
||||
{
|
||||
_dbContext.Set<Instance>().Remove(instance);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _dbContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user