Implementing a Delete Operation Safety Net

To mitigate this use-case you can use Project Automation to abort the project should the Delete set return more than 10% of the whole data set.

In Data Sync the Delete operation is disabled by default, however if you require delete it maybe also required to implement something that would prevent the Delete operation should something else have gone wrong to prevent mass delete of your data.

What could happen is a change to a downstream system creating un-desired results within a Data Sync project. For example a Change to the SQL View/Query used for the source could break something which in turn may no longer return the results that was expected.

To mitigate this use-case you can use Project Automation to abort the project should the Delete set return more than 10% of the whole data set.

The code sample below for Project Automation will Throw an ApplicationException when the Delete actions are more than 10% of the Total Target rows, this then aborts the project and allows the user to investigate if this was intended before the data is deleted.

#region Usings
using System;
using System.Collections.Generic;
using System.Data;
using System.Golbalization;
using System.Text;
using System.Linq;
using System.DataSync;
#endregion

class ProjectAutomationOverride : Simego.DataSync.Automation.ProjectAutomationShim //Do Not Change This Line
{
//Implements a Safety Check to cancel the project if there are more than 10% of the total to be deleted.
//Assumes a 1 way project from A -> B

public override void Start()
{

}

public override void BeforeCompare(ProjectAutomationLoadResult loadResult)
{
    Trace.WriteLine(DatasourceA Total{0}, loadResult.TableA.Rows.Count);
    Trace.WriteLine(DatasourceB Total{0}, loadResult.TableB.Rows.Count);
}

public override void AfterCompare(ProjectAutomationCompareResult compareResult)
{
    if(compareResult.HasChanges)
    {
        var totalRows = compareResult.TableB.Rows.Count;

        if(DataSourceB.EnableDelete)
        {
            //Check that Delete does not affect more than 10%
            if(compareResult.Deleted.Count > (totalRows / 10))
            {
                Trace.WriteLine("Total Delete Operations {0}, compareResult.Deleted.Count);
                throw new ApplicationException("Total delete rows too much please investigate.");
            }
        }
    }
}

public override void BeforeSynchronisation(ProjectAutomationCompareResult compareResult)
{

}

public override void End(ProjectAutomationResult result)
{

}

public override void Error(ProjectAutomationException e)
{

}
}



Can't find the answers you're looking for? Contact our support team and we'll personally get back to you as quickly as we can.