]> git.donarmstrong.com Git - roundcube.git/blob - SQL/postgres.initial.sql
Imported Upstream version 0.2~alpha
[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) DEFAULT 'en'::character varying NOT NULL,
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
46
47 --
48 -- Sequence "identity_ids"
49 -- Name: identity_ids; Type: SEQUENCE; Schema: public; Owner: postgres
50 --
51
52 CREATE SEQUENCE identity_ids
53     START WITH 1
54     INCREMENT BY 1
55     NO MAXVALUE
56     NO MINVALUE
57     CACHE 1;
58
59 --
60 -- Table "identities"
61 -- Name: identities; Type: TABLE; Schema: public; Owner: postgres
62 --
63
64 CREATE TABLE identities (
65     identity_id integer DEFAULT nextval('identity_ids'::text) PRIMARY KEY,
66     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
67     del integer DEFAULT 0 NOT NULL,
68     standard integer DEFAULT 0 NOT NULL,
69     name character varying(128) NOT NULL,
70     organization character varying(128),
71     email character varying(128) NOT NULL,
72     "reply-to" character varying(128),
73     bcc character varying(128),
74     signature text,
75     html_signature integer DEFAULT 0 NOT NULL
76 );
77
78 CREATE INDEX identities_user_id_idx ON identities (user_id);
79
80
81 --
82 -- Sequence "contact_ids"
83 -- Name: contact_ids; Type: SEQUENCE; Schema: public; Owner: postgres
84 --
85
86 CREATE SEQUENCE contact_ids
87     START WITH 1
88     INCREMENT BY 1
89     NO MAXVALUE
90     NO MINVALUE
91     CACHE 1;
92
93 --
94 -- Table "contacts"
95 -- Name: contacts; Type: TABLE; Schema: public; Owner: postgres
96 --
97
98 CREATE TABLE contacts (
99     contact_id integer DEFAULT nextval('contact_ids'::text) PRIMARY KEY,
100     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
101     changed timestamp with time zone DEFAULT now() NOT NULL,
102     del integer DEFAULT 0 NOT NULL,
103     name character varying(128) DEFAULT ''::character varying NOT NULL,
104     email character varying(128) DEFAULT ''::character varying NOT NULL,
105     firstname character varying(128) DEFAULT ''::character varying NOT NULL,
106     surname character varying(128) DEFAULT ''::character varying NOT NULL,
107     vcard text
108 );
109
110 CREATE INDEX contacts_user_id_idx ON contacts (user_id);
111
112 --
113 -- Sequence "cache_ids"
114 -- Name: cache_ids; Type: SEQUENCE; Schema: public; Owner: postgres
115 --
116
117 CREATE SEQUENCE cache_ids
118     INCREMENT BY 1
119     NO MAXVALUE
120     NO MINVALUE
121     CACHE 1;
122
123 --
124 -- Table "cache"
125 -- Name: cache; Type: TABLE; Schema: public; Owner: postgres
126 --
127
128 CREATE TABLE "cache" (
129     cache_id integer DEFAULT nextval('cache_ids'::text) PRIMARY KEY,
130     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
131     session_id character varying(40) REFERENCES "session" (sess_id),
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
139 --
140 -- Sequence "message_ids"
141 -- Name: message_ids; Type: SEQUENCE; Schema: public; Owner: postgres
142 --
143
144 CREATE SEQUENCE message_ids
145     INCREMENT BY 1
146     NO MAXVALUE
147     NO MINVALUE
148     CACHE 1;
149
150 --
151 -- Table "messages"
152 -- Name: messages; Type: TABLE; Schema: public; Owner: postgres
153 --
154
155 CREATE TABLE "messages" (
156     message_id integer DEFAULT nextval('message_ids'::text) PRIMARY KEY,
157     user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE,
158     del integer DEFAULT 0 NOT NULL,
159     cache_key character varying(128) DEFAULT ''::character varying NOT NULL,
160     created timestamp with time zone DEFAULT now() NOT NULL,
161     idx integer DEFAULT 0 NOT NULL,
162     uid integer DEFAULT 0 NOT NULL,
163     subject character varying(128) DEFAULT ''::character varying NOT NULL,
164     "from" character varying(128) DEFAULT ''::character varying NOT NULL,
165     "to" character varying(128) DEFAULT ''::character varying NOT NULL,
166     cc character varying(128) DEFAULT ''::character varying NOT NULL,
167     date timestamp with time zone NOT NULL,
168     size integer DEFAULT 0 NOT NULL,
169     headers text NOT NULL,
170     structure text
171 );
172
173 ALTER TABLE "messages" ADD UNIQUE (user_id, cache_key, uid);