From 1fc90598a21da74d8b5299c5ffb068138b306c2a Mon Sep 17 00:00:00 2001 From: Fredrik Ringqvist <35255659+fredrikphotowall@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:53:29 +0100 Subject: [PATCH] Create v_order_emails (#360) --- migrations/000.449.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 migrations/000.449.sql diff --git a/migrations/000.449.sql b/migrations/000.449.sql new file mode 100644 index 0000000..a82dfa6 --- /dev/null +++ b/migrations/000.449.sql @@ -0,0 +1,20 @@ +DROP VIEW IF EXISTS v_order_emails; +CREATE VIEW v_order_emails AS +select + orders.id order_id, + orders.inserted::date order_date, + billing.email billing_email, + billing.first_name billing_firstname, + billing.last_name billing_lastname +from + orders + left join addresses billing on billing_address_id = billing.id +where + orders.paid = 1 +; + +-- If we want to read this with direct access from BigQuery to Postgres: +-- CREATE USER bigquery WITH PASSWORD 'secret'; +-- GRANT SELECT ON v_order_emails TO bigquery; +-- GRANT USAGE ON SCHEMA public TO bigquery; +-- We don't need this now as we will access the view ourselves instead and get the results to BigQuery via S3.