You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postgres.initial.sql 8.0KB

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