From 1f5a729a92a760afa3a7f0cce93ad17ada20073a Mon Sep 17 00:00:00 2001 From: Paul Brown Date: Thu, 20 Jul 2023 15:22:45 +0100 Subject: [PATCH 1/5] Fivetran cannot extract the reminder tables when the primary key is a string or compound key and not a UUID. This PR switches them round. The ALTER statements are in the PR description, but the table definitions have been updated in the code instead. --- sql/create-signups-tables.sql | 18 ++++++++++++------ src/create-reminder-signup/lib/db.ts | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sql/create-signups-tables.sql b/sql/create-signups-tables.sql index ba2a20e..6581581 100644 --- a/sql/create-signups-tables.sql +++ b/sql/create-signups-tables.sql @@ -11,17 +11,20 @@ CREATE TABLE one_off_reminder_signups( reminder_stage TEXT NOT NULL, reminder_period DATE NOT NULL, reminder_option TEXT, - reminder_code uuid NOT NULL UNIQUE DEFAULT uuid_generate_v4 (), + reminder_code uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4 (), created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), - PRIMARY KEY (identity_id, reminder_period) + UNIQUE KEY (identity_id, reminder_period) ); -CREATE INDEX one_off_reminder_signups_reminder_code ON one_off_reminder_signups (reminder_code); +/* PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table + - https://www.postgresql.org/docs/current/indexes-unique.html + */ +-- CREATE INDEX one_off_reminder_signups_reminder_code ON one_off_reminder_signups (identity_id); DROP TABLE IF EXISTS recurring_reminder_signups; CREATE TABLE recurring_reminder_signups( - identity_id TEXT NOT NULL PRIMARY KEY, + identity_id TEXT NOT NULL UNIQUE, country TEXT, reminder_created_at TIMESTAMP NOT NULL, reminder_cancelled_at TIMESTAMP, @@ -30,12 +33,15 @@ CREATE TABLE recurring_reminder_signups( reminder_stage TEXT NOT NULL, reminder_frequency_months INT NOT NULL, reminder_option TEXT, - reminder_code uuid NOT NULL UNIQUE DEFAULT uuid_generate_v4 (), + reminder_code uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4 (), created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW() ); -CREATE INDEX recurring_reminder_signups_reminder_code ON recurring_reminder_signups (reminder_code); +/* PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table + - https://www.postgresql.org/docs/current/indexes-unique.html + */ +-- CREATE INDEX recurring_reminder_signups_reminder_code ON recurring_reminder_signups (identity_id); CREATE OR REPLACE FUNCTION set_updated_at_column() RETURNS TRIGGER AS $$ diff --git a/src/create-reminder-signup/lib/db.ts b/src/create-reminder-signup/lib/db.ts index 1069c36..f07fd61 100644 --- a/src/create-reminder-signup/lib/db.ts +++ b/src/create-reminder-signup/lib/db.ts @@ -20,7 +20,7 @@ export function writeOneOffSignup( ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8 ) - ON CONFLICT ON CONSTRAINT one_off_reminder_signups_pkey + ON CONFLICT ON CONSTRAINT one_off_reminder_signups_identity_id_reminder_period_key DO UPDATE SET country = $2, @@ -65,7 +65,7 @@ export function writeRecurringSignup( ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8 ) - ON CONFLICT ON CONSTRAINT recurring_reminder_signups_pkey + ON CONFLICT ON CONSTRAINT recurring_reminder_signups_identity_id_key DO UPDATE SET country = $2, From ab5da4003eaa3315250414bcf909737ef8f234ef Mon Sep 17 00:00:00 2001 From: Paul Brown Date: Thu, 20 Jul 2023 15:36:50 +0100 Subject: [PATCH 2/5] Fix SQL --- sql/create-signups-tables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/create-signups-tables.sql b/sql/create-signups-tables.sql index 6581581..7625af1 100644 --- a/sql/create-signups-tables.sql +++ b/sql/create-signups-tables.sql @@ -14,7 +14,7 @@ CREATE TABLE one_off_reminder_signups( reminder_code uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4 (), created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), - UNIQUE KEY (identity_id, reminder_period) + UNIQUE (identity_id, reminder_period) ); /* PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table From fdc08667c8230c886404e832b1c900e3d601b2f5 Mon Sep 17 00:00:00 2001 From: Paul Brown Date: Thu, 20 Jul 2023 16:40:16 +0100 Subject: [PATCH 3/5] Upgrading to node 14 so that I can test this in CODE --- cdk/lib/support-reminders.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdk/lib/support-reminders.ts b/cdk/lib/support-reminders.ts index 7459cdb..482c1e9 100644 --- a/cdk/lib/support-reminders.ts +++ b/cdk/lib/support-reminders.ts @@ -32,7 +32,7 @@ export class SupportReminders extends GuStack { // ---- Miscellaneous constants ---- // const app = "support-reminders"; const vpc = GuVpc.fromIdParameter(this, "vpc"); - const runtime = Runtime.NODEJS_12_X; + const runtime = Runtime.NODEJS_14_X; const fileName = "support-reminders.zip"; const environment = { "Bucket": props.datalakeBucket, From eddbd2956f250a4698d35658bdb051d361fda69d Mon Sep 17 00:00:00 2001 From: Paul Brown Date: Thu, 20 Jul 2023 16:44:00 +0100 Subject: [PATCH 4/5] Upgrading to node 14 so that I can test this in CODE --- cdk/lib/__snapshots__/support-reminders.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdk/lib/__snapshots__/support-reminders.test.ts.snap b/cdk/lib/__snapshots__/support-reminders.test.ts.snap index d554be7..7e5250a 100644 --- a/cdk/lib/__snapshots__/support-reminders.test.ts.snap +++ b/cdk/lib/__snapshots__/support-reminders.test.ts.snap @@ -1372,7 +1372,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", From ce42ed6dd057e872ad1c8a0a146f958b57f659ae Mon Sep 17 00:00:00 2001 From: Paul Brown Date: Thu, 20 Jul 2023 16:49:45 +0100 Subject: [PATCH 5/5] So many definitions of the runtime! --- .../support-reminders.test.ts.snap | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cdk/lib/__snapshots__/support-reminders.test.ts.snap b/cdk/lib/__snapshots__/support-reminders.test.ts.snap index 7e5250a..2fc9a53 100644 --- a/cdk/lib/__snapshots__/support-reminders.test.ts.snap +++ b/cdk/lib/__snapshots__/support-reminders.test.ts.snap @@ -1602,7 +1602,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -1832,7 +1832,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -2207,7 +2207,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -2437,7 +2437,7 @@ exports[`The SupportReminders stack matches the snapshot 1`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -4158,7 +4158,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -4388,7 +4388,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -4618,7 +4618,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -4993,7 +4993,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App", @@ -5223,7 +5223,7 @@ exports[`The SupportReminders stack matches the snapshot 2`] = ` "Arn", ], }, - "Runtime": "nodejs12.x", + "Runtime": "nodejs14.x", "Tags": [ { "Key": "App",