summaryrefslogtreecommitdiff
path: root/SQL/mssql.initial.sql
diff options
context:
space:
mode:
Diffstat (limited to 'SQL/mssql.initial.sql')
-rw-r--r--SQL/mssql.initial.sql144
1 files changed, 90 insertions, 54 deletions
diff --git a/SQL/mssql.initial.sql b/SQL/mssql.initial.sql
index 8e103eb55..eb5f20bcc 100644
--- a/SQL/mssql.initial.sql
+++ b/SQL/mssql.initial.sql
@@ -7,6 +7,37 @@ CREATE TABLE [dbo].[cache] (
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
+CREATE TABLE [dbo].[cache_index] (
+ [user_id] [int] NOT NULL ,
+ [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
+ [changed] [datetime] NOT NULL ,
+ [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+GO
+
+CREATE TABLE [dbo].[cache_thread] (
+ [user_id] [int] NOT NULL ,
+ [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
+ [changed] [datetime] NOT NULL ,
+ [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+GO
+
+CREATE TABLE [dbo].[cache_messages] (
+ [user_id] [int] NOT NULL ,
+ [mailbox] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
+ [uid] [int] NOT NULL ,
+ [changed] [datetime] NOT NULL ,
+ [data] [text] COLLATE Latin1_General_CI_AI NOT NULL
+ [seen] [char](1) NOT NULL ,
+ [deleted] [char](1) NOT NULL ,
+ [answered] [char](1) NOT NULL ,
+ [forwarded] [char](1) NOT NULL ,
+ [flagged] [char](1) NOT NULL ,
+ [mdnsent] [char](1) NOT NULL ,
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+GO
+
CREATE TABLE [dbo].[contacts] (
[contact_id] [int] IDENTITY (1, 1) NOT NULL ,
[user_id] [int] NOT NULL ,
@@ -53,25 +84,6 @@ CREATE TABLE [dbo].[identities] (
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
-CREATE TABLE [dbo].[messages] (
- [message_id] [int] IDENTITY (1, 1) NOT NULL ,
- [user_id] [int] NOT NULL ,
- [del] [tinyint] NOT NULL ,
- [cache_key] [varchar] (128) COLLATE Latin1_General_CI_AI NOT NULL ,
- [created] [datetime] NOT NULL ,
- [idx] [int] NOT NULL ,
- [uid] [int] NOT NULL ,
- [subject] [varchar] (255) COLLATE Latin1_General_CI_AI NOT NULL ,
- [from] [varchar] (255) COLLATE Latin1_General_CI_AI NOT NULL ,
- [to] [varchar] (255) COLLATE Latin1_General_CI_AI NOT NULL ,
- [cc] [varchar] (255) COLLATE Latin1_General_CI_AI NOT NULL ,
- [date] [datetime] NOT NULL ,
- [size] [int] NOT NULL ,
- [headers] [text] COLLATE Latin1_General_CI_AI NOT NULL ,
- [structure] [text] COLLATE Latin1_General_CI_AI NULL
-) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
-GO
-
CREATE TABLE [dbo].[session] (
[sess_id] [varchar] (32) COLLATE Latin1_General_CI_AI NOT NULL ,
[created] [datetime] NOT NULL ,
@@ -116,6 +128,27 @@ ALTER TABLE [dbo].[cache] WITH NOCHECK ADD
) ON [PRIMARY]
GO
+ALTER TABLE [dbo].[cache_index] WITH NOCHECK ADD
+ PRIMARY KEY CLUSTERED
+ (
+ [user_id],[mailbox]
+ ) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[cache_thread] WITH NOCHECK ADD
+ PRIMARY KEY CLUSTERED
+ (
+ [user_id],[mailbox]
+ ) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[cache_messages] WITH NOCHECK ADD
+ PRIMARY KEY CLUSTERED
+ (
+ [user_id],[mailbox],[uid]
+ ) ON [PRIMARY]
+GO
+
ALTER TABLE [dbo].[contacts] WITH NOCHECK ADD
CONSTRAINT [PK_contacts_contact_id] PRIMARY KEY CLUSTERED
(
@@ -144,13 +177,6 @@ ALTER TABLE [dbo].[identities] WITH NOCHECK ADD
) ON [PRIMARY]
GO
-ALTER TABLE [dbo].[messages] WITH NOCHECK ADD
- PRIMARY KEY CLUSTERED
- (
- [message_id]
- ) ON [PRIMARY]
-GO
-
ALTER TABLE [dbo].[session] WITH NOCHECK ADD
CONSTRAINT [PK_session_sess_id] PRIMARY KEY CLUSTERED
(
@@ -187,6 +213,33 @@ GO
CREATE INDEX [IX_cache_created] ON [dbo].[cache]([created]) ON [PRIMARY]
GO
+ALTER TABLE [dbo].[cache_index] ADD
+ CONSTRAINT [DF_cache_index_changed] DEFAULT (getdate()) FOR [changed]
+GO
+
+CREATE INDEX [IX_cache_index_user_id] ON [dbo].[cache_index]([user_id]) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[cache_thread] ADD
+ CONSTRAINT [DF_cache_thread_changed] DEFAULT (getdate()) FOR [changed]
+GO
+
+CREATE INDEX [IX_cache_thread_user_id] ON [dbo].[cache_thread]([user_id]) ON [PRIMARY]
+GO
+
+ALTER TABLE [dbo].[cache_messages] ADD
+ CONSTRAINT [DF_cache_messages_changed] DEFAULT (getdate()) FOR [changed]
+ CONSTRAINT [DF_cache_messages_seen] DEFAULT (0) FOR [seen],
+ CONSTRAINT [DF_cache_messages_deleted] DEFAULT (0) FOR [deleted],
+ CONSTRAINT [DF_cache_messages_answered] DEFAULT (0) FOR [answered],
+ CONSTRAINT [DF_cache_messages_forwarded] DEFAULT (0) FOR [forwarded],
+ CONSTRAINT [DF_cache_messages_flagged] DEFAULT (0) FOR [flagged],
+ CONSTRAINT [DF_cache_messages_mdnsent] DEFAULT (0) FOR [mdnsent],
+GO
+
+CREATE INDEX [IX_cache_messages_user_id] ON [dbo].[cache_messages]([user_id]) ON [PRIMARY]
+GO
+
ALTER TABLE [dbo].[contacts] ADD
CONSTRAINT [DF_contacts_user_id] DEFAULT (0) FOR [user_id],
CONSTRAINT [DF_contacts_changed] DEFAULT (getdate()) FOR [changed],
@@ -238,33 +291,6 @@ GO
CREATE INDEX [IX_identities_user_id] ON [dbo].[identities]([user_id]) ON [PRIMARY]
GO
-ALTER TABLE [dbo].[messages] ADD
- CONSTRAINT [DF_messages_user_id] DEFAULT (0) FOR [user_id],
- CONSTRAINT [DF_messages_del] DEFAULT (0) FOR [del],
- CONSTRAINT [DF_messages_cache_key] DEFAULT ('') FOR [cache_key],
- CONSTRAINT [DF_messages_created] DEFAULT (getdate()) FOR [created],
- CONSTRAINT [DF_messages_idx] DEFAULT (0) FOR [idx],
- CONSTRAINT [DF_messages_uid] DEFAULT (0) FOR [uid],
- CONSTRAINT [DF_messages_subject] DEFAULT ('') FOR [subject],
- CONSTRAINT [DF_messages_from] DEFAULT ('') FOR [from],
- CONSTRAINT [DF_messages_to] DEFAULT ('') FOR [to],
- CONSTRAINT [DF_messages_cc] DEFAULT ('') FOR [cc],
- CONSTRAINT [DF_messages_date] DEFAULT (getdate()) FOR [date],
- CONSTRAINT [DF_messages_size] DEFAULT (0) FOR [size]
-GO
-
-CREATE INDEX [IX_messages_user_id] ON [dbo].[messages]([user_id]) ON [PRIMARY]
-GO
-
-CREATE INDEX [IX_messages_cache_key] ON [dbo].[messages]([cache_key]) ON [PRIMARY]
-GO
-
-CREATE INDEX [IX_messages_uid] ON [dbo].[messages]([uid]) ON [PRIMARY]
-GO
-
-CREATE INDEX [IX_messages_created] ON [dbo].[messages]([created]) ON [PRIMARY]
-GO
-
ALTER TABLE [dbo].[session] ADD
CONSTRAINT [DF_session_sess_id] DEFAULT ('') FOR [sess_id],
CONSTRAINT [DF_session_created] DEFAULT (getdate()) FOR [created],
@@ -318,7 +344,17 @@ ALTER TABLE [dbo].[cache] ADD CONSTRAINT [FK_cache_user_id]
ON DELETE CASCADE ON UPDATE CASCADE
GO
-ALTER TABLE [dbo].[messages] ADD CONSTRAINT [FK_messages_user_id]
+ALTER TABLE [dbo].[cache_index] ADD CONSTRAINT [FK_cache_index_user_id]
+ FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
+ ON DELETE CASCADE ON UPDATE CASCADE
+GO
+
+ALTER TABLE [dbo].[cache_thread] ADD CONSTRAINT [FK_cache_thread_user_id]
+ FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
+ ON DELETE CASCADE ON UPDATE CASCADE
+GO
+
+ALTER TABLE [dbo].[cache_messages] ADD CONSTRAINT [FK_cache_messages_user_id]
FOREIGN KEY ([user_id]) REFERENCES [dbo].[users] ([user_id])
ON DELETE CASCADE ON UPDATE CASCADE
GO