Skip to content

Commit

Permalink
Check for attached relations before dropping distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Feb 21, 2024
1 parent a805661 commit b0b5000
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,31 @@ func processDrop(ctx context.Context, dstmt spqrparser.Statement, isCascade bool
}

if stmt.ID != "*" {
if ds, err := mngr.GetDistribution(ctx, stmt.ID); err != nil {
return err
} else if len(ds.Relations) != 0 && !isCascade {
fmt.Errorf("cannot drop distribution %s because there are relations attached to it\nHINT: Use DROP ... CASCADE to detach relations autoimatically", stmt.ID)

Check failure on line 89 in pkg/meta/meta.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unusedresult: result of fmt.Errorf call not used (govet)

Check failure on line 89 in pkg/meta/meta.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unusedresult: result of fmt.Errorf call not used (govet)
}

if err := mngr.DropDistribution(ctx, stmt.ID); err != nil {
return cli.ReportError(err)
}
return cli.DropDistribution(ctx, []string{stmt.ID})
}

dss, err := mngr.ListDistributions(ctx)
if err != nil {
return err
}
ret := make([]string, 0)
if err != nil {
return err
}
for _, ds := range dss {
if stmt.ID == "*" && ds.Id != "default" {
if ds.Id != "default" {
if len(ds.Relations) != 0 && !isCascade {
fmt.Errorf("cannot drop distribution %s because there are relations attached to it\nHINT: Use DROP ... CASCADE to detach relations autoimatically", ds.ID)

Check failure on line 109 in pkg/meta/meta.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: fmt.Errorf format %s arg ds.ID is a func value, not called (govet)

Check failure on line 109 in pkg/meta/meta.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: fmt.Errorf format %s arg ds.ID is a func value, not called (govet)
}
ret = append(ret, ds.ID())
err = mngr.DropDistribution(ctx, ds.Id)
if err != nil {
Expand Down

0 comments on commit b0b5000

Please sign in to comment.