sql/schéma.sql
author František Kučera <franta-hg@frantovo.cz>
Sun May 10 01:13:12 2009 +0200 (2009-05-10)
changeset 13 119744ae4179
parent 0 c83d559ca362
child 14 c830b05699ba
permissions -rw-r--r--
Odkaz na zdrojové kódy – do HTML komentáře
franta-hg@0
     1
--
franta-hg@0
     2
-- PostgreSQL database dump
franta-hg@0
     3
--
franta-hg@0
     4
franta-hg@12
     5
-- Started on 2009-05-06 02:13:29 CEST
franta-hg@0
     6
franta-hg@0
     7
SET client_encoding = 'UTF8';
franta-hg@0
     8
SET standard_conforming_strings = off;
franta-hg@0
     9
SET check_function_bodies = false;
franta-hg@0
    10
SET client_min_messages = warning;
franta-hg@0
    11
SET escape_string_warning = off;
franta-hg@0
    12
franta-hg@0
    13
--
franta-hg@12
    14
-- TOC entry 8 (class 2615 OID 16387)
franta-hg@0
    15
-- Name: posta; Type: SCHEMA; Schema: -; Owner: -
franta-hg@0
    16
--
franta-hg@0
    17
franta-hg@0
    18
CREATE SCHEMA posta;
franta-hg@0
    19
franta-hg@0
    20
franta-hg@0
    21
SET search_path = posta, pg_catalog;
franta-hg@0
    22
franta-hg@0
    23
--
franta-hg@12
    24
-- TOC entry 55 (class 1255 OID 16694)
franta-hg@12
    25
-- Dependencies: 364 8
franta-hg@0
    26
-- Name: zmen_heslo(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: posta; Owner: -
franta-hg@0
    27
--
franta-hg@0
    28
franta-hg@12
    29
CREATE FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) RETURNS text
franta-hg@12
    30
    AS $_$DECLARE pocet integer;
franta-hg@12
    31
BEGIN
franta-hg@12
    32
UPDATE uzivatel
franta-hg@0
    33
 SET heslo = md5($4)
franta-hg@0
    34
 WHERE 	login = $1
franta-hg@0
    35
	AND domena = $2
franta-hg@12
    36
	AND heslo = md5($3);
franta-hg@12
    37
	GET DIAGNOSTICS pocet = ROW_COUNT;
franta-hg@12
    38
	IF pocet = 1 THEN
franta-hg@12
    39
		RETURN 'Změna hesla pro ' || $1 || '@' || $2 || ' proběhla úspěšně.';
franta-hg@12
    40
	ELSE
franta-hg@12
    41
		RAISE EXCEPTION 'Nesprávné heslo, nebo uživatel % neexistuje', $1 || '@' || $2;
franta-hg@12
    42
	END IF;
franta-hg@12
    43
END;
franta-hg@12
    44
	$_$
franta-hg@12
    45
    LANGUAGE plpgsql SECURITY DEFINER;
franta-hg@0
    46
franta-hg@0
    47
franta-hg@0
    48
--
franta-hg@12
    49
-- TOC entry 1835 (class 0 OID 0)
franta-hg@12
    50
-- Dependencies: 55
franta-hg@0
    51
-- Name: FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying); Type: COMMENT; Schema: posta; Owner: -
franta-hg@0
    52
--
franta-hg@0
    53
franta-hg@0
    54
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.';
franta-hg@0
    55
franta-hg@0
    56
franta-hg@0
    57
SET default_tablespace = '';
franta-hg@0
    58
franta-hg@0
    59
SET default_with_oids = false;
franta-hg@0
    60
franta-hg@0
    61
--
franta-hg@12
    62
-- TOC entry 1549 (class 1259 OID 16550)
franta-hg@12
    63
-- Dependencies: 8
franta-hg@0
    64
-- Name: alias; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
    65
--
franta-hg@0
    66
franta-hg@0
    67
CREATE TABLE alias (
franta-hg@0
    68
    login character varying(255) NOT NULL,
franta-hg@0
    69
    domena character varying(255) NOT NULL,
franta-hg@0
    70
    cilova_adresa character varying(255) NOT NULL
franta-hg@0
    71
);
franta-hg@0
    72
franta-hg@0
    73
franta-hg@0
    74
--
franta-hg@12
    75
-- TOC entry 1536 (class 1259 OID 16396)
franta-hg@12
    76
