This commit is contained in:
mwiegand 2021-06-14 19:04:41 +02:00
parent d5c613f6e4
commit c7ad365846
4 changed files with 7 additions and 28 deletions

View file

@ -19,7 +19,7 @@ setup = '''
CONSTRAINT "fk_domain"
FOREIGN KEY("domain_id")
REFERENCES domains("id"),
"password" varchar(255) NOT NULL,
"password" varchar(255) NULL,
"redirect" varchar(255) DEFAULT NULL
);
CREATE UNIQUE INDEX ON users ("name", "domain_id") WHERE "redirect" IS NULL;
@ -36,8 +36,12 @@ actions['initialize_mailserver_db'] = {
# TEST
'''
DROP TABLE users; DROP TABLE domains;
INSERT INTO domains (id, name)
VALUES (1, 'mails2.sublimity.de');
INSERT INTO users (id, name, domain_id, password)
VALUES (1, 'ckn', 1, MD5('test123'));
INSERT INTO users (id, name, domain_id, redirect)
VALUES (1, 'weg', 1, 'irgendweo@gmail.com');
'''

View file

@ -2,4 +2,4 @@ hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT redirect FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)
query = SELECT redirect FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE redirect IS NOT NULL AND users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)

View file

@ -2,4 +2,4 @@ hosts = ${host}
dbname = ${name}
user = ${user}
password = ${password}
query = SELECT CONCAT(users.name, '@', domains.name) AS email FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)
query = SELECT CONCAT(users.name, '@', domains.name) AS email FROM users LEFT JOIN domains ON users.domain_id = domains.id WHERE redirect IS NULL AND users.name = SPLIT_PART('%s', '@', 1) AND domains.name = SPLIT_PART('%s', '@', 2)

View file

@ -1,25 +0,0 @@
DROP TABLE users; DROP TABLE domains;
CREATE TABLE domains (
"id" BIGSERIAL PRIMARY KEY,
"name" varchar(255) UNIQUE NOT NULL
);
CREATE INDEX ON domains ("name");
CREATE TABLE users (
"id" BIGSERIAL PRIMARY KEY,
"name" varchar(255) NOT NULL,
"domain_id" BIGSERIAL NOT NULL,
CONSTRAINT "fk_domain"
FOREIGN KEY("domain_id")
REFERENCES domains("id"),
"password" varchar(255) NOT NULL,
"redirect" varchar(255) DEFAULT NULL
);
CREATE UNIQUE INDEX ON users ("name", "domain_id") WHERE "redirect" IS NULL;
INSERT INTO domains (id, name)
VALUES (1, 'mails2.sublimity.de');
INSERT INTO users (id, name, domain_id, password)
VALUES (1, 'ckn', 1, MD5('test123'));