--
-- PostgreSQL database dump
--

-- Started on 2009-08-28 17:21:16 CEST

SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 8 (class 2615 OID 16387)
-- Name: posta; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA posta;


SET search_path = posta, pg_catalog;

--
-- TOC entry 57 (class 1255 OID 16694)
-- Dependencies: 472 8
-- Name: zmen_heslo(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: posta; Owner: -
--

CREATE FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) RETURNS text
    AS $$DECLARE pocet integer;
BEGIN
UPDATE uzivatel
 SET heslo = md5("Nove_heslo")
 WHERE 	uzivatel.login = "Login"
	AND uzivatel.domena = "Domena"
	AND uzivatel.heslo = md5("Stare_heslo");
	GET DIAGNOSTICS pocet = ROW_COUNT;
	IF pocet = 1 THEN
		RETURN 'Změna hesla pro ' || "Login" || '@' || "Domena" || ' proběhla úspěšně.';
	ELSE
		RAISE EXCEPTION 'Nesprávné heslo, nebo uživatel % neexistuje', "Login" || '@' || "Domena";
	END IF;
END;
	$$
    LANGUAGE plpgsql SECURITY DEFINER;


--
-- TOC entry 1981 (class 0 OID 0)
-- Dependencies: 57
-- Name: FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying); Type: COMMENT; Schema: posta; Owner: -
--

COMMENT ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) IS 'Změní heslo uživatele.';


SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1657 (class 1259 OID 16550)
-- Dependencies: 8
-- Name: alias; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
--

CREATE TABLE alias (
    zdroj_jmeno character varying(255) NOT NULL,
    zdroj_domena character varying(255) NOT NULL,
    cil_jmeno character varying(255) NOT NULL,
    cil_domena character varying(255) NOT NULL
);


--
-- TOC entry 1983 (class 0 OID 0)
-- Dependencies: 1657
-- Name: COLUMN alias.zdroj_jmeno; Type: COMMENT; Schema: posta; Owner: -
--

COMMENT ON COLUMN alias.zdroj_jmeno IS 'Část zdrojové adresy před zavináčem.
(sem přijde zpráva)';


--
-- TOC entry 1984 (class 0 OID 0)
-- Dependencies: 1657
-- Name: COLUMN alias.zdroj_domena; Type: COMMENT; Schema: posta; Owner: -
--

COMMENT ON COLUMN alias.zdroj_domena IS 'Část zdrojové adresy za zavináčem.
(sem přijde zpráva)';


--
-- TOC entry 1985 (class 0 OID 0)
-- Dependencies: 1657
-- Name: COLUMN alias.cil_jmeno; Type: COMMENT; Schema: posta; Owner: -
--

COMMENT ON COLUMN alias.cil_jmeno IS 'Část cílové adresy před zavináčem.
(sem zprávu předáme)';


--
-- TOC entry 1986 (class 0 OID 0)
-- Dependencies: 1657
-- Name: COLUMN alias.cil_domena; Type: COMMENT; Schema: posta; Owner: -
--

COMMENT ON COLUMN alias.cil_domena IS 'Část cílové adresy za zavináčem.
(sem zprávu předáme)';


--
-- TOC entry 1644 (class 1259 OID 16396)
-- Dependencies: 8
-- Name: domena; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
--

CREATE TABLE domena (
    domena character varying(255) NOT NULL
);


--
-- TOC entry 1645 (class 1259 OID 16409)
-- Dependencies: 8
-- Name: uzivatel; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
--

CREATE TABLE uzivatel (
    login character varying(255) NOT NULL,
    heslo character varying(512),
    domena character varying(255) NOT NULL
);


--
-- TOC entry 1658 (class 1259 OID 16602)
-- Dependencies: 1775 8
-- Name: dovecot_heslo; Type: VIEW; Schema: posta; Owner: -
--

CREATE VIEW dovecot_heslo AS
    SELECT (((uzivatel.login)::text || '@'::text) || (uzivatel.domena)::text) AS "user", uzivatel.heslo AS password, uzivatel.login, uzivatel.domena FROM uzivatel;


--
-- TOC entry 1660 (class 1259 OID 16631)
-- Dependencies: 1777 8
-- Name: dovecot_uzivatel; Type: VIEW; Schema: posta; Owner: -
--

CREATE VIEW dovecot_uzivatel AS
    SELECT 5000 AS uid, 5000 AS gid, ((('/var/mail/virtualniposta/'::text || (uzivatel.domena)::text) || '/'::text) || (uzivatel.login)::text) AS home, (((('maildir:/var/mail/virtualniposta/'::text || (uzivatel.domena)::text) || '/'::text) || (uzivatel.login)::text) || '/Maildir'::text) AS mail, 'maildir:storage=524288'::text AS quota, uzivatel.login, uzivatel.domena FROM uzivatel;


--
-- TOC entry 1661 (class 1259 OID 16695)
-- Dependencies: 1778 8
-- Name: postfix_alias; Type: VIEW; Schema: posta; Owner: -
--

CREATE VIEW postfix_alias AS
    SELECT (((alias.zdroj_jmeno)::text || '@'::text) || (alias.zdroj_domena)::text) AS zdroj, (((alias.cil_jmeno)::text || '@'::text) || (alias.cil_domena)::text) AS cil FROM alias;


--
-- TOC entry 1659 (class 1259 OID 16607)
-- Dependencies: 1776 8
-- Name: postfix_uzivatel; Type: VIEW; Schema: posta; Owner: -
--