-- Dependencies: 8
franta-hg@0
    77
-- Name: domena; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
    78
--
franta-hg@0
    79
franta-hg@0
    80
CREATE TABLE domena (
franta-hg@0
    81
    domena character varying(255) NOT NULL
franta-hg@0
    82
);
franta-hg@0
    83
franta-hg@0
    84
franta-hg@0
    85
--
franta-hg@12
    86
-- TOC entry 1537 (class 1259 OID 16409)
franta-hg@12
    87
-- Dependencies: 8
franta-hg@0
    88
-- Name: uzivatel; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
    89
--
franta-hg@0
    90
franta-hg@0
    91
CREATE TABLE uzivatel (
franta-hg@0
    92
    login character varying(255) NOT NULL,
franta-hg@0
    93
    heslo character varying(512),
franta-hg@0
    94
    domena character varying(255) NOT NULL
franta-hg@0
    95
);
franta-hg@0
    96
franta-hg@0
    97
franta-hg@0
    98
--
franta-hg@12
    99
-- TOC entry 1551 (class 1259 OID 16602)
franta-hg@12
   100
-- Dependencies: 1630 8
franta-hg@0
   101
-- Name: dovecot_heslo; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   102
--
franta-hg@0
   103
franta-hg@0
   104
CREATE VIEW dovecot_heslo AS
franta-hg@0
   105
    SELECT (((uzivatel.login)::text || '@'::text) || (uzivatel.domena)::text) AS "user", uzivatel.heslo AS password, uzivatel.login, uzivatel.domena FROM uzivatel;
franta-hg@0
   106
franta-hg@0
   107
franta-hg@0
   108
--
franta-hg@12
   109
-- TOC entry 1553 (class 1259 OID 16631)
franta-hg@12
   110
-- Dependencies: 1632 8
franta-hg@0
   111
-- Name: dovecot_uzivatel; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   112
--
franta-hg@0
   113
franta-hg@0
   114
CREATE VIEW dovecot_uzivatel AS
franta-hg@0
   115
    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;
franta-hg@0
   116
franta-hg@0
   117
franta-hg@0
   118
--
franta-hg@12
   119
-- TOC entry 1550 (class 1259 OID 16563)
franta-hg@12
   120
-- Dependencies: 1629 8
franta-hg@0
   121
-- Name: postfix_alias; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   122
--
franta-hg@0
   123
franta-hg@0
   124
CREATE VIEW postfix_alias AS
franta-hg@0
   125
    SELECT (((alias.login)::text || '@'::text) || (alias.domena)::text) AS zdroj, alias.cilova_adresa AS cil FROM alias;
franta-hg@0
   126
franta-hg@0
   127
franta-hg@0
   128
--
franta-hg@12
   129
-- TOC entry 1552 (class 1259 OID 16607)
franta-hg@12
   130
-- Dependencies: 1631 8
franta-hg@0
   131
-- Name: postfix_uzivatel; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   132
--
franta-hg@0
   133
franta-hg@0
   134
CREATE VIEW postfix_uzivatel AS
franta-hg@0
   135
    SELECT ((((uzivatel.domena)::text || '/'::text) || (uzivatel.login)::text) || '/Maildir/'::text) AS cesta, uzivatel.login, uzivatel.domena FROM uzivatel;
franta-hg@0
   136
franta-hg@0
   137
franta-hg@0
   138
--
franta-hg@12
   139
-- TOC entry 1829 (class 2606 OID 16557)
franta-hg@12
   140
-- Dependencies: 1549 1549 1549 1549
franta-hg@0
   141
-- Name: aliasy_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   142
--
franta-hg@0
   143
franta-hg@0
   144
ALTER TABLE ONLY alias
franta-hg@0
   145
    ADD CONSTRAINT aliasy_pk PRIMARY KEY (login, domena, cilova_adresa);
franta-hg@0
   146
franta-hg@0
   147
franta-hg@0
   148
--
franta-hg@12
   149
-- TOC entry 1825 (class 2606 OID 16400)
franta-hg@12
   150
-- Dependencies: 1536 1536
franta-hg@0
   151
-- Name: domena_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   152
--
franta-hg@0
   153
franta-hg@0
   154
ALTER TABLE ONLY domena
franta-hg@0
   155
    ADD CONSTRAINT domena_pk PRIMARY KEY (domena);
franta-hg@0
   156
franta-hg@0
   157
