zrhoffman commented on a change in pull request #5071:
URL: https://github.com/apache/trafficcontrol/pull/5071#discussion_r501975728



##########
File path: traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
##########
@@ -423,6 +425,34 @@ func GetServerCapabilitiesFromName(name string, tx 
*sql.Tx) ([]string, error) {
        return caps, nil
 }
 
+const dsrExistsQuery = `
+SELECT EXISTS(
+       SELECT id
+       FROM deliveryservice_request
+       WHERE status <> 'complete' AND
+               status <> 'rejected' AND
+               (
+                       (change_type = 'delete' AND original->>'xmlId' = $1)
+                       OR
+                       (change_type <> 'delete' AND deliveryservice->>'xmlId' 
= $1)
+               )
+)
+`
+
+// DSRExistsWithXMLID returns whether or not an **open** Delivery Service
+// Request with the given xmlid exists, and any error that occurred.
+func DSRExistsWithXMLID(xmlid string, tx *sql.Tx) (bool, error) {
+       if tx == nil {
+               return false, errors.New("checking for DSR with nil 
transaction")
+       }
+
+       var exists bool
+       if err := tx.QueryRow(dsrExistsQuery, xmlid).Scan(&exists); err != nil {
+               return false, err
+       }
+       return exists, nil

Review comment:
       Whoops, yeah that's what I meant




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to