Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNTOR-1800: Part 1 - new table for subscriber email preferences #4972

Merged
merged 13 commits into from
Sep 5, 2024
23 changes: 23 additions & 0 deletions src/db/migrations/20240822032133_subscriber_email_preferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* 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/. */

export async function up(knex) {
await knex.schema
.createTable('subscriber_email_preferences', function(table) {
table.increments('id').primary();
table.integer("subscriber_id").references("subscribers.id").unique().notNullable().onDelete('CASCADE').onUpdate('CASCADE');
table.string('unsubscribe_token').unique();
table.boolean('monthly_monitor_report_free').defaultTo(true);
table.timestamp('monthly_monitor_report_free_at');
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex) {
return knex.schema
.dropTableIfExists("subscriber_email_preferences")
}
16 changes: 16 additions & 0 deletions src/knex-tables.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ declare module "knex/types/tables" {
"id" | "subscriber_id" | "created_at"
>;

interface SubscriberEmailPreferencesRow {
id: number;
subscriber_id: number;
unsubscribe_token: string;
monthly_monitor_report_free: boolean;
monthly_monitor_report_free_at: Date | null;
}

interface BreachRow {
id: number;
name: HibpGetBreachesResponse[number]["Name"];
Expand Down Expand Up @@ -397,6 +405,14 @@ declare module "knex/types/tables" {
WritableDateColumns<Partial<Omit<SubscriberCouponRow, "id">>>
>;

subscriber_email_preferences: Knex.CompositeTableType<
SubscriberEmailPreferencesRow,
// On inserts, auto-generated columns cannot be set, and nullable columns are optional:
WritableDateColumns<Omit<SubscriberEmailPreferencesRow, "id">>,
// On updates, don't allow updating the ID; all other fields are optional:
WritableDateColumns<Partial<Omit<SubscriberEmailPreferencesRow, "id">>>
>;

email_addresses: Knex.CompositeTableType<
EmailAddressRow,
// On inserts, auto-generated columns cannot be set, and nullable columns are optional:
Expand Down
Loading