From 66ee7bfe6e4ed7fd300dbcc8902bc77b57198d6f Mon Sep 17 00:00:00 2001 From: Joey Zhou Date: Thu, 9 Jan 2025 13:11:04 -0800 Subject: [PATCH 1/3] feat: db table changes for churn email column --- ...9140803_add_churn_prevention_email_sent.js | 25 +++++++++++++++++++ src/knex-tables.d.ts | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 src/db/migrations/20250109140803_add_churn_prevention_email_sent.js diff --git a/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js b/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js new file mode 100644 index 00000000000..20321b0fde8 --- /dev/null +++ b/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +export function up (knex) { + return knex.schema.table("subscribers", table => { + table.boolean("churn_prevention_email_sent").defaultTo(false); + table.index("churn_prevention_email_sent"); + }); +} + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +export function down (knex) { + return knex.schema.table("subscribers", table => { + table.dropIndex("churn_prevention_email_sent") + table.dropColumn("churn_prevention_email_sent"); + }); +} diff --git a/src/knex-tables.d.ts b/src/knex-tables.d.ts index b536c885ee5..35936cb46c5 100644 --- a/src/knex-tables.d.ts +++ b/src/knex-tables.d.ts @@ -152,6 +152,7 @@ declare module "knex/types/tables" { sign_in_count: null | number; email_addresses: SubscriberEmail[]; first_broker_removal_email_sent: boolean; + churn_prevention_email_sent: boolean; } type SubscriberOptionalColumns = Extract< keyof SubscriberRow, @@ -174,6 +175,7 @@ declare module "knex/types/tables" { | "onerep_profile_id" | "email_addresses" | "first_broker_removal_email_sent" + | "churn_prevention_email_sent" >; type SubscriberAutoInsertedColumns = Extract< keyof SubscriberRow, From 7209b75c7d1ea5055f27dffc6037e2b20aa252cd Mon Sep 17 00:00:00 2001 From: Joey Zhou Date: Thu, 9 Jan 2025 13:19:48 -0800 Subject: [PATCH 2/3] chore: fix lint --- .../user/(dashboard)/settings/SettingsPage.test.tsx | 1 + .../(dashboard)/settings/SettingsPageRedesign.test.tsx | 1 + src/utils/subscriberBreaches.test.ts | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx index d521ef41653..ef00ccd4eb7 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx @@ -137,6 +137,7 @@ const mockedSubscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; const mockedUser: Session["user"] = { diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx index 938e28cc898..ba42247aa58 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx @@ -141,6 +141,7 @@ const mockedSubscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; const mockedUser: Session["user"] = { diff --git a/src/utils/subscriberBreaches.test.ts b/src/utils/subscriberBreaches.test.ts index 552d5815a9a..d101a28764f 100644 --- a/src/utils/subscriberBreaches.test.ts +++ b/src/utils/subscriberBreaches.test.ts @@ -101,6 +101,7 @@ const subscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; const allBreaches: HibpLikeDbBreach[] = [ @@ -550,6 +551,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( @@ -649,6 +651,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( @@ -756,6 +759,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( @@ -873,6 +877,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( @@ -990,6 +995,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( @@ -1103,6 +1109,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, + churn_prevention_email_sent: false, }; ( From d5e8bab08bb142a69a4b7a15cdd075022a582c6e Mon Sep 17 00:00:00 2001 From: Joey Zhou Date: Mon, 13 Jan 2025 13:20:57 -0800 Subject: [PATCH 3/3] feat: move to using ts --- .../(dashboard)/settings/SettingsPage.test.tsx | 2 +- .../settings/SettingsPageRedesign.test.tsx | 2 +- ...250109140803_add_churn_prevention_email_sent.js | 8 ++++---- src/knex-tables.d.ts | 4 ++-- src/utils/subscriberBreaches.test.ts | 14 +++++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx index ef00ccd4eb7..2502ea84a9e 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPage.test.tsx @@ -137,7 +137,7 @@ const mockedSubscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; const mockedUser: Session["user"] = { diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx index ba42247aa58..e9bcf13bc24 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/SettingsPageRedesign.test.tsx @@ -141,7 +141,7 @@ const mockedSubscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; const mockedUser: Session["user"] = { diff --git a/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js b/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js index 20321b0fde8..dcc786424f3 100644 --- a/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js +++ b/src/db/migrations/20250109140803_add_churn_prevention_email_sent.js @@ -8,8 +8,8 @@ */ export function up (knex) { return knex.schema.table("subscribers", table => { - table.boolean("churn_prevention_email_sent").defaultTo(false); - table.index("churn_prevention_email_sent"); + table.timestamp("churn_prevention_email_sent_at"); + table.index("churn_prevention_email_sent_at"); }); } @@ -19,7 +19,7 @@ export function up (knex) { */ export function down (knex) { return knex.schema.table("subscribers", table => { - table.dropIndex("churn_prevention_email_sent") - table.dropColumn("churn_prevention_email_sent"); + table.dropIndex("churn_prevention_email_sent_at") + table.dropColumn("churn_prevention_email_sent_at"); }); } diff --git a/src/knex-tables.d.ts b/src/knex-tables.d.ts index 35936cb46c5..4e90667233c 100644 --- a/src/knex-tables.d.ts +++ b/src/knex-tables.d.ts @@ -152,7 +152,7 @@ declare module "knex/types/tables" { sign_in_count: null | number; email_addresses: SubscriberEmail[]; first_broker_removal_email_sent: boolean; - churn_prevention_email_sent: boolean; + churn_prevention_email_sent_at: null | Date; } type SubscriberOptionalColumns = Extract< keyof SubscriberRow, @@ -175,7 +175,7 @@ declare module "knex/types/tables" { | "onerep_profile_id" | "email_addresses" | "first_broker_removal_email_sent" - | "churn_prevention_email_sent" + | "churn_prevention_email_sent_at" >; type SubscriberAutoInsertedColumns = Extract< keyof SubscriberRow, diff --git a/src/utils/subscriberBreaches.test.ts b/src/utils/subscriberBreaches.test.ts index d101a28764f..5e38332e896 100644 --- a/src/utils/subscriberBreaches.test.ts +++ b/src/utils/subscriberBreaches.test.ts @@ -101,7 +101,7 @@ const subscriber: SubscriberRow = { monthly_monitor_report: false, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; const allBreaches: HibpLikeDbBreach[] = [ @@ -551,7 +551,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; ( @@ -651,7 +651,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; ( @@ -759,7 +759,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; ( @@ -877,7 +877,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; ( @@ -995,7 +995,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; ( @@ -1109,7 +1109,7 @@ describe("getSubBreaches", () => { onerep_profile_id: null, sign_in_count: null, first_broker_removal_email_sent: false, - churn_prevention_email_sent: false, + churn_prevention_email_sent_at: null, }; (