Skip to content

Commit

Permalink
Adds a NoDeletes function to the Syncer
Browse files Browse the repository at this point in the history
If the Syncer is configured with noDeletes true, deleteDuplicates and delete operations
are skipped entirely in the diff() function.

Testing WIP
  • Loading branch information
rspurgeon committed Oct 3, 2024
1 parent a8c9a93 commit 25aeab0
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Syncer struct {
// enableEntityActions enables entity actions and disables direct output prints. If set to true, clients must
// consume the Syncer.resultChan channel or Syncer.Solve() will block.
enableEntityActions bool

// Prevents the Syncer from performing any Delete operations. Default is false (will delete).
noDeletes bool
}

type SyncerOpts struct {
Expand All @@ -173,6 +176,9 @@ type SyncerOpts struct {
// EnableEntityActions instructs the Syncer to send EntityActions to its resultChan. If enabled, clients must
// consume the Syncer.resultChan channel or Syncer.Solve() will block.
EnableEntityActions bool

// Prevents the Syncer from performing any Delete operations. Default is false (will delete).
NoDeletes bool
}

// NewSyncer constructs a Syncer.
Expand All @@ -196,6 +202,7 @@ func NewSyncer(opts SyncerOpts) (*Syncer, error) {
isKonnect: opts.IsKonnect,

enableEntityActions: opts.EnableEntityActions,
noDeletes: opts.NoDeletes,
}

if opts.IsKonnect {
Expand Down Expand Up @@ -278,11 +285,20 @@ func (sc *Syncer) init() error {
}

func (sc *Syncer) diff() error {
for _, operation := range []func() error{
sc.deleteDuplicates,
sc.createUpdate,
sc.delete,
} {
var operations []func() error

// If the syncer is configured to skip deletes, then don't add those functions at all to the list of diff operations.
if !sc.noDeletes {
operations = append(operations, sc.deleteDuplicates)
}

operations = append(operations, sc.createUpdate)

if !sc.noDeletes {
operations = append(operations, sc.delete)
}

for _, operation := range operations {
err := operation()
if err != nil {
return err
Expand Down

0 comments on commit 25aeab0

Please sign in to comment.