diff --git a/db/DB.js b/db/DB.js index f48ce987c..25f217618 100644 --- a/db/DB.js +++ b/db/DB.js @@ -428,6 +428,10 @@ const DB = { await knex("subscribers").where("fxa_uid", fxaUID).del(); }, + async deleteEmailAddressesByUid(uid) { + await knex("email_addresses").where({"subscriber_id": uid}).del(); + }, + async createConnection() { if (knex === null) { knex = Knex(knexConfig); diff --git a/scripts/delete-user.js b/scripts/delete-user.js new file mode 100644 index 000000000..ca81dfbbf --- /dev/null +++ b/scripts/delete-user.js @@ -0,0 +1,32 @@ +"use strict"; + +const readline = require("readline"); + +const DB = require("../db/DB"); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +(async () => { + rl.question("What FXA primary email address? ", first_answer => { + rl.question("Please re-type the email address to confirm. ", async (second_answer) => { + if (first_answer !== second_answer) { + console.error("Email addresses do not match."); + process.exit(1); + } + + const subscriber = await DB.getSubscriberByEmail(second_answer); + if (!subscriber) { + console.error("Could not find subscriber."); + process.exit(1); + } + + await DB.deleteEmailAddressesByUid(subscriber.id); + await DB.deleteSubscriberByFxAUID(subscriber.fxa_uid); + console.log("Deleted email_addresses and subscribers records."); + process.exit(); + }); + }); +})();