]> git.donarmstrong.com Git - roundcube.git/blob - SQL/postgres.initial.sql
Imported Upstream version 0.2~stable
[roundcube.git] / SQL / postgres.initial.sql
1 --
2 -- Sequence "user_ids"
3 -- Name: user_ids; Type: SEQUENCE; Schema: public; Owner: postgres
4 --
5
6 CREATE SEQUENCE user_ids
7     INCREMENT BY 1
8     NO MAXVALUE
9     NO MINVALUE
10     CACHE 1;
11
12 --
13 -- Table "users"
14 -- Name: users; Type: TABLE; Schema: public; Owner: postgres
15 --
16
17 CREATE TABLE users (
18     user_id integer DEFAULT nextval('user_ids'::text) PRIMARY KEY,
19     username character varying(128) DEFAULT ''::character varying NOT NULL,
20     mail_host character varying(128) DEFAULT ''::character varying NOT NULL,
21     alias character varying(128) DEFAULT ''::character varying NOT NULL,
22     created timestamp with time zone DEFAULT now() NOT NULL,
23     last_login timestamp with time zone DEFAULT now() NOT NULL,
24     "language" character varying(5),
25     preferences text DEFAULT ''::text NOT NULL
26 );
27
28 CREATE INDEX users_username_id_idx ON users (username);
29 CREATE INDEX users_alias_id_idx ON users (alias);
30
31   
32 --
33 -- Table "session"
34 -- Name: session; Type: TABLE; Schema: public; Owner: postgres
35 --
36
37 CREATE TABLE "session" (
38     sess_id character varying(40) DEFAULT ''::character varying PRIMARY KEY,
39     created timestamp with time zone DEFAULT now() NOT NULL,
40     changed timestamp with time zone DEFAULT now() NOT NULL,
41     ip character varying(41) NOT NULL,
42     vars text NOT NULL
43 );
44
45 CREATE INDEX session_changed_idx ON session (changed);
46
47
48 --
49 -- Sequence "identity_ids"
50 -- Name: identity_ids; Type: SEQUENCE; Schema: public; Owner: postgres
51 --
52
53 CREATE SEQUENCE identity_ids
54     START WITH 1
55     INCREMENT BY 1
56     NO MAXVALUE
57     NO MINVALUE
58     CACHE 1;
59
60 --
61 -- Table "identities"
62 -- Name: identities; Type: TABLE; Schema: public; Owner: postgres
63 --
64
65 CREATE TABLE identities (
66     identity_id integer DEFAULT nextval('identity_ids'::text) PRIMARY KEY,
67     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
68     del smallint DEFAULT 0 NOT NULL,
69     standard smallint DEFAULT 0 NOT NULL,
70     name character varying(128) NOT NULL,
71     organization character varying(128),
72     email character varying(128) NOT NULL,
73     "reply-to" character varying(128),
74     bcc character varying(128),
75     signature text,
76     html_signature integer DEFAULT 0 NOT NULL
77 );
78
79 CREATE INDEX identities_user_id_idx ON identities (user_id);
80
81
82 --
83 -- Sequence "contact_ids"
84 -- Name: contact_ids; Type: SEQUENCE; Schema: public; Owner: postgres
85 --
86
87 CREATE SEQUENCE contact_ids
88     START WITH 1
89     INCREMENT BY 1
90     NO MAXVALUE
91     NO MINVALUE
92     CACHE 1;
93
94 --
95 -- Table "contacts"
96 -- Name: contacts; Type: TABLE; Schema: public; Owner: postgres
97 --
98
99 CREATE TABLE contacts (
100     contact_id integer DEFAULT nextval('contact_ids'::text) PRIMARY KEY,
101     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
102     changed timestamp with time zone DEFAULT now() NOT NULL,
103     del smallint DEFAULT 0 NOT NULL,
104     name character varying(128) DEFAULT ''::character varying NOT NULL,
105     email character varying(128) DEFAULT ''::character varying NOT NULL,
106     firstname character varying(128) DEFAULT ''::character varying NOT NULL,
107     surname character varying(128) DEFAULT ''::character varying NOT NULL,
108     vcard text
109 );
110
111 CREATE INDEX contacts_user_id_idx ON contacts (user_id);
112
113 --
114 -- Sequence "cache_ids"
115 -- Name: cache_ids; Type: SEQUENCE; Schema: public; Owner: postgres
116 --
117
118 CREATE SEQUENCE cache_ids
119     INCREMENT BY 1
120     NO MAXVALUE
121     NO MINVALUE
122     CACHE 1;
123
124 --
125 -- Table "cache"
126 -- Name: cache; Type: TABLE; Schema: public; Owner: postgres
127 --
128
129 CREATE TABLE "cache" (
130     cache_id integer DEFAULT nextval('cache_ids'::text) PRIMARY KEY,
131     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
132     cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
133     created timestamp with time zone DEFAULT now() NOT NULL,
134     data text NOT NULL
135 );
136
137 CREATE INDEX cache_user_id_idx ON "cache" (user_id, cache_key);
138 CREATE INDEX cache_created_idx ON "cache" (created);
139
140 --
141 -- Sequence "message_ids"
142 -- Name: message_ids; Type: SEQUENCE; Schema: public; Owner: postgres
143 --
144
145 CREATE SEQUENCE message_ids
146     INCREMENT BY 1
147     NO MAXVALUE
148     NO MINVALUE
149     CACHE 1;
150
151 --
152 -- Table "messages"
153 -- Name: messages; Type: TABLE; Schema: public; Owner: postgres
154 --
155
156 CREATE TABLE messages (
157     message_id integer DEFAULT nextval('message_ids'::text) PRIMARY KEY,
158     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
159     del smallint DEFAULT 0 NOT NULL,
160     cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
161     created timestamp with time zone DEFAULT now() NOT NULL,
162     idx integer DEFAULT 0 NOT NULL,
163     uid integer DEFAULT 0 NOT NULL,
164     subject character varying(128) DEFAULT ''::character varying NOT NULL,
165     "from" character varying(128) DEFAULT ''::character varying NOT NULL,
166     "to" character varying(128) DEFAULT ''::character varying NOT NULL,
167     cc character varying(128) DEFAULT ''::character varying NOT NULL,
168     date timestamp with time zone NOT NULL,
169     size integer DEFAULT 0 NOT NULL,
170     headers text NOT NULL,
171     structure text
172 );
173
174 ALTER TABLE messages ADD UNIQUE (user_id, cache_key, uid);
175 CREATE INDEX messages_created_idx ON messages (created);