From 845d0340201db81e6c605537ef27ed13f946d892 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 5 May 2022 18:16:08 +0200 Subject: ... --- hosts/surtr/postgresql.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hosts/surtr/postgresql.nix b/hosts/surtr/postgresql.nix index ca56f60c..7b3b8c74 100644 --- a/hosts/surtr/postgresql.nix +++ b/hosts/surtr/postgresql.nix @@ -30,14 +30,17 @@ in { BEGIN; SELECT _v.register_patch('000-base', null, null); - CREATE TABLE virtual_mailbox ( + CREATE TABLE virtual_mailbox_mapping ( id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), local text CONSTRAINT local_non_empty CHECK (local IS DISTINCT FROM '''), domain text NOT NULL CONSTRAINT domain_non_empty CHECK (domain <> '''), mailbox text NOT NULL CONSTRAINT mailbox_non_empty CHECK (mailbox <> '''), CONSTRAINT local_domain_unique UNIQUE (local, domain) ); - CREATE UNIQUE INDEX domain_unique ON TABLE virtual_mailbox (domain) WHERE local IS NULL; + CREATE UNIQUE INDEX domain_unique ON virtual_mailbox_mapping (domain) WHERE local IS NULL; + + CREATE VIEW virtual_mailbox_domain (domain) AS SELECT DISTINCT domain FROM virtual_mailbox_mapping; + CREATE VIEW virtual_mailbox (mailbox) AS SELECT DISTINCT mailbox FROM virtual_mailbox_mapping; COMMIT; ''} ''; -- cgit v1.2.3