Deleting Apps

Overview

The following steps are a recipe to delete an app.

The steps were documented while working on SUITEDEV-19730.

The recipe contains the queries and commands while working on the issue and values like customer_id, app_code, …​ were not substituted with placeholders.

If the deleting of apps has to be done on a regular basis a script must be developed to automate the steps.

Known Issues

  • Delete In-App Campaigns

  • Delete Inbox Campaigns

These were not needed when working on the issue.

Soft-Delete the Push Campaigns

Push service has an endpoint to delete and campaign (it’s soft-deleted). The endpoint checks if the campaign is used in an AC program and cancels the campaign in scheduler when it is scheduled.

Getting the campaign ids

select id from campaigns where application_id in (select id from applications where customer_id = 799943121 and app_code not in ('EMS2E-E3B36','EMSDE-9AA11','EMS70-188A3','EMSFD-02A01')) and status!='deleted' order by id;

Getting the authorization header

  • Login as the customer

  • Copy cookie (in Chrome I had to open the request to get the campaigns in a new tab to see the correct request headers)

Deleting the campaigns

#!/usr/bin/env bash

function deleteCampaign() {
  id=$1

  echo $id
  http --verbose DELETE https://push.eservice.emarsys.net/api/campaigns/$id Cookie:'koa:sess=...; koa:sess.sig=...;'
  echo
}

for id in 71168 71218 71229 71230 73033 73036 73038 73063 73064 73081 73083 73087 73096 73099 73115 73116 73117 73137 73146 73200 73203 73214 73215 73216 73232 73247 73251 73255 73259 73262 73264 73267 73273 73277 73282 73283 73886 73901 73906 73911 73916 73948 73998 73999 74011 74060 74144 74145 74147 74154 74167 74173 74237 74779 75880 76018 76021 76029 76076 76082 76091 76744 77330 77332 77416 77710 77713 77715 77716 79137 79528 79572 79575 79585 79587 79779; do deleteCampaign $id; done

Hard-Delete the Push Campaigns

Backup

heroku pg:backups:capture --app ems-push-notification

Keep the campaign ids

Store the campaign ids in a text file because we need it later.

SQL

begin;
delete from campaigns where application_id in (select id from applications where customer_id = 799943121 and app_code not in ('EMS2E-E3B36','EMSDE-9AA11','EMS70-188A3','EMSFD-02A01')) and status='deleted';
commit;

Delete Apps

Keep Application Id and Code, suite fields

Store the application id, code and suite field ids in a text file because we need it later.

begin;
select contact_hardware_id, contact_field_app_installed, contact_field_push_accepted, contact_field_last_mobile_activity from applications where customer_id = 799943121 and app_code not in ('EMS2E-E3B36','EMSDE-9AA11','EMS70-188A3','EMSFD-02A01');
commit;

Delete apps in push database

begin;
delete from applications where customer_id = 799943121 and app_code not in ('EMS2E-E3B36','EMSDE-9AA11','EMS70-188A3','EMSFD-02A01');
commit;

SDK Events

Backup

Backup Redis in compose

Delete SDK logs and device logs

redis-cli -u 'redis://admin:***@aws-eu-central-1-portal.0.dblayer.com:15809'
del sdklogs:1083 sdklogs:1084 sdklogs:1148 sdklogs:1149 sdklogs:1163 sdklogs:1165 sdklogs:1180 sdklogs:1188
del devicelog:1083 devicelog:1084 devicelog:1148 devicelog:1149 devicelog:1163 devicelog:1165 devicelog:1180 devicelog:1188

Delivery

There is an endpoint POST /api/:customerId/credentials/delete which needs the applicationId and the platform. It only removes the platform and does not remove the whole object.

Backup

Backup ems-me-delivery Mongo in compose

Delete objects

mongo 'mongodb://me-delivery:***@portal-ssl2953-0.ems-me-delivery.3910074919.composedb.com:20542,portal-ssl2494-2.ems-me-delivery.3910074919.composedb.com:20542/me-delivery?authSource=me-delivery&ssl=true'
db.credentials.deleteOne( { applicationId: 1083 } )
db.credentials.deleteOne( { applicationId: 1084 } )
db.credentials.deleteOne( { applicationId: 1148 } )
db.credentials.deleteOne( { applicationId: 1149 } )
db.credentials.deleteOne( { applicationId: 1163 } )
db.credentials.deleteOne( { applicationId: 1165 } )
db.credentials.deleteOne( { applicationId: 1180 } )
db.credentials.deleteOne( { applicationId: 1188 } )

Stats

Backup

Delete objects

mongo 'mongodb://ems-me-stats:***@portal-ssl895-10.ems-me-stats-mongo.emarsys-technologies-ltd.composedb.com:16004,aws-eu-west-1-portal.7.dblayer.com:16004/mobile-engage-statistics?ssl=true'

Statistics

db.statistics.deleteMany({ campaignId: 70641})
db.statistics.deleteMany({ campaignId: 70696})
db.statistics.deleteMany({ campaignId: 70699})
...

Device Statistics

db.devices.deleteOne({ customerId: 799943121, applicationId: 1083 })
...

DynamoDB

A full table scan is required to search for all uid which start with a certain application code. Since DynamoDB is mainly billed by data read/written it’s better to just leave the stale data in DynamoDB.

Suite

Remove application fields that were queried before https://dev.emarsys.com/v2/fields/delete-a-field.

Manually, the easiest way is to use the api-demo page: https://suite38.emarsys.net/api-demo/#tab-field