CREATE TABLE vmail_domain (
    id SERIAL,
    name character varying(100) NOT NULL,
    sys_user character varying(10) NOT NULL,
    sys_edit timestamp without time zone NOT NULL
);

CREATE UNIQUE INDEX vmail_domain_id ON vmail_domain USING btree (id);

CREATE TABLE vmail_user (
    id SERIAL,
    vmail_domain_id integer NOT NULL,
    username character varying(50) NOT NULL,
    password character varying(50),
    forward character varying(150),
    active integer DEFAULT 0 NOT NULL,
    sys_user character varying(10) NOT NULL,
    sys_edit timestamp without time zone NOT NULL
);

CREATE UNIQUE INDEX vmail_user_id ON vmail_user USING btree (id);
CREATE INDEX vmail_user_vmail_domain_id ON vmail_user USING btree (vmail_domain_id);

REVOKE ALL ON TABLE vmail_user FROM PUBLIC;
GRANT SELECT ON TABLE vmail_user TO "vmail";
GRANT ALL ON TABLE vmail_user TO "hallinta";

REVOKE ALL ON SEQUENCE vmail_user_id_seq FROM PUBLIC;
GRANT ALL ON SEQUENCE vmail_user_id_seq TO "hallinta";

REVOKE ALL ON TABLE vmail_domain FROM PUBLIC;
GRANT SELECT ON TABLE vmail_domain TO "vmail";
GRANT ALL ON TABLE vmail_domain TO "hallinta";

REVOKE ALL ON SEQUENCE vmail_domain_id_seq FROM PUBLIC;
GRANT ALL ON SEQUENCE vmail_domain_id_seq TO "hallinta";

