Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

mssql.initial.sql 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. CREATE TABLE [dbo].[cache] (
  2. [user_id] [int] NOT NULL ,
  3. [cache_key] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  4. [created] [datetime] NOT NULL ,
  5. [expires] [datetime] NULL ,
  6. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  7. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  8. GO
  9. CREATE TABLE [dbo].[cache_shared] (
  10. [cache_key] [varchar] (255) COLLATE Latin1_General_CI_AI NOT NULL ,
  11. [created] [datetime] NOT NULL ,
  12. [expires] [datetime] NULL ,
  13. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  14. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  15. GO
  16. CREATE TABLE [dbo].[cache_index] (
  17. [user_id] [int] NOT NULL ,
  18. [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  19. [expires] [datetime] NULL ,
  20. [valid] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL ,
  21. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  22. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  23. GO
  24. CREATE TABLE [dbo].[cache_thread] (
  25. [user_id] [int] NOT NULL ,
  26. [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  27. [expires] [datetime] NULL ,
  28. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  29. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  30. GO
  31. CREATE TABLE [dbo].[cache_messages] (
  32. [user_id] [int] NOT NULL ,
  33. [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  34. [uid] [int] NOT NULL ,
  35. [expires] [datetime] NULL ,
  36. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL ,
  37. [flags] [int] NOT NULL
  38. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  39. GO
  40. CREATE TABLE [dbo].[contacts] (
  41. [contact_id] [int] IDENTITY (1, 1) NOT NULL ,
  42. [user_id] [int] NOT NULL ,
  43. [changed] [datetime] NOT NULL ,
  44. [del] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL ,
  45. [name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  46. [email] [varchar] (8000) COLLATE Latin1_General_CI_AI NOT NULL ,
  47. [firstname] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  48. [surname] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  49. [vcard] [text] COLLATE Latin1_General_CI_AI NULL ,
  50. [words] [text] COLLATE Latin1_General_CI_AI NULL
  51. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  52. GO
  53. CREATE TABLE [dbo].[contactgroups] (
  54. [contactgroup_id] [int] IDENTITY (1, 1) NOT NULL ,
  55. [user_id] [int] NOT NULL ,
  56. [changed] [datetime] NOT NULL ,
  57. [del] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL ,
  58. [name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL
  59. ) ON [PRIMARY]
  60. GO
  61. CREATE TABLE [dbo].[contactgroupmembers] (
  62. [contactgroup_id] [int] NOT NULL ,
  63. [contact_id] [int] NOT NULL ,
  64. [created] [datetime] NOT NULL
  65. ) ON [PRIMARY]
  66. GO
  67. CREATE TABLE [dbo].[identities] (
  68. [identity_id] [int] IDENTITY (1, 1) NOT NULL ,
  69. [user_id] [int] NOT NULL ,
  70. [changed] [datetime] NOT NULL ,
  71. [del] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL ,
  72. [standard] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL ,
  73. [name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  74. [organization] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  75. [email] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  76. [reply-to] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  77. [bcc] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  78. [signature] [text] COLLATE Latin1_General_CI_AI NULL,
  79. [html_signature] [char] (1) COLLATE Latin1_General_CI_AI NOT NULL
  80. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  81. GO
  82. CREATE TABLE [dbo].[session] (
  83. [sess_id] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  84. [created] [datetime] NOT NULL ,
  85. [changed] [datetime] NULL ,
  86. [ip] [varchar] (40) COLLATE Latin1_General_CI_AI NOT NULL ,
  87. [vars] [text] COLLATE Latin1_General_CI_AI NOT NULL
  88. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  89. GO
  90. CREATE TABLE [dbo].[users] (
  91. [user_id] [int] IDENTITY (1, 1) NOT NULL ,
  92. [username] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  93. [mail_host] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  94. [created] [datetime] NOT NULL ,
  95. [last_login] [datetime] NULL ,
  96. [failed_login] [datetime] NULL ,
  97. [failed_login_counter] [int] NULL ,
  98. [language] [varchar] (5) COLLATE Latin1_General_CI_AI NULL ,
  99. [preferences] [text] COLLATE Latin1_General_CI_AI NULL
  100. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  101. GO
  102. CREATE TABLE [dbo].[dictionary] (
  103. [user_id] [int] ,
  104. [language] [varchar] (5) COLLATE Latin1_General_CI_AI NOT NULL ,
  105. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  106. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  107. GO
  108. CREATE TABLE [dbo].[searches] (
  109. [search_id] [int] IDENTITY (1, 1) NOT NULL ,
  110. [user_id] [int] NOT NULL ,
  111. [type] [tinyint] NOT NULL ,
  112. [name] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
  113. [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
  114. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  115. GO
  116. CREATE TABLE [dbo].[system] (
  117. [name] [varchar] (64) COLLATE Latin1_General_CI_AI NOT NULL ,
  118. [value] [text] COLLATE Latin1_General_CI_AI NOT NULL
  119. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  120. GO
  121. ALTER TABLE [dbo].[cache_index] WITH NOCHECK ADD
  122. PRIMARY KEY CLUSTERED
  123. (
  124. [user_id],[mailbox]
  125. ) ON [PRIMARY]
  126. GO
  127. ALTER TABLE [dbo].[cache_thread] WITH NOCHECK ADD
  128. PRIMARY KEY CLUSTERED
  129. (
  130. [user_id],[mailbox]
  131. ) ON [PRIMARY]
  132. GO
  133. ALTER TABLE [dbo].[cache_messages] WITH NOCHECK ADD
  134. PRIMARY KEY CLUSTERED
  135. (
  136. [user_id],[mailbox],[uid]
  137. ) ON [PRIMARY]
  138. GO
  139. ALTER TABLE [dbo].[contacts] WITH NOCHECK ADD
  140. CONSTRAINT [PK_contacts_contact_id] PRIMARY KEY CLUSTERED
  141. (
  142. [contact_id]
  143. ) ON [PRIMARY]
  144. GO
  145. ALTER TABLE [dbo].[contactgroups] WITH NOCHECK ADD
  146. CONSTRAINT [PK_contactgroups_contactgroup_id] PRIMARY KEY CLUSTERED
  147. (
  148. [contactgroup_id]
  149. ) ON [PRIMARY]
  150. GO
  151. ALTER TABLE [dbo].[contactgroupmembers] WITH NOCHECK ADD
  152. CONSTRAINT [PK_contactgroupmembers_id] PRIMARY KEY CLUSTERED
  153. (
  154. [contactgroup_id], [contact_id]
  155. ) ON [PRIMARY]
  156. GO
  157. ALTER TABLE [dbo].[identities] WITH NOCHECK ADD
  158. PRIMARY KEY CLUSTERED
  159. (
  160. [identity_id]
  161. ) ON [PRIMARY]
  162. GO
  163. ALTER TABLE [dbo].[session] WITH NOCHECK ADD
  164. CONSTRAINT [PK_session_sess_id] PRIMARY KEY CLUSTERED
  165. (
  166. [sess_id]
  167. ) ON [PRIMARY]
  168. GO
  169. ALTER TABLE [dbo].[users] WITH NOCHECK ADD
  170. CONSTRAINT [PK_users_user_id] PRIMARY KEY CLUSTERED
  171. (
  172. [user_id]
  173. ) ON [PRIMARY]
  174. GO
  175. ALTER TABLE [dbo].[searches] WITH NOCHECK ADD
  176. CONSTRAINT [PK_searches_search_id] PRIMARY KEY CLUSTERED
  177. (
  178. [search_id]
  179. ) ON [PRIMARY]
  180. GO
  181. ALTER TABLE [dbo].[system] WITH NOCHECK ADD
  182. CONSTRAINT [PK_system_name] PRIMARY KEY CLUSTERED
  183. (
  184. [name]
  185. ) ON [PRIMARY]
  186. GO
  187. ALTER TABLE [dbo].[cache] ADD
  188. CONSTRAINT [DF_cache_user_id] DEFAULT ('0') FOR [user_id],
  189. CONSTRAINT [DF_cache_cache_key] DEFAULT ('') FOR [cache_key],
  190. CONSTRAINT [DF_cache_created] DEFAULT (getdate()) FOR [created]
  191. GO
  192. ALTER TABLE [dbo].[cache_shared] ADD
  193. CONSTRAINT [DF_cache_shared_created] DEFAULT (getdate()) FOR [created]
  194. GO
  195. ALTER TABLE [dbo].[cache_index] ADD
  196. CONSTRAINT [DF_cache_index_valid] DEFAULT ('0') FOR [valid]
  197. GO
  198. ALTER TABLE [dbo].[cache_messages] ADD
  199. CONSTRAINT [DF_cache_messages_flags] DEFAULT (0) FOR [flags]
  200. GO
  201. CREATE INDEX [IX_cache_user_id] ON [dbo].[cache]([user_id]) ON [PRIMARY]
  202. GO
  203. CREATE INDEX [IX_cache_cache_key] ON [dbo].[cache]([cache_key]) ON [PRIMARY]
  204. GO
  205. CREATE INDEX [IX_cache_shared_cache_key] ON [dbo].[cache_shared]([cache_key]) ON [PRIMARY]
  206. GO
  207. CREATE INDEX [IX_cache_index_user_id] ON [dbo].[cache_index]([user_id]) ON [PRIMARY]
  208. GO
  209. CREATE INDEX [IX_cache_thread_user_id] ON [dbo].[cache_thread]([user_id]) ON [PRIMARY]
  210. GO
  211. CREATE INDEX [IX_cache_messages_user_id] ON [dbo].[cache_messages]([user_id]) ON [PRIMARY]
  212. GO
  213. CREATE INDEX [IX_cache_expires] ON [dbo].[cache]([expires]) ON [PRIMARY]
  214. GO
  215. CREATE INDEX [IX_cache_shared_expires] ON [dbo].[cache_shared]([expires]) ON [PRIMARY]
  216. GO
  217. CREATE INDEX [IX_cache_index_expires] ON [dbo].[cache_index]([expires]) ON [PRIMARY]
  218. GO
  219. CREATE INDEX [IX_cache_thread_expires] ON [dbo].[cache_thread]([expires]) ON [PRIMARY]
  220. GO
  221. CREATE INDEX [IX_cache_messages_expires] ON [dbo].[cache_messages]([expires]) ON [PRIMARY]
  222. GO
  223. ALTER TABLE [dbo].[contacts] ADD
  224. CONSTRAINT [DF_contacts_user_id] DEFAULT (0) FOR [user_id],
  225. CONSTRAINT [DF_contacts_changed] DEFAULT (getdate()) FOR [changed],
  226. CONSTRAINT [DF_contacts_del] DEFAULT ('0') FOR [del],
  227. CONSTRAINT [DF_contacts_name] DEFAULT ('') FOR [name],
  228. CONSTRAINT [DF_contacts_email] DEFAULT ('') FOR [email],
  229. CONSTRAINT [DF_contacts_firstname] DEFAULT ('') FOR [firstname],
  230. CONSTRAINT [DF_contacts_surname] DEFAULT ('') FOR [surname],
  231. CONSTRAINT [CK_contacts_del] CHECK ([del] = '1' or [del] = '0')
  232. GO
  233. CREATE INDEX [IX_contacts_user_id] ON [dbo].[contacts]([user_id]) ON [PRIMARY]
  234. GO
  235. ALTER TABLE [dbo].[contactgroups] ADD
  236. CONSTRAINT [DF_contactgroups_user_id] DEFAULT (0) FOR [user_id],
  237. CONSTRAINT [DF_contactgroups_changed] DEFAULT (getdate()) FOR [changed],
  238. CONSTRAINT [DF_contactgroups_del] DEFAULT ('0') FOR [del],
  239. CONSTRAINT [DF_contactgroups_name] DEFAULT ('') FOR [name],
  240. CONSTRAINT [CK_contactgroups_del] CHECK ([del] = '1' or [del] = '0')
  241. GO
  242. CREATE INDEX [IX_contactgroups_user_id] ON [dbo].[contactgroups]([user_id]) ON [PRIMARY]
  243. GO
  244. ALTER TABLE [dbo].[contactgroupmembers] ADD
  245. CONSTRAINT [DF_contactgroupmembers_contactgroup_id] DEFAULT (0) FOR [contactgroup_id],
  246. CONSTRAINT [DF_contactgroupmembers_contact_id] DEFAULT (0) FOR [contact_id],
  247. CONSTRAINT [DF_contactgroupmembers_created] DEFAULT (getdate()) FOR [created]
  248. GO
  249. CREATE INDEX [IX_contactgroupmembers_contact_id] ON [dbo].[contactgroupmembers]([contact_id]) ON [PRIMARY]
  250. GO
  251. ALTER TABLE [dbo].[identities] ADD
  252. CONSTRAINT [DF_identities_user] DEFAULT ('0') FOR [user_id],
  253. CONSTRAINT [DF_identities_del] DEFAULT ('0') FOR [del],
  254. CONSTRAINT [DF_identities_standard] DEFAULT ('0') FOR [standard],
  255. CONSTRAINT [DF_identities_name] DEFAULT ('') FOR [name],
  256. CONSTRAINT [DF_identities_organization] DEFAULT ('') FOR [organization],
  257. CONSTRAINT [DF_identities_email] DEFAULT ('') FOR [email],
  258. CONSTRAINT [DF_identities_reply] DEFAULT ('') FOR [reply-to],
  259. CONSTRAINT [DF_identities_bcc] DEFAULT ('') FOR [bcc],
  260. CONSTRAINT [DF_identities_html_signature] DEFAULT ('0') FOR [html_signature],
  261. CHECK ([standard] = '1' or [standard] = '0'),
  262. CHECK ([del] = '1' or [del] = '0')
  263. GO
  264. CREATE INDEX [IX_identities_user_id] ON [dbo].[identities]([user_id]) ON [PRIMARY]
  265. GO
  266. CREATE INDEX [IX_identities_email] ON [dbo].[identities]([email],[del]) ON [PRIMARY]
  267. GO
  268. ALTER TABLE [dbo].[session] ADD
  269. CONSTRAINT [DF_session_sess_id] DEFAULT ('') FOR [sess_id],
  270. CONSTRAINT [DF_session_created] DEFAULT (getdate()) FOR [created],
  271. CONSTRAINT [DF_session_ip] DEFAULT ('') FOR [ip]
  272. GO
  273. CREATE INDEX [IX_session_changed] ON [dbo].[session]([changed]) ON [PRIMARY]
  274. GO
  275. ALTER TABLE [dbo].[users] ADD
  276. CONSTRAINT [DF_users_username] DEFAULT ('') FOR [username],
  277. CONSTRAINT [DF_users_mail_host] DEFAULT ('') FOR [mail_host],
  278. CONSTRAINT [DF_users_created] DEFAULT (getdate()) FOR [created]
  279. GO
  280. CREATE UNIQUE INDEX [IX_users_username] ON [dbo].[users]([username],[mail_host]) ON [PRIMARY]
  281. GO
  282. CREATE UNIQUE INDEX [IX_dictionary_user_language] ON [dbo].[dictionary]([user_id],[language]) ON [PRIMARY]
  283. GO
  284. ALTER TABLE [dbo].[searches] ADD
  285. CONSTRAINT [DF_searches_user] DEFAULT (0) FOR [user_id],
  286. CONSTRAINT [DF_searches_type] DEFAULT (0) FOR [type]
  287. GO
  288. CREATE UNIQUE INDEX [IX_searches_user_type_name] ON [dbo].[searches]([user_id],[type],[name]) ON [PRIMARY]
  289. GO
  290. ALTER TABLE [dbo].[identities] ADD CONSTRAINT [FK_identities_user_id]
  291. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  292. ON DELETE CASCADE ON UPDATE CASCADE
  293. GO
  294. ALTER TABLE [dbo].[contacts] ADD CONSTRAINT [FK_contacts_user_id]
  295. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  296. ON DELETE CASCADE ON UPDATE CASCADE
  297. GO
  298. ALTER TABLE [dbo].[contactgroups] ADD CONSTRAINT [FK_contactgroups_user_id]
  299. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  300. ON DELETE CASCADE ON UPDATE CASCADE
  301. GO
  302. ALTER TABLE [dbo].[cache] ADD CONSTRAINT [FK_cache_user_id]
  303. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  304. ON DELETE CASCADE ON UPDATE CASCADE
  305. GO
  306. ALTER TABLE [dbo].[cache_index] ADD CONSTRAINT [FK_cache_index_user_id]
  307. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  308. ON DELETE CASCADE ON UPDATE CASCADE
  309. GO
  310. ALTER TABLE [dbo].[cache_thread] ADD CONSTRAINT [FK_cache_thread_user_id]
  311. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  312. ON DELETE CASCADE ON UPDATE CASCADE
  313. GO
  314. ALTER TABLE [dbo].[cache_messages] ADD CONSTRAINT [FK_cache_messages_user_id]
  315. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  316. ON DELETE CASCADE ON UPDATE CASCADE
  317. GO
  318. ALTER TABLE [dbo].[contactgroupmembers] ADD CONSTRAINT [FK_contactgroupmembers_contactgroup_id]
  319. FOREIGN KEY ([contactgroup_id]) REFERENCES [dbo].[contactgroups] ([contactgroup_id])
  320. ON DELETE CASCADE ON UPDATE CASCADE
  321. GO
  322. ALTER TABLE [dbo].[searches] ADD CONSTRAINT [FK_searches_user_id]
  323. FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
  324. ON DELETE CASCADE ON UPDATE CASCADE
  325. GO
  326. -- Use trigger instead of foreign key (#1487112)
  327. -- "Introducing FOREIGN KEY constraint ... may cause cycles or multiple cascade paths."
  328. CREATE TRIGGER [contact_delete_member] ON [dbo].[contacts]
  329. AFTER DELETE AS
  330. DELETE FROM [dbo].[contactgroupmembers]
  331. WHERE [contact_id] IN (SELECT [contact_id] FROM deleted)
  332. GO
  333. INSERT INTO [dbo].[system] ([name], [value]) VALUES ('roundcube-version', '2015111100')
  334. GO