franta-hg@0
   158
--
franta-hg@12
   159
-- TOC entry 1827 (class 2606 OID 16416)
franta-hg@12
   160
-- Dependencies: 1537 1537 1537
franta-hg@0
   161
-- Name: uzivatel_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   162
--
franta-hg@0
   163
franta-hg@0
   164
ALTER TABLE ONLY uzivatel
franta-hg@0
   165
    ADD CONSTRAINT uzivatel_pk PRIMARY KEY (login, domena);
franta-hg@0
   166
franta-hg@0
   167
franta-hg@0
   168
--
franta-hg@12
   169
-- TOC entry 1831 (class 2606 OID 16558)
franta-hg@12
   170
-- Dependencies: 1824 1536 1549
franta-hg@0
   171
-- Name: alias_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
franta-hg@0
   172
--
franta-hg@0
   173
franta-hg@0
   174
ALTER TABLE ONLY alias
franta-hg@0
   175
    ADD CONSTRAINT alias_domena_fk FOREIGN KEY (domena) REFERENCES domena(domena);
franta-hg@0
   176
franta-hg@0
   177
franta-hg@0
   178
--
franta-hg@12
   179
-- TOC entry 1830 (class 2606 OID 16417)
franta-hg@12
   180
-- Dependencies: 1537 1536 1824
franta-hg@0
   181
-- Name: uzivatel_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
franta-hg@0
   182
--
franta-hg@0
   183
franta-hg@0
   184
ALTER TABLE ONLY uzivatel
franta-hg@0
   185
    ADD CONSTRAINT uzivatel_domena_fk FOREIGN KEY (domena) REFERENCES domena(domena);
franta-hg@0
   186
franta-hg@0
   187
franta-hg@0
   188
--
franta-hg@12
   189
-- TOC entry 1834 (class 0 OID 0)
franta-hg@12
   190
-- Dependencies: 8
franta-hg@0
   191
-- Name: posta; Type: ACL; Schema: -; Owner: -
franta-hg@0
   192
--
franta-hg@0
   193
franta-hg@0
   194
REVOKE ALL ON SCHEMA posta FROM PUBLIC;
franta-hg@0
   195
REVOKE ALL ON SCHEMA posta FROM posta;
franta-hg@0
   196
GRANT ALL ON SCHEMA posta TO posta;
franta-hg@0
   197
GRANT USAGE ON SCHEMA posta TO posta_cteni;
franta-hg@12
   198
GRANT USAGE ON SCHEMA posta TO posta_zmena_hesla;
franta-hg@0
   199
franta-hg@0
   200
franta-hg@0
   201
--
franta-hg@12
   202
-- TOC entry 1836 (class 0 OID 0)
franta-hg@12
   203
-- Dependencies: 55
franta-hg@12
   204
-- Name: zmen_heslo(character varying, character varying, character varying, character varying); Type: ACL; Schema: posta; Owner: -
franta-hg@12
   205
--
franta-hg@12
   206
franta-hg@12
   207
REVOKE ALL ON FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) FROM PUBLIC;
franta-hg@12
   208
REVOKE ALL ON FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) FROM posta;
franta-hg@12
   209
GRANT ALL ON FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) TO posta;
franta-hg@12
   210
GRANT ALL ON FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) TO PUBLIC;
franta-hg@12
   211
GRANT ALL ON FUNCTION zmen_heslo(login character varying, domena character varying, stare_heslo character varying, nove_heslo character varying) TO posta_zmena_hesla;
franta-hg@12
   212
franta-hg@12
   213
franta-hg@12
   214
--
franta-hg@12
   215
-- TOC entry 1837 (class 0 OID 0)
franta-hg@12
   216
-- Dependencies: 1549
franta-hg@0
   217
-- Name: alias; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   218
--
franta-hg@0
   219
franta-hg@0
   220
REVOKE ALL ON TABLE alias FROM PUBLIC;
franta-hg@0
   221
REVOKE ALL ON TABLE alias FROM posta;
franta-hg@0
   222
GRANT ALL ON TABLE alias TO posta;
franta-hg@0
   223
franta-hg@0
   224
franta-hg@0
   225
--
franta-hg@12
   226
-- TOC entry 1838 (class 0 OID 0)
franta-hg@12
   227
-- Dependencies: 1536
franta-hg@0
   228
-- Name: domena; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   229
--
franta-hg@0
   230
