Aleksander Machniak
2016-03-28 46f7b7096450939fe03c95aa81ce06ae4bfca89d
commit | author | age
abc00f 1 -- Roundcube Webmail initial database structure
AM 2 -- This was tested with Oracle 11g
3
4 CREATE TABLE "users" (
5     "user_id" integer PRIMARY KEY,
6     "username" varchar(128) NOT NULL,
7     "mail_host" varchar(128) NOT NULL,
8     "created" timestamp with time zone DEFAULT current_timestamp NOT NULL,
9     "last_login" timestamp with time zone DEFAULT NULL,
a15d87 10     "failed_login" timestamp with time zone DEFAULT NULL,
AM 11     "failed_login_counter" integer DEFAULT NULL,
abc00f 12     "language" varchar(5),
AM 13     "preferences" long DEFAULT NULL,
14     CONSTRAINT "users_username_key" UNIQUE ("username", "mail_host")
15 );
16
17 CREATE SEQUENCE "users_seq"
18     START WITH 1 INCREMENT BY 1 NOMAXVALUE;
19
20 CREATE TRIGGER "users_seq_trig"
21 BEFORE INSERT ON "users" FOR EACH ROW
22 BEGIN
23     :NEW."user_id" := "users_seq".nextval;
24 END;
9aa55d 25 /
abc00f 26
AM 27 CREATE TABLE "session" (
28     "sess_id" varchar(128) NOT NULL PRIMARY KEY,
29     "created" timestamp with time zone DEFAULT current_timestamp NOT NULL,
30     "changed" timestamp with time zone DEFAULT current_timestamp NOT NULL,
31     "ip" varchar(41) NOT NULL,
32     "vars" long NOT NULL
33 );
34
35 CREATE INDEX "session_changed_idx" ON "session" ("changed");
36
37
38 CREATE TABLE "identities" (
39     "identity_id" integer PRIMARY KEY,
40     "user_id" integer NOT NULL
41         REFERENCES "users" ("user_id") ON DELETE CASCADE,
42     "changed" timestamp with time zone DEFAULT current_timestamp NOT NULL,
43     "del" smallint DEFAULT 0 NOT NULL,
44     "standard" smallint DEFAULT 0 NOT NULL,
45     "name" varchar(128) NOT NULL,
46     "organization" varchar(128),
47     "email" varchar(128) NOT NULL,
48     "reply-to" varchar(128),
49     "bcc" varchar(128),
50     "signature" long,
51     "html_signature" integer DEFAULT 0 NOT NULL
52 );
53
54 CREATE INDEX "identities_user_id_idx" ON "identities" ("user_id", "del");
55 CREATE INDEX "identities_email_idx" ON "identities" ("email", "del");
56
57 CREATE SEQUENCE "identities_seq"
58     START WITH 1 INCREMENT BY 1 NOMAXVALUE;
59
60 CREATE TRIGGER "identities_seq_trig"
61 BEFORE INSERT ON "identities" FOR EACH ROW
62 BEGIN
63     :NEW."identity_id" := "identities_seq".nextval;
64 END;
9aa55d 65 /
abc00f 66
AM 67 CREATE TABLE "contacts" (
68     "contact_id" integer PRIMARY KEY,
69     "user_id" integer NOT NULL
70         REFERENCES "users" ("user_id") ON DELETE CASCADE,
71     "changed" timestamp with time zone DEFAULT current_timestamp NOT NULL,
72     "del" smallint DEFAULT 0 NOT NULL,
73     "name" varchar(128) DEFAULT NULL,
74     "email" varchar(4000) DEFAULT NULL,
75     "firstname" varchar(128) DEFAULT NULL,
76     "surname" varchar(128) DEFAULT NULL,
77     "vcard" long,
78     "words" varchar(4000)
79 );
80
81 CREATE INDEX "contacts_user_id_idx" ON "contacts" ("user_id", "del");
82
83 CREATE SEQUENCE "contacts_seq"
84     START WITH 1 INCREMENT BY 1 NOMAXVALUE;
85
86 CREATE TRIGGER "contacts_seq_trig"
87 BEFORE INSERT ON "contacts" FOR EACH ROW
88 BEGIN
89     :NEW."contact_id" := "contacts_seq".nextval;
90 END;
9aa55d 91 /
abc00f 92
AM 93 CREATE TABLE "contactgroups" (
94     "contactgroup_id" integer PRIMARY KEY,
95     "user_id" integer NOT NULL
96         REFERENCES "users" ("user_id") ON DELETE CASCADE,
97     "changed" timestamp with time zone DEFAULT current_timestamp NOT NULL,
98     "del" smallint DEFAULT 0 NOT NULL,
99     "name" varchar(128) NOT NULL
100 );
101
102 CREATE INDEX "contactgroups_user_id_idx" ON "contactgroups" ("user_id", "del");
103
104 CREATE SEQUENCE "contactgroups_seq"
105     START WITH 1 INCREMENT BY 1 NOMAXVALUE;
106
107 CREATE TRIGGER "contactgroups_seq_trig"
108 BEFORE INSERT ON "contactgroups" FOR EACH ROW
109 BEGIN
110     :NEW."contactgroup_id" := "contactgroups_seq".nextval;
111 END;
9aa55d 112 /
abc00f 113
AM 114 CREATE TABLE "contactgroupmembers" (
115     "contactgroup_id" integer NOT NULL
116         REFERENCES "contactgroups" ("contactgroup_id") ON DELETE CASCADE,
117     "contact_id" integer NOT NULL
118         REFERENCES "contacts" ("contact_id") ON DELETE CASCADE,
119     "created" timestamp with time zone DEFAULT current_timestamp NOT NULL,
120     PRIMARY KEY ("contactgroup_id", "contact_id")
121 );
122
123 CREATE INDEX "contactgroupmembers_idx" ON "contactgroupmembers" ("contact_id");
124
125
126 CREATE TABLE "cache" (
127     "user_id" integer NOT NULL
128         REFERENCES "users" ("user_id") ON DELETE CASCADE,
129     "cache_key" varchar(128) NOT NULL,
130     "created" timestamp with time zone DEFAULT current_timestamp NOT NULL,
131     "expires" timestamp with time zone DEFAULT NULL,
132     "data" long NOT NULL
133 );
134
135 CREATE INDEX "cache_user_id_idx" ON "cache" ("user_id", "cache_key");
136 CREATE INDEX "cache_expires_idx" ON "cache" ("expires");
137
138
139 CREATE TABLE "cache_shared" (
140     "cache_key" varchar(255) NOT NULL,
141     "created" timestamp with time zone DEFAULT current_timestamp NOT NULL,
142     "expires" timestamp with time zone DEFAULT NULL,
143     "data" long NOT NULL
144 );
145
146 CREATE INDEX "cache_shared_cache_key_idx" ON "cache_shared" ("cache_key");
147 CREATE INDEX "cache_shared_expires_idx" ON "cache_shared" ("expires");
148
149
150 CREATE TABLE "cache_index" (
151     "user_id" integer NOT NULL
152         REFERENCES "users" ("user_id") ON DELETE CASCADE,
153     "mailbox" varchar(255) NOT NULL,
154     "expires" timestamp with time zone DEFAULT NULL,
155     "valid" smallint DEFAULT 0 NOT NULL,
156     "data" long NOT NULL,
157     PRIMARY KEY ("user_id", "mailbox")
158 );
159
160 CREATE INDEX "cache_index_expires_idx" ON "cache_index" ("expires");
161
162
163 CREATE TABLE "cache_thread" (
164     "user_id" integer NOT NULL
165         REFERENCES "users" ("user_id") ON DELETE CASCADE,
166     "mailbox" varchar(255) NOT NULL,
167     "expires" timestamp with time zone DEFAULT NULL,
168     "data" long NOT NULL,
169     PRIMARY KEY ("user_id", "mailbox")
170 );
171
172 CREATE INDEX "cache_thread_expires_idx" ON "cache_thread" ("expires");
173
174
175 CREATE TABLE "cache_messages" (
176     "user_id" integer NOT NULL
177         REFERENCES "users" ("user_id") ON DELETE CASCADE,
178     "mailbox" varchar(255) NOT NULL,
179     "uid" integer NOT NULL,
180     "expires" timestamp with time zone DEFAULT NULL,
181     "data" long NOT NULL,
182     "flags" integer DEFAULT 0 NOT NULL,
183     PRIMARY KEY ("user_id", "mailbox", "uid")
184 );
185
186 CREATE INDEX "cache_messages_expires_idx" ON "cache_messages" ("expires");
187
188
189 CREATE TABLE "dictionary" (
190     "user_id" integer DEFAULT NULL
191         REFERENCES "users" ("user_id") ON DELETE CASCADE,
192     "language" varchar(5) NOT NULL,
193     "data" long DEFAULT NULL,
194     CONSTRAINT "dictionary_user_id_lang_key" UNIQUE ("user_id", "language")
195 );
196
197
198 CREATE TABLE "searches" (
199     "search_id" integer PRIMARY KEY,
200     "user_id" integer NOT NULL
201         REFERENCES "users" ("user_id") ON DELETE CASCADE,
202     "type" smallint DEFAULT 0 NOT NULL,
203     "name" varchar(128) NOT NULL,
204     "data" long NOT NULL,
205     CONSTRAINT "searches_user_id_key" UNIQUE ("user_id", "type", "name")
206 );
207
208 CREATE SEQUENCE "searches_seq"
209     START WITH 1 INCREMENT BY 1 NOMAXVALUE;
210
211 CREATE TRIGGER "searches_seq_trig"
212 BEFORE INSERT ON "searches" FOR EACH ROW
213 BEGIN
214     :NEW."search_id" := "searches_seq".nextval;
215 END;
9aa55d 216 /
abc00f 217
AM 218 CREATE TABLE "system" (
219     "name" varchar(64) NOT NULL PRIMARY KEY,
220     "value" long
221 );
222
a15d87 223 INSERT INTO "system" ("name", "value") VALUES ('roundcube-version', '2015111100');