CREATE VIEW postfix_uzivatel AS
    SELECT ((((uzivatel.domena)::text || '/'::text) || (uzivatel.login)::text) || '/Maildir/'::text) AS cesta, uzivatel.login, uzivatel.domena FROM uzivatel;


--
-- TOC entry 1975 (class 2606 OID 17071)
-- Dependencies: 1657 1657 1657 1657 1657
-- Name: aliasy_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
--

ALTER TABLE ONLY alias
    ADD CONSTRAINT aliasy_pk PRIMARY KEY (zdroj_jmeno, zdroj_domena, cil_jmeno, cil_domena);


--
-- TOC entry 1971 (class 2606 OID 16400)
-- Dependencies: 1644 1644
-- Name: domena_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
--

ALTER TABLE ONLY domena
    ADD CONSTRAINT domena_pk PRIMARY KEY (domena);


--
-- TOC entry 1973 (class 2606 OID 16416)
-- Dependencies: 1645 1645 1645
-- Name: uzivatel_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
--

ALTER TABLE ONLY uzivatel
    ADD CONSTRAINT uzivatel_pk PRIMARY KEY (login, domena);


--
-- TOC entry 1977 (class 2606 OID 16558)
-- Dependencies: 1657 1970 1644
-- Name: alias_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
--

ALTER TABLE ONLY alias
    ADD CONSTRAINT alias_domena_fk FOREIGN KEY (zdroj_domena) REFERENCES domena(domena);


--
-- TOC entry 1976 (class 2606 OID 16417)
-- Dependencies: 1644 1645 1970
-- Name: uzivatel_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
--

ALTER TABLE ONLY uzivatel
    ADD CONSTRAINT uzivatel_domena_fk FOREIGN KEY (domena) REFERENCES domena(domena);


--
-- TOC entry 1980 (class 0 OID 0)
-- Dependencies: 8
-- Name: posta; Type: ACL; Schema: -; Owner: -
--

REVOKE ALL ON SCHEMA posta FROM PUBLIC;
REVOKE ALL ON SCHEMA posta FROM posta;
GRANT ALL ON SCHEMA posta TO posta;
GRANT USAGE ON SCHEMA posta TO posta_cteni;
GRANT USAGE ON SCHEMA posta TO posta_zmena_hesla;


--
-- TOC entry 1982 (class 0 OID 0)
-- Dependencies: 57
-- Name: zmen_heslo(character varying, character varying, character varying, character varying); Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) FROM PUBLIC;
REVOKE ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) FROM posta;
GRANT ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) TO posta;
GRANT ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) TO PUBLIC;
GRANT ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) TO posta_zmena_hesla;


--
-- TOC entry 1987 (class 0 OID 0)
-- Dependencies: 1657
-- Name: alias; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE alias FROM PUBLIC;
REVOKE ALL ON TABLE alias FROM posta;
GRANT ALL ON TABLE alias TO posta;


--
-- TOC entry 1988 (class 0 OID 0)
-- Dependencies: 1644
-- Name: domena; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE domena FROM PUBLIC;
REVOKE ALL ON TABLE domena FROM posta;
GRANT ALL ON TABLE domena TO posta;
GRANT SELECT ON TABLE domena TO posta_cteni;


--
-- TOC entry 1989 (class 0 OID 0)
-- Dependencies: 1645
-- Name: uzivatel; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE uzivatel FROM PUBLIC;
REVOKE ALL ON TABLE uzivatel FROM posta;
GRANT ALL ON TABLE uzivatel TO posta;
GRANT SELECT ON TABLE uzivatel TO posta_cteni;


--
-- TOC entry 1990 (class 0 OID 0)
-- Dependencies: 1658
-- Name: dovecot_heslo; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE dovecot_heslo FROM PUBLIC;
REVOKE ALL ON TABLE dovecot_heslo FROM posta;
GRANT ALL ON TABLE dovecot_heslo TO posta;
GRANT SELECT ON TABLE dovecot_heslo TO posta_cteni;


--
-- TOC entry 1991 (class 0 OID 0)
-- Dependencies: 1660
-- Name: dovecot_uzivatel; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE dovecot_uzivatel FROM PUBLIC;
REVOKE ALL ON TABLE dovecot_uzivatel FROM posta;
GRANT ALL ON TABLE dovecot_uzivatel TO posta;
GRANT SELECT ON TABLE dovecot_uzivatel TO posta_cteni;


--
-- TOC entry 1992 (class 0 OID 0)
-- Dependencies: 1661
-- Name: postfix_alias; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE postfix_alias FROM PUBLIC;
REVOKE ALL ON TABLE postfix_alias FROM posta;
GRANT ALL ON TABLE postfix_alias TO posta;
GRANT SELECT ON TABLE postfix_alias TO posta_cteni;


--
-- TOC entry 1993 (class 0 OID 0)
-- Dependencies: 1659
-- Name: postfix_uzivatel; Type: ACL; Schema: posta; Owner: -
--

REVOKE ALL ON TABLE postfix_uzivatel FROM PUBLIC;
REVOKE ALL ON TABLE postfix_uzivatel FROM posta;
GRANT ALL ON TABLE postfix_uzivatel TO posta;
GRANT SELECT ON TABLE postfix_uzivatel TO posta_cteni;


-- Completed on 2009-08-28 17:21:17 CEST

--
-- PostgreSQL database dump complete
--

