source: subversion/trunk/roundcubemail/SQL/postgres.initial.sql @ 3333

Last change on this file since 3333 was 3333, checked in by alec, 3 years ago
  • re-fix (#1486474) + require MySQL 4.0.8 + add index/update in identities table
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1-- RoundCube Webmail initial database structure
2
3--
4-- Sequence "user_ids"
5-- Name: user_ids; Type: SEQUENCE; Schema: public; Owner: postgres
6--
7
8CREATE SEQUENCE user_ids
9    INCREMENT BY 1
10    NO MAXVALUE
11    NO MINVALUE
12    CACHE 1;
13
14--
15-- Table "users"
16-- Name: users; Type: TABLE; Schema: public; Owner: postgres
17--
18
19CREATE TABLE users (
20    user_id integer DEFAULT nextval('user_ids'::text) PRIMARY KEY,
21    username character varying(128) DEFAULT ''::character varying NOT NULL,
22    mail_host character varying(128) DEFAULT ''::character varying NOT NULL,
23    alias character varying(128) DEFAULT ''::character varying NOT NULL,
24    created timestamp with time zone DEFAULT now() NOT NULL,
25    last_login timestamp with time zone DEFAULT now() NOT NULL,
26    "language" character varying(5),
27    preferences text DEFAULT ''::text NOT NULL
28);
29
30CREATE INDEX users_username_id_idx ON users (username);
31CREATE INDEX users_alias_id_idx ON users (alias);
32
33 
34--
35-- Table "session"
36-- Name: session; Type: TABLE; Schema: public; Owner: postgres
37--
38
39CREATE TABLE "session" (
40    sess_id character varying(40) DEFAULT ''::character varying PRIMARY KEY,
41    created timestamp with time zone DEFAULT now() NOT NULL,
42    changed timestamp with time zone DEFAULT now() NOT NULL,
43    ip character varying(41) NOT NULL,
44    vars text NOT NULL
45);
46
47CREATE INDEX session_changed_idx ON session (changed);
48
49
50--
51-- Sequence "identity_ids"
52-- Name: identity_ids; Type: SEQUENCE; Schema: public; Owner: postgres
53--
54
55CREATE SEQUENCE identity_ids
56    START WITH 1
57    INCREMENT BY 1
58    NO MAXVALUE
59    NO MINVALUE
60    CACHE 1;
61
62--
63-- Table "identities"
64-- Name: identities; Type: TABLE; Schema: public; Owner: postgres
65--
66
67CREATE TABLE identities (
68    identity_id integer DEFAULT nextval('identity_ids'::text) PRIMARY KEY,
69    user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
70    del smallint DEFAULT 0 NOT NULL,
71    standard smallint DEFAULT 0 NOT NULL,
72    name character varying(128) NOT NULL,
73    organization character varying(128),
74    email character varying(128) NOT NULL,
75    "reply-to" character varying(128),
76    bcc character varying(128),
77    signature text,
78    html_signature integer DEFAULT 0 NOT NULL
79);
80
81CREATE INDEX identities_user_id_idx ON identities (user_id, del);
82
83
84--
85-- Sequence "contact_ids"
86-- Name: contact_ids; Type: SEQUENCE; Schema: public; Owner: postgres
87--
88
89CREATE SEQUENCE contact_ids
90    START WITH 1
91    INCREMENT BY 1
92    NO MAXVALUE
93    NO MINVALUE
94    CACHE 1;
95
96--
97-- Table "contacts"
98-- Name: contacts; Type: TABLE; Schema: public; Owner: postgres
99--
100
101CREATE TABLE contacts (
102    contact_id integer DEFAULT nextval('contact_ids'::text) PRIMARY KEY,
103    user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
104    changed timestamp with time zone DEFAULT now() NOT NULL,
105    del smallint DEFAULT 0 NOT NULL,
106    name character varying(128) DEFAULT ''::character varying NOT NULL,
107    email character varying(128) DEFAULT ''::character varying NOT NULL,
108    firstname character varying(128) DEFAULT ''::character varying NOT NULL,
109    surname character varying(128) DEFAULT ''::character varying NOT NULL,
110    vcard text
111);
112
113CREATE INDEX contacts_user_id_idx ON contacts (user_id, email);
114
115--
116-- Sequence "cache_ids"
117-- Name: cache_ids; Type: SEQUENCE; Schema: public; Owner: postgres
118--
119
120CREATE SEQUENCE cache_ids
121    INCREMENT BY 1
122    NO MAXVALUE
123    NO MINVALUE
124    CACHE 1;
125
126--
127-- Table "cache"
128-- Name: cache; Type: TABLE; Schema: public; Owner: postgres
129--
130
131CREATE TABLE "cache" (
132    cache_id integer DEFAULT nextval('cache_ids'::text) PRIMARY KEY,
133    user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
134    cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
135    created timestamp with time zone DEFAULT now() NOT NULL,
136    data text NOT NULL
137);
138
139CREATE INDEX cache_user_id_idx ON "cache" (user_id, cache_key);
140CREATE INDEX cache_created_idx ON "cache" (created);
141
142--
143-- Sequence "message_ids"
144-- Name: message_ids; Type: SEQUENCE; Schema: public; Owner: postgres
145--
146
147CREATE SEQUENCE message_ids
148    INCREMENT BY 1
149    NO MAXVALUE
150    NO MINVALUE
151    CACHE 1;
152
153--
154-- Table "messages"
155-- Name: messages; Type: TABLE; Schema: public; Owner: postgres
156--
157
158CREATE TABLE messages (
159    message_id integer DEFAULT nextval('message_ids'::text) PRIMARY KEY,
160    user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
161    del smallint DEFAULT 0 NOT NULL,
162    cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
163    created timestamp with time zone DEFAULT now() NOT NULL,
164    idx integer DEFAULT 0 NOT NULL,
165    uid integer DEFAULT 0 NOT NULL,
166    subject character varying(128) DEFAULT ''::character varying NOT NULL,
167    "from" character varying(128) DEFAULT ''::character varying NOT NULL,
168    "to" character varying(128) DEFAULT ''::character varying NOT NULL,
169    cc character varying(128) DEFAULT ''::character varying NOT NULL,
170    date timestamp with time zone NOT NULL,
171    size integer DEFAULT 0 NOT NULL,
172    headers text NOT NULL,
173    structure text
174);
175
176ALTER TABLE messages ADD UNIQUE (user_id, cache_key, uid);
177CREATE INDEX messages_index_idx ON messages (user_id, cache_key, idx);
178CREATE INDEX messages_created_idx ON messages (created);
Note: See TracBrowser for help on using the repository browser.