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 7.7KB

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