CREATE TABLE IF NOT EXISTS virtual_domains (
    id integer primary key generated by default as identity,
    name varchar(50) NOT NULL
);

CREATE TABLE IF NOT EXISTS virtual_users (
    id integer primary key generated by default as identity,
    domain_id integer NOT NULL,
    email varchar(254) NOT NULL,
    password varchar(150) NOT NULL,
    quota bigint NOT NULL DEFAULT 0,
    UNIQUE (email),
    FOREIGN KEY (domain_id) REFERENCES virtual_domains(id)
    ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS virtual_aliases (
    id integer primary key generated by default as identity,
    domain_id integer NOT NULL,
    source varchar(254) NOT NULL,
    destination varchar(254) NOT NULL,
    FOREIGN KEY (domain_id) REFERENCES virtual_domains(id)
    ON DELETE CASCADE
);
