sql/schéma.sql
author František Kučera <franta-hg@frantovo.cz>
Wed, 30 Nov 2011 15:40:16 +0100
changeset 20 2a00ee0b740a
parent 17 693f2b2587aa
child 24 571d9fd2d336
permissions -rw-r--r--
doručenky milter a sieve
franta-hg@0
     1
--
franta-hg@0
     2
-- PostgreSQL database dump
franta-hg@0
     3
--
franta-hg@0
     4
franta-hg@17
     5
-- Started on 2009-08-28 17:21:16 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@17
    24
-- TOC entry 57 (class 1255 OID 16694)
franta-hg@17
    25
-- Dependencies: 472 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@16
    29
CREATE FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) RETURNS text
franta-hg@17
    30
    AS $$DECLARE pocet integer;
franta-hg@12
    31
BEGIN
franta-hg@12
    32
UPDATE uzivatel
franta-hg@16
    33
 SET heslo = md5("Nove_heslo")
franta-hg@16
    34
 WHERE 	uzivatel.login = "Login"
franta-hg@16
    35
	AND uzivatel.domena = "Domena"
franta-hg@16
    36
	AND uzivatel.heslo = md5("Stare_heslo");
franta-hg@12
    37
	GET DIAGNOSTICS pocet = ROW_COUNT;
franta-hg@12
    38
	IF pocet = 1 THEN
franta-hg@17
    39
		RETURN 'Změna hesla pro ' || "Login" || '@' || "Domena" || ' proběhla úspěšně.';
franta-hg@12
    40
	ELSE
franta-hg@17
    41
		RAISE EXCEPTION 'Nesprávné heslo, nebo uživatel % neexistuje', "Login" || '@' || "Domena";
franta-hg@12
    42
	END IF;
franta-hg@12
    43
END;
franta-hg@17
    44
	$$
franta-hg@12
    45
    LANGUAGE plpgsql SECURITY DEFINER;
franta-hg@0
    46
franta-hg@0
    47
franta-hg@0
    48
--
franta-hg@17
    49
-- TOC entry 1981 (class 0 OID 0)
franta-hg@17
    50
-- Dependencies: 57
franta-hg@16
    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@16
    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@17
    62
-- TOC entry 1657 (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@14
    68
    zdroj_jmeno character varying(255) NOT NULL,
franta-hg@14
    69
    zdroj_domena character varying(255) NOT NULL,
franta-hg@14
    70
    cil_jmeno character varying(255) NOT NULL,
franta-hg@17
    71
    cil_domena character varying(255) NOT NULL
franta-hg@0
    72
);
franta-hg@0
    73
franta-hg@0
    74
franta-hg@0
    75
--
franta-hg@17
    76
-- TOC entry 1983 (class 0 OID 0)
franta-hg@17
    77
-- Dependencies: 1657
franta-hg@14
    78
-- Name: COLUMN alias.zdroj_jmeno; Type: COMMENT; Schema: posta; Owner: -
franta-hg@14
    79
--
franta-hg@14
    80
franta-hg@15
    81
COMMENT ON COLUMN alias.zdroj_jmeno IS 'Část zdrojové adresy před zavináčem.
franta-hg@15
    82
(sem přijde zpráva)';
franta-hg@14
    83
franta-hg@14
    84
franta-hg@14
    85
--
franta-hg@17
    86
-- TOC entry 1984 (class 0 OID 0)
franta-hg@17
    87
-- Dependencies: 1657
franta-hg@14
    88
-- Name: COLUMN alias.zdroj_domena; Type: COMMENT; Schema: posta; Owner: -
franta-hg@14
    89
--
franta-hg@14
    90
franta-hg@15
    91
COMMENT ON COLUMN alias.zdroj_domena IS 'Část zdrojové adresy za zavináčem.
franta-hg@15
    92
(sem přijde zpráva)';
franta-hg@14
    93
franta-hg@14
    94
franta-hg@14
    95
--
franta-hg@17
    96
-- TOC entry 1985 (class 0 OID 0)
franta-hg@17
    97
-- Dependencies: 1657
franta-hg@14
    98
-- Name: COLUMN alias.cil_jmeno; Type: COMMENT; Schema: posta; Owner: -
franta-hg@14
    99
--
franta-hg@14
   100
franta-hg@15
   101
COMMENT ON COLUMN alias.cil_jmeno IS 'Část cílové adresy před zavináčem.
franta-hg@14
   102
(sem zprávu předáme)';
franta-hg@14
   103
franta-hg@14
   104
franta-hg@14
   105
--
franta-hg@17
   106
-- TOC entry 1986 (class 0 OID 0)
franta-hg@17
   107
-- Dependencies: 1657
franta-hg@14
   108
-- Name: COLUMN alias.cil_domena; Type: COMMENT; Schema: posta; Owner: -
franta-hg@14
   109
--
franta-hg@14
   110
franta-hg@15
   111
COMMENT ON COLUMN alias.cil_domena IS 'Část cílové adresy za zavináčem.
franta-hg@14
   112
(sem zprávu předáme)';
franta-hg@14
   113
franta-hg@14
   114
franta-hg@14
   115
--
franta-hg@17
   116
-- TOC entry 1644 (class 1259 OID 16396)
franta-hg@12
   117
-- Dependencies: 8
franta-hg@0
   118
-- Name: domena; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   119
--
franta-hg@0
   120
franta-hg@0
   121
CREATE TABLE domena (
franta-hg@0
   122
    domena character varying(255) NOT NULL
franta-hg@0
   123
);
franta-hg@0
   124
franta-hg@0
   125
franta-hg@0
   126
--
franta-hg@17
   127
-- TOC entry 1645 (class 1259 OID 16409)
franta-hg@12
   128
-- Dependencies: 8
franta-hg@0
   129
-- Name: uzivatel; Type: TABLE; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   130
--
franta-hg@0
   131
franta-hg@0
   132
CREATE TABLE uzivatel (
franta-hg@0
   133
    login character varying(255) NOT NULL,
franta-hg@0
   134
    heslo character varying(512),
franta-hg@0
   135
    domena character varying(255) NOT NULL
franta-hg@0
   136
);
franta-hg@0
   137
franta-hg@0
   138
franta-hg@0
   139
--
franta-hg@17
   140
-- TOC entry 1658 (class 1259 OID 16602)
franta-hg@17
   141
-- Dependencies: 1775 8
franta-hg@0
   142
-- Name: dovecot_heslo; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   143
--
franta-hg@0
   144
franta-hg@0
   145
CREATE VIEW dovecot_heslo AS
franta-hg@0
   146
    SELECT (((uzivatel.login)::text || '@'::text) || (uzivatel.domena)::text) AS "user", uzivatel.heslo AS password, uzivatel.login, uzivatel.domena FROM uzivatel;
franta-hg@0
   147
franta-hg@0
   148
franta-hg@0
   149
--
franta-hg@17
   150
-- TOC entry 1660 (class 1259 OID 16631)
franta-hg@17
   151
-- Dependencies: 1777 8
franta-hg@0
   152
-- Name: dovecot_uzivatel; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   153
--
franta-hg@0
   154
franta-hg@0
   155
CREATE VIEW dovecot_uzivatel AS
franta-hg@0
   156
    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
   157
franta-hg@0
   158
franta-hg@0
   159
--
franta-hg@17
   160
-- TOC entry 1661 (class 1259 OID 16695)
franta-hg@17
   161
-- Dependencies: 1778 8
franta-hg@0
   162
-- Name: postfix_alias; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   163
--
franta-hg@0
   164
franta-hg@0
   165
CREATE VIEW postfix_alias AS
franta-hg@14
   166
    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;
franta-hg@0
   167
franta-hg@0
   168
franta-hg@0
   169
--
franta-hg@17
   170
-- TOC entry 1659 (class 1259 OID 16607)
franta-hg@17
   171
-- Dependencies: 1776 8
franta-hg@0
   172
-- Name: postfix_uzivatel; Type: VIEW; Schema: posta; Owner: -
franta-hg@0
   173
--
franta-hg@0
   174
franta-hg@0
   175
CREATE VIEW postfix_uzivatel AS
franta-hg@0
   176
    SELECT ((((uzivatel.domena)::text || '/'::text) || (uzivatel.login)::text) || '/Maildir/'::text) AS cesta, uzivatel.login, uzivatel.domena FROM uzivatel;
franta-hg@0
   177
franta-hg@0
   178
franta-hg@0
   179
--
franta-hg@17
   180
-- TOC entry 1975 (class 2606 OID 17071)
franta-hg@17
   181
-- Dependencies: 1657 1657 1657 1657 1657
franta-hg@0
   182
-- Name: aliasy_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   183
--
franta-hg@0
   184
franta-hg@0
   185
ALTER TABLE ONLY alias
franta-hg@17
   186
    ADD CONSTRAINT aliasy_pk PRIMARY KEY (zdroj_jmeno, zdroj_domena, cil_jmeno, cil_domena);
franta-hg@0
   187
franta-hg@0
   188
franta-hg@0
   189
--
franta-hg@17
   190
-- TOC entry 1971 (class 2606 OID 16400)
franta-hg@17
   191
-- Dependencies: 1644 1644
franta-hg@0
   192
-- Name: domena_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   193
--
franta-hg@0
   194
franta-hg@0
   195
ALTER TABLE ONLY domena
franta-hg@0
   196
    ADD CONSTRAINT domena_pk PRIMARY KEY (domena);
franta-hg@0
   197
franta-hg@0
   198
franta-hg@0
   199
--
franta-hg@17
   200
-- TOC entry 1973 (class 2606 OID 16416)
franta-hg@17
   201
-- Dependencies: 1645 1645 1645
franta-hg@0
   202
-- Name: uzivatel_pk; Type: CONSTRAINT; Schema: posta; Owner: -; Tablespace: 
franta-hg@0
   203
--
franta-hg@0
   204
franta-hg@0
   205
ALTER TABLE ONLY uzivatel
franta-hg@0
   206
    ADD CONSTRAINT uzivatel_pk PRIMARY KEY (login, domena);
franta-hg@0
   207
franta-hg@0
   208
franta-hg@0
   209
--
franta-hg@17
   210
-- TOC entry 1977 (class 2606 OID 16558)
franta-hg@17
   211
-- Dependencies: 1657 1970 1644
franta-hg@0
   212
-- Name: alias_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
franta-hg@0
   213
--
franta-hg@0
   214
franta-hg@0
   215
ALTER TABLE ONLY alias
franta-hg@14
   216
    ADD CONSTRAINT alias_domena_fk FOREIGN KEY (zdroj_domena) REFERENCES domena(domena);
franta-hg@0
   217
franta-hg@0
   218
franta-hg@0
   219
--
franta-hg@17
   220
-- TOC entry 1976 (class 2606 OID 16417)
franta-hg@17
   221
-- Dependencies: 1644 1645 1970
franta-hg@0
   222
-- Name: uzivatel_domena_fk; Type: FK CONSTRAINT; Schema: posta; Owner: -
franta-hg@0
   223
--
franta-hg@0
   224
franta-hg@0
   225
ALTER TABLE ONLY uzivatel
franta-hg@0
   226
    ADD CONSTRAINT uzivatel_domena_fk FOREIGN KEY (domena) REFERENCES domena(domena);
franta-hg@0
   227
franta-hg@0
   228
franta-hg@0
   229
--
franta-hg@17
   230
-- TOC entry 1980 (class 0 OID 0)
franta-hg@12
   231
-- Dependencies: 8
franta-hg@0
   232
-- Name: posta; Type: ACL; Schema: -; Owner: -
franta-hg@0
   233
--
franta-hg@0
   234
franta-hg@0
   235
REVOKE ALL ON SCHEMA posta FROM PUBLIC;
franta-hg@0
   236
REVOKE ALL ON SCHEMA posta FROM posta;
franta-hg@0
   237
GRANT ALL ON SCHEMA posta TO posta;
franta-hg@0
   238
GRANT USAGE ON SCHEMA posta TO posta_cteni;
franta-hg@12
   239
GRANT USAGE ON SCHEMA posta TO posta_zmena_hesla;
franta-hg@0
   240
franta-hg@0
   241
franta-hg@0
   242
--
franta-hg@17
   243
-- TOC entry 1982 (class 0 OID 0)
franta-hg@17
   244
-- Dependencies: 57
franta-hg@12
   245
-- Name: zmen_heslo(character varying, character varying, character varying, character varying); Type: ACL; Schema: posta; Owner: -
franta-hg@12
   246
--
franta-hg@12
   247
franta-hg@16
   248
REVOKE ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) FROM PUBLIC;
franta-hg@16
   249
REVOKE ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) FROM posta;
franta-hg@16
   250
GRANT ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) TO posta;
franta-hg@16
   251
GRANT ALL ON FUNCTION zmen_heslo("Login" character varying, "Domena" character varying, "Stare_heslo" character varying, "Nove_heslo" character varying) TO PUBLIC;
franta-hg@16
   252
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
   253
franta-hg@12
   254
franta-hg@12
   255
--
franta-hg@17
   256
-- TOC entry 1987 (class 0 OID 0)
franta-hg@17
   257
-- Dependencies: 1657
franta-hg@0
   258
-- Name: alias; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   259
--
franta-hg@0
   260
franta-hg@0
   261
REVOKE ALL ON TABLE alias FROM PUBLIC;
franta-hg@0
   262
REVOKE ALL ON TABLE alias FROM posta;
franta-hg@0
   263
GRANT ALL ON TABLE alias TO posta;
franta-hg@0
   264
franta-hg@0
   265
franta-hg@0
   266
--
franta-hg@17
   267
-- TOC entry 1988 (class 0 OID 0)
franta-hg@17
   268
-- Dependencies: 1644
franta-hg@0
   269
-- Name: domena; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   270
--
franta-hg@0
   271
franta-hg@0
   272
REVOKE ALL ON TABLE domena FROM PUBLIC;
franta-hg@0
   273
REVOKE ALL ON TABLE domena FROM posta;
franta-hg@0
   274
GRANT ALL ON TABLE domena TO posta;
franta-hg@0
   275
GRANT SELECT ON TABLE domena TO posta_cteni;
franta-hg@0
   276
franta-hg@0
   277
franta-hg@0
   278
--
franta-hg@17
   279
-- TOC entry 1989 (class 0 OID 0)
franta-hg@17
   280
-- Dependencies: 1645
franta-hg@0
   281
-- Name: uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   282
--
franta-hg@0
   283
franta-hg@0
   284
REVOKE ALL ON TABLE uzivatel FROM PUBLIC;
franta-hg@0
   285
REVOKE ALL ON TABLE uzivatel FROM posta;
franta-hg@0
   286
GRANT ALL ON TABLE uzivatel TO posta;
franta-hg@0
   287
GRANT SELECT ON TABLE uzivatel TO posta_cteni;
franta-hg@0
   288
franta-hg@0
   289
franta-hg@0
   290
--
franta-hg@17
   291
-- TOC entry 1990 (class 0 OID 0)
franta-hg@17
   292
-- Dependencies: 1658
franta-hg@0
   293
-- Name: dovecot_heslo; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   294
--
franta-hg@0
   295
franta-hg@0
   296
REVOKE ALL ON TABLE dovecot_heslo FROM PUBLIC;
franta-hg@0
   297
REVOKE ALL ON TABLE dovecot_heslo FROM posta;
franta-hg@0
   298
GRANT ALL ON TABLE dovecot_heslo TO posta;
franta-hg@0
   299
GRANT SELECT ON TABLE dovecot_heslo TO posta_cteni;
franta-hg@0
   300
franta-hg@0
   301
franta-hg@0
   302
--
franta-hg@17
   303
-- TOC entry 1991 (class 0 OID 0)
franta-hg@17
   304
-- Dependencies: 1660
franta-hg@0
   305
-- Name: dovecot_uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   306
--
franta-hg@0
   307
franta-hg@0
   308
REVOKE ALL ON TABLE dovecot_uzivatel FROM PUBLIC;
franta-hg@0
   309
REVOKE ALL ON TABLE dovecot_uzivatel FROM posta;
franta-hg@0
   310
GRANT ALL ON TABLE dovecot_uzivatel TO posta;
franta-hg@0
   311
GRANT SELECT ON TABLE dovecot_uzivatel TO posta_cteni;
franta-hg@0
   312
franta-hg@0
   313
franta-hg@0
   314
--
franta-hg@17
   315
-- TOC entry 1992 (class 0 OID 0)
franta-hg@17
   316
-- Dependencies: 1661
franta-hg@0
   317
-- Name: postfix_alias; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   318
--
franta-hg@0
   319
franta-hg@0
   320
REVOKE ALL ON TABLE postfix_alias FROM PUBLIC;
franta-hg@0
   321
REVOKE ALL ON TABLE postfix_alias FROM posta;
franta-hg@0
   322
GRANT ALL ON TABLE postfix_alias TO posta;
franta-hg@0
   323
GRANT SELECT ON TABLE postfix_alias TO posta_cteni;
franta-hg@0
   324
franta-hg@0
   325
franta-hg@0
   326
--
franta-hg@17
   327
-- TOC entry 1993 (class 0 OID 0)
franta-hg@17
   328
-- Dependencies: 1659
franta-hg@0
   329
-- Name: postfix_uzivatel; Type: ACL; Schema: posta; Owner: -
franta-hg@0
   330
--
franta-hg@0
   331
franta-hg@0
   332
REVOKE ALL ON TABLE postfix_uzivatel FROM PUBLIC;
franta-hg@0
   333
REVOKE ALL ON TABLE postfix_uzivatel FROM posta;
franta-hg@0
   334
GRANT ALL ON TABLE postfix_uzivatel TO posta;
franta-hg@0
   335
GRANT SELECT ON TABLE postfix_uzivatel TO posta_cteni;
franta-hg@0
   336
franta-hg@0
   337
franta-hg@17
   338
-- Completed on 2009-08-28 17:21:17 CEST
franta-hg@0
   339
franta-hg@0
   340
--
franta-hg@0
   341
-- PostgreSQL database dump complete
franta-hg@0
   342
--
franta-hg@0
   343