wip
This commit is contained in:
parent
bcd2286de2
commit
d5c613f6e4
2 changed files with 45 additions and 0 deletions
|
@ -2,3 +2,42 @@ assert node.has_bundle('postfix')
|
|||
assert node.has_bundle('dovecot')
|
||||
assert node.has_bundle('letsencrypt')
|
||||
assert node.has_bundle('roundcube')
|
||||
|
||||
from shlex import quote
|
||||
|
||||
setup = '''
|
||||
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;
|
||||
'''
|
||||
|
||||
actions['initialize_mailserver_db'] = {
|
||||
'command': f'psql -d mailserver -c {quote(setup)}',
|
||||
'unless': f'psql -At -d mailserver -c "SELECT to_regclass(\'public.users\')" | grep -q \'^users$\'',
|
||||
'needs': [
|
||||
'postgres_db:mailserver',
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
# TEST
|
||||
'''
|
||||
INSERT INTO domains (id, name)
|
||||
VALUES (1, 'mails2.sublimity.de');
|
||||
INSERT INTO users (id, name, domain_id, password)
|
||||
VALUES (1, 'ckn', 1, MD5('test123'));
|
||||
'''
|
||||
|
|
|
@ -17,3 +17,9 @@ CREATE TABLE users (
|
|||
"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'));
|
Loading…
Reference in a new issue