franta-hg@0
   231
REVOKE ALL ON TABLE domena FROM PUBLIC;
franta-hg@0
   232
REVOKE ALL ON TABLE domena FROM posta;
franta-hg@0
   233
GRANT ALL ON TABLE domena TO posta;
franta-hg@0
   234
GRANT SELECT ON TABLE domena TO posta_cteni;
franta-hg@0
   235
franta-hg@0
   236
franta-hg@0
   237
--
franta-hg@12
   238
-- TOC entry 1839 (class 0 OID 0)
franta-hg@12
   239
-- Dependencies: 1537
franta-hg@0
   240
-- Name: uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   241
--
franta-hg@0
   242
franta-hg@0
   243
REVOKE ALL ON TABLE uzivatel FROM PUBLIC;
franta-hg@0
   244
REVOKE ALL ON TABLE uzivatel FROM posta;
franta-hg@0
   245
GRANT ALL ON TABLE uzivatel TO posta;
franta-hg@0
   246
GRANT SELECT ON TABLE uzivatel TO posta_cteni;
franta-hg@0
   247
franta-hg@0
   248
franta-hg@0
   249
--
franta-hg@12
   250
-- TOC entry 1840 (class 0 OID 0)
franta-hg@12
   251
-- Dependencies: 1551
franta-hg@0
   252
-- Name: dovecot_heslo; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   253
--
franta-hg@0
   254
franta-hg@0
   255
REVOKE ALL ON TABLE dovecot_heslo FROM PUBLIC;
franta-hg@0
   256
REVOKE ALL ON TABLE dovecot_heslo FROM posta;
franta-hg@0
   257
GRANT ALL ON TABLE dovecot_heslo TO posta;
franta-hg@0
   258
GRANT SELECT ON TABLE dovecot_heslo TO posta_cteni;
franta-hg@0
   259
franta-hg@0
   260
franta-hg@0
   261
--
franta-hg@12
   262
-- TOC entry 1841 (class 0 OID 0)
franta-hg@12
   263
-- Dependencies: 1553
franta-hg@0
   264
-- Name: dovecot_uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   265
--
franta-hg@0
   266
franta-hg@0
   267
REVOKE ALL ON TABLE dovecot_uzivatel FROM PUBLIC;
franta-hg@0
   268
REVOKE ALL ON TABLE dovecot_uzivatel FROM posta;
franta-hg@0
   269
GRANT ALL ON TABLE dovecot_uzivatel TO posta;
franta-hg@0
   270
GRANT SELECT ON TABLE dovecot_uzivatel TO posta_cteni;
franta-hg@0
   271
franta-hg@0
   272
franta-hg@0
   273
--
franta-hg@12
   274
-- TOC entry 1842 (class 0 OID 0)
franta-hg@12
   275
-- Dependencies: 1550
franta-hg@0
   276
-- Name: postfix_alias; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   277
--
franta-hg@0
   278
franta-hg@0
   279
REVOKE ALL ON TABLE postfix_alias FROM PUBLIC;
franta-hg@0
   280
REVOKE ALL ON TABLE postfix_alias FROM posta;
franta-hg@0
   281
GRANT ALL ON TABLE postfix_alias TO posta;
franta-hg@0
   282
GRANT SELECT ON TABLE postfix_alias TO posta_cteni;
franta-hg@0
   283
franta-hg@0
   284
franta-hg@0
   285
--
franta-hg@12
   286
-- TOC entry 1843 (class 0 OID 0)
franta-hg@12
   287
-- Dependencies: 1552
franta-hg@0
   288
-- Name: postfix_uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   289
--
franta-hg@0
   290
franta-hg@0
   291
REVOKE ALL ON TABLE postfix_uzivatel FROM PUBLIC;
franta-hg@0
   292
REVOKE ALL ON TABLE postfix_uzivatel FROM posta;
franta-hg@0
   293
GRANT ALL ON TABLE postfix_uzivatel TO posta;
franta-hg@0
   294
GRANT SELECT ON TABLE postfix_uzivatel TO posta_cteni;
franta-hg@0
   295
franta-hg@0
   296
franta-hg@12
   297
-- Completed on 2009-05-06 02:13:36 CEST
franta-hg@0
   298
franta-hg@0
   299
--
franta-hg@0
   300
-- PostgreSQL database dump complete
franta-hg@0
   301
--
franta-hg@0
   302