From c492400cea65f3e939166ced8a19d5a90990e372 Mon Sep 17 00:00:00 2001 From: Fredrik Ringqvist <35255659+fredrikphotowall@users.noreply.github.com> Date: Mon, 17 Oct 2022 12:07:13 +0200 Subject: [PATCH] Create delayed_order_emails table (#296) --- migrations/000.392.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 migrations/000.392.sql diff --git a/migrations/000.392.sql b/migrations/000.392.sql new file mode 100644 index 0000000..527dc3b --- /dev/null +++ b/migrations/000.392.sql @@ -0,0 +1,17 @@ +-- Delayed order emails table + +CREATE TYPE delayed_orders_email_type AS ENUM ('automatic', 'manual'); +CREATE TYPE delayed_orders_email_status as ENUM ('created', 'sent', 'error', 'blocked'); + +CREATE TABLE delayed_orders_email ( + id SERIAL PRIMARY KEY, + order_id int REFERENCES orders (id) NOT NULL, + type delayed_orders_email_type NOT NULL, + status delayed_orders_email_status NOT NULL, + date timestamp with time zone DEFAULT now() +); + +-- This creates a partial unique constraint. +-- It enforces max one automatic email; allows multiple manual emails; enables blocking automatic email. +CREATE UNIQUE INDEX unique_automatic_delayed_orders_emails ON delayed_orders_email (order_id) WHERE (type = 'automatic'); +