Browse Source

Refactor subscriber delete query to support UUIDs

Kailash Nadh 6 years ago
parent
commit
81fe874ee7
2 changed files with 3 additions and 3 deletions
  1. 2 2
      queries.sql
  2. 1 1
      subscribers.go

+ 2 - 2
queries.sql

@@ -107,8 +107,8 @@ INSERT INTO subscriber_lists (subscriber_id, list_id, status)
     SET status = (CASE WHEN $4='blacklisted' THEN 'unsubscribed'::subscription_status ELSE 'unconfirmed' END);
 
 -- name: delete-subscribers
--- Delete one or more subscribers.
-DELETE FROM subscribers WHERE id = ANY($1);
+-- Delete one or more subscribers by ID or UUID.
+DELETE FROM subscribers WHERE CASE WHEN ARRAY_LENGTH($1::INT[], 1) > 0 THEN id = ANY($1) ELSE uuid = ANY($2::UUID[]) END;
 
 -- name: blacklist-subscribers
 WITH b AS (

+ 1 - 1
subscribers.go

@@ -327,7 +327,7 @@ func handleDeleteSubscribers(c echo.Context) error {
 		IDs = i
 	}
 
-	if _, err := app.Queries.DeleteSubscribers.Exec(IDs); err != nil {
+	if _, err := app.Queries.DeleteSubscribers.Exec(IDs, nil); err != nil {
 		return echo.NewHTTPError(http.StatusInternalServerError,
 			fmt.Sprintf("Error deleting: %v", err))
 	}