import rt 3.8.10
[freeside.git] / rt / etc / schema.mysql
1 # {{{ Attachments
2
3 CREATE TABLE Attachments (
4   id INTEGER NOT NULL  AUTO_INCREMENT,
5   TransactionId integer NOT NULL  ,
6   Parent integer NOT NULL DEFAULT 0  ,
7   MessageId varchar(160) NULL  ,
8   Subject varchar(255) NULL  ,
9   Filename varchar(255) NULL  ,
10   ContentType varchar(80) NULL  ,
11   ContentEncoding varchar(80) NULL  ,
12   Content LONGTEXT NULL  ,
13   Headers LONGTEXT NULL  ,
14   Creator integer NOT NULL DEFAULT 0  ,
15   Created DATETIME NULL  ,
16   PRIMARY KEY (id)
17 ) TYPE=InnoDB;
18
19 CREATE INDEX Attachments2 ON Attachments (TransactionId) ;
20 CREATE INDEX Attachments3 ON Attachments (Parent, TransactionId) ;
21 # }}}
22
23 # {{{ Queues
24 CREATE TABLE Queues (
25   id INTEGER NOT NULL  AUTO_INCREMENT,
26   Name varchar(200) NOT NULL  ,
27   Description varchar(255) NULL  ,
28   CorrespondAddress varchar(120) NULL  ,
29   CommentAddress varchar(120) NULL  ,
30   InitialPriority integer NOT NULL DEFAULT 0  ,
31   FinalPriority integer NOT NULL DEFAULT 0  ,
32   DefaultDueIn integer NOT NULL DEFAULT 0  ,
33   Creator integer NOT NULL DEFAULT 0  ,
34   Created DATETIME NULL  ,
35   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
36   LastUpdated DATETIME NULL  ,
37   Disabled int2 NOT NULL DEFAULT 0 ,
38   PRIMARY KEY (id)
39 ) TYPE=InnoDB;
40 CREATE UNIQUE INDEX Queues1 ON Queues (Name) ;
41 CREATE INDEX Queues2 ON Queues (Disabled) ;
42
43 # }}}
44
45 # {{{ Links
46
47 CREATE TABLE Links (
48   id INTEGER NOT NULL  AUTO_INCREMENT,
49   Base varchar(240) NULL  ,
50   Target varchar(240) NULL  ,
51   Type varchar(20) NOT NULL  ,
52   LocalTarget integer NOT NULL DEFAULT 0  ,
53   LocalBase integer NOT NULL DEFAULT 0  ,
54   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
55   LastUpdated DATETIME NULL  ,
56   Creator integer NOT NULL DEFAULT 0  ,
57   Created DATETIME NULL  ,
58   PRIMARY KEY (id)
59 ) TYPE=InnoDB;
60
61 CREATE INDEX Links2 ON Links (Base,  Type) ;
62 CREATE INDEX Links3 ON Links (Target,  Type) ;
63 CREATE INDEX Links4 ON Links (Type,LocalBase);
64
65 # }}}
66
67 # {{{ Principals
68
69 CREATE TABLE Principals (
70         id INTEGER  AUTO_INCREMENT not null,
71         PrincipalType VARCHAR(16) not null,
72         ObjectId integer, # foreign key to Users or Groups, depending
73         Disabled int2 NOT NULL DEFAULT 0 ,
74         PRIMARY KEY (id)
75 ) TYPE=InnoDB;
76
77 CREATE INDEX Principals2 ON Principals (ObjectId);
78
79 # }}}
80
81 # {{{ Groups
82
83 CREATE TABLE Groups (
84   id INTEGER NOT NULL  AUTO_INCREMENT,
85   Name varchar(200) NULL  ,
86   Description varchar(255) NULL  ,
87   Domain varchar(64),
88   Type varchar(64),
89   Instance integer,
90   PRIMARY KEY (id)
91 ) TYPE=InnoDB;
92
93 CREATE INDEX Groups1 ON Groups (Domain,Instance,Type,id);
94 CREATE INDEX Groups2 On Groups (Type, Instance);   
95
96 # }}}
97
98 # {{{ ScripConditions
99
100 CREATE TABLE ScripConditions (
101   id INTEGER NOT NULL  AUTO_INCREMENT,
102   Name varchar(200) NULL  ,
103   Description varchar(255) NULL  ,
104   ExecModule varchar(60) NULL  ,
105   Argument varchar(255) NULL  ,
106   ApplicableTransTypes varchar(60) NULL  ,
107
108   Creator integer NOT NULL DEFAULT 0  ,
109   Created DATETIME NULL  ,
110   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
111   LastUpdated DATETIME NULL  ,
112   PRIMARY KEY (id)
113 ) TYPE=InnoDB;
114
115 # }}}
116
117 # {{{ Transactions
118 CREATE TABLE Transactions (
119   id INTEGER NOT NULL  AUTO_INCREMENT,
120   ObjectType varchar(64) NOT NULL,
121   ObjectId integer NOT NULL DEFAULT 0  ,
122   TimeTaken integer NOT NULL DEFAULT 0  ,
123   Type varchar(20) NULL  ,
124   Field varchar(40) NULL  ,
125   OldValue varchar(255) NULL  ,
126   NewValue varchar(255) NULL  ,
127   ReferenceType varchar(255) NULL,
128   OldReference integer NULL  ,
129   NewReference integer NULL  ,
130   Data varchar(255) NULL  ,
131
132   Creator integer NOT NULL DEFAULT 0  ,
133   Created DATETIME NULL  ,
134   PRIMARY KEY (id)
135 ) TYPE=InnoDB;
136 CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);
137
138 # }}}
139
140 # {{{ Scrips 
141
142 CREATE TABLE Scrips (
143   id INTEGER NOT NULL  AUTO_INCREMENT,
144   Description varchar(255),
145   ScripCondition integer NOT NULL DEFAULT 0  ,
146   ScripAction integer NOT NULL DEFAULT 0  ,
147   ConditionRules text NULL  ,
148   ActionRules text NULL  ,
149   CustomIsApplicableCode text NULL  ,
150   CustomPrepareCode text NULL  ,
151   CustomCommitCode text NULL  ,
152   Stage varchar(32) NULL  ,
153   Queue integer NOT NULL DEFAULT 0  ,
154   Template integer NOT NULL DEFAULT 0  ,
155   Creator integer NOT NULL DEFAULT 0  ,
156   Created DATETIME NULL  ,
157   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
158   LastUpdated DATETIME NULL  ,
159   PRIMARY KEY (id)
160 ) TYPE=InnoDB;
161
162 # }}}
163
164 # {{{ ACL
165 CREATE TABLE ACL (
166   id INTEGER NOT NULL  AUTO_INCREMENT,
167   PrincipalType varchar(25) NOT NULL, #"User" "Group", "Owner", "Cc" "AdminCc", "Requestor", "Requestor" 
168
169   PrincipalId integer NOT NULL  , #Foreign key to principals
170   RightName varchar(25) NOT NULL  ,
171   ObjectType varchar(25) NOT NULL  ,
172   ObjectId integer NOT NULL default 0,
173   DelegatedBy integer NOT NULL default 0, #foreign key to principals with a userid
174   DelegatedFrom integer NOT NULL default 0, #foreign key to ACL
175   PRIMARY KEY (id)
176 ) TYPE=InnoDB;
177
178 CREATE INDEX  ACL1 on ACL(RightName, ObjectType, ObjectId,PrincipalType,PrincipalId);
179
180 # }}}
181
182 # {{{ GroupMembers 
183
184 CREATE TABLE GroupMembers (
185   id INTEGER NOT NULL  AUTO_INCREMENT,
186   GroupId integer NOT NULL DEFAULT 0,
187   MemberId integer NOT NULL DEFAULT 0,  #Foreign key to Principals
188   PRIMARY KEY (id)
189 ) TYPE=InnoDB;
190 CREATE UNIQUE INDEX GroupMembers1 on GroupMembers (GroupId, MemberId);
191
192
193 # }}}
194
195 # {{{ GroupMembersCache
196
197 create table CachedGroupMembers (
198         id int auto_increment,
199         GroupId int, # foreign key to Principals
200         MemberId int, # foreign key to Principals
201         Via int, #foreign key to CachedGroupMembers. (may point to $self->id)
202         ImmediateParentId int, #foreign key to prinicpals.         
203                                # this points to the group that the member is
204                                # a member of, for ease of deletes.
205         Disabled int2 NOT NULL DEFAULT 0 , # if this cached group member is a member of this group by way of a disabled
206                                            # group or this group is disabled, this will be set to 1
207                                            # this allows us to not find members of disabled subgroups when listing off
208                                            # group members recursively.
209                                            # Also, this allows us to have the ACL system elide members of disabled groups
210         PRIMARY KEY (id)
211 ) TYPE=InnoDB;
212
213 CREATE INDEX DisGrouMem  on CachedGroupMembers (GroupId,MemberId,Disabled);
214
215 # }}}
216
217 # {{{ Users
218
219 CREATE TABLE Users (
220   id INTEGER NOT NULL  AUTO_INCREMENT,
221   Name varchar(200) NOT NULL  ,
222   Password varchar(40) NULL  ,
223   Comments blob NULL  ,
224   Signature blob NULL  ,
225   EmailAddress varchar(120) NULL  ,
226   FreeformContactInfo blob NULL  ,
227   Organization varchar(200) NULL  ,
228   RealName varchar(120) NULL  ,
229   NickName varchar(16) NULL  ,
230   Lang varchar(16) NULL  ,
231   EmailEncoding varchar(16) NULL  ,
232   WebEncoding varchar(16) NULL  ,
233   ExternalContactInfoId varchar(100) NULL  ,
234   ContactInfoSystem varchar(30) NULL  ,
235   ExternalAuthId varchar(100) NULL  ,
236   AuthSystem varchar(30) NULL  ,
237   Gecos varchar(16) NULL  ,
238   HomePhone varchar(30) NULL  ,
239   WorkPhone varchar(30) NULL  ,
240   MobilePhone varchar(30) NULL  ,
241   PagerPhone varchar(30) NULL  ,
242   Address1 varchar(200) NULL  ,
243   Address2 varchar(200) NULL  ,
244   City varchar(100) NULL  ,
245   State varchar(100) NULL  ,
246   Zip varchar(16) NULL  ,
247   Country varchar(50) NULL  ,
248   Timezone varchar(50) NULL  ,
249   PGPKey text NULL,
250
251   Creator integer NOT NULL DEFAULT 0  ,
252   Created DATETIME NULL  ,
253   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
254   LastUpdated DATETIME NULL  ,
255   PRIMARY KEY (id)
256 ) TYPE=InnoDB;
257
258
259 CREATE UNIQUE INDEX Users1 ON Users (Name) ;
260 CREATE INDEX Users4 ON Users (EmailAddress);
261
262
263 # }}}
264
265 # {{{ Tickets
266
267 CREATE TABLE Tickets (
268   id INTEGER NOT NULL  AUTO_INCREMENT,
269   EffectiveId integer NOT NULL DEFAULT 0  ,
270   Queue integer NOT NULL DEFAULT 0  ,
271   Type varchar(16) NULL  ,
272   IssueStatement integer NOT NULL DEFAULT 0  ,
273   Resolution integer NOT NULL DEFAULT 0  ,
274   Owner integer NOT NULL DEFAULT 0  ,
275   Subject varchar(200) NULL DEFAULT '[no subject]' ,
276   InitialPriority integer NOT NULL DEFAULT 0  ,
277   FinalPriority integer NOT NULL DEFAULT 0  ,
278   Priority integer NOT NULL DEFAULT 0  ,
279   TimeEstimated integer NOT NULL DEFAULT 0  ,
280   TimeWorked integer NOT NULL DEFAULT 0  ,
281   Status varchar(10) NULL  ,
282   TimeLeft integer NOT NULL DEFAULT 0  ,
283   Told DATETIME NULL  ,
284   Starts DATETIME NULL  ,
285   Started DATETIME NULL  ,
286   Due DATETIME NULL  ,
287   Resolved DATETIME NULL  ,
288
289
290   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
291   LastUpdated DATETIME NULL  ,
292   Creator integer NOT NULL DEFAULT 0  ,
293   Created DATETIME NULL  ,
294   Disabled int2 NOT NULL DEFAULT 0 ,
295   PRIMARY KEY (id)
296 ) TYPE=InnoDB;
297
298 CREATE INDEX Tickets1 ON Tickets (Queue, Status) ;
299 CREATE INDEX Tickets2 ON Tickets (Owner) ;
300 CREATE INDEX Tickets6 ON Tickets (EffectiveId, Type) ;
301
302 # }}}
303
304 # {{{ ScripActions
305
306 CREATE TABLE ScripActions (
307   id INTEGER NOT NULL  AUTO_INCREMENT,
308   Name varchar(200) NULL  ,
309   Description varchar(255) NULL  ,
310   ExecModule varchar(60) NULL  ,
311   Argument varchar(255) NULL  ,
312   Creator integer NOT NULL DEFAULT 0  ,
313   Created DATETIME NULL  ,
314   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
315   LastUpdated DATETIME NULL  ,
316   PRIMARY KEY (id)
317 ) TYPE=InnoDB;
318
319 # }}}
320
321 # {{{ Templates
322
323 CREATE TABLE Templates (
324   id INTEGER NOT NULL  AUTO_INCREMENT,
325   Queue integer NOT NULL DEFAULT 0 ,
326   Name varchar(200) NOT NULL  ,
327   Description varchar(255) NULL  ,
328   Type varchar(16) NULL  ,
329   Language varchar(16) NULL  ,
330   TranslationOf integer NOT NULL DEFAULT 0  ,
331   Content blob NULL  ,
332   LastUpdated DATETIME NULL  ,
333   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
334   Creator integer NOT NULL DEFAULT 0  ,
335   Created DATETIME NULL  ,
336   PRIMARY KEY (id)
337 ) TYPE=InnoDB;
338
339 # }}}
340
341 # {{{ ObjectCustomFieldValues 
342
343 CREATE TABLE ObjectCustomFieldValues (
344   id INTEGER NOT NULL  AUTO_INCREMENT,
345   CustomField int NOT NULL  ,
346   ObjectType varchar(255) NOT NULL,         # Final target of the Object
347   ObjectId int NOT NULL  ,                  # New -- Replaces Ticket
348   SortOrder integer NOT NULL DEFAULT 0  ,   # New -- ordering for multiple values
349
350   Content varchar(255) NULL  ,
351   LargeContent LONGTEXT NULL,               # New -- to hold 255+ strings
352   ContentType varchar(80) NULL,             # New -- only text/* gets searched
353   ContentEncoding varchar(80) NULL  ,       # New -- for binary Content
354
355   Creator integer NOT NULL DEFAULT 0  ,
356   Created DATETIME NULL  ,
357   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
358   LastUpdated DATETIME NULL  ,
359   Disabled int2 NOT NULL DEFAULT 0 ,        # New -- whether the value was current
360   PRIMARY KEY (id)
361 ) TYPE=InnoDB;
362
363 CREATE INDEX ObjectCustomFieldValues1 ON ObjectCustomFieldValues (Content); 
364 CREATE INDEX ObjectCustomFieldValues2 ON ObjectCustomFieldValues (CustomField,ObjectType,ObjectId); 
365
366 # }}}
367
368 # {{{ CustomFields
369
370 CREATE TABLE CustomFields (
371   id INTEGER NOT NULL  AUTO_INCREMENT,
372   Name varchar(200) NULL  ,
373   Type varchar(200) NULL  ,     # Changed -- 'Single' and 'Multiple' is moved out
374   MaxValues integer,            # New -- was 'Single'(1) and 'Multiple'(0)
375   Pattern varchar(255) NULL  ,  # New -- Must validate against this
376   Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry
377   Description varchar(255) NULL  ,
378   SortOrder integer NOT NULL DEFAULT 0  ,
379   LookupType varchar(255) NOT NULL,
380
381   Creator integer NOT NULL DEFAULT 0  ,
382   Created DATETIME NULL  ,
383   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
384   LastUpdated DATETIME NULL  ,
385   Disabled int2 NOT NULL DEFAULT 0 ,
386   PRIMARY KEY (id)
387 ) TYPE=InnoDB;
388
389 # }}}
390
391 # {{{ ObjectCustomFields 
392
393 CREATE TABLE ObjectCustomFields (
394   id INTEGER NOT NULL  AUTO_INCREMENT,
395   CustomField int NOT NULL  ,
396   ObjectId integer NOT NULL,
397   SortOrder integer NOT NULL DEFAULT 0  ,
398
399   Creator integer NOT NULL DEFAULT 0  ,
400   Created DATETIME NULL  ,
401   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
402   LastUpdated DATETIME NULL  ,
403   PRIMARY KEY (id)
404 ) TYPE=InnoDB;
405
406 # }}}
407
408 # {{{ CustomFieldValues 
409
410 CREATE TABLE CustomFieldValues (
411   id INTEGER NOT NULL  AUTO_INCREMENT,
412   CustomField int NOT NULL  ,
413   Name varchar(200) NULL  ,
414   Description varchar(255) NULL  ,
415   SortOrder integer NOT NULL DEFAULT 0  ,
416
417   Creator integer NOT NULL DEFAULT 0  ,
418   Created DATETIME NULL  ,
419   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
420   LastUpdated DATETIME NULL  ,
421   PRIMARY KEY (id)
422 ) TYPE=InnoDB;
423
424 CREATE INDEX CustomFieldValues1 ON CustomFieldValues (CustomField);
425  
426 # }}}
427
428
429 # {{{ Attributes
430
431 CREATE TABLE Attributes (
432   id INTEGER NOT NULL  AUTO_INCREMENT,
433   Name varchar(255) NULL  ,
434   Description varchar(255) NULL  ,
435   Content text,
436   ContentType varchar(16),
437   ObjectType varchar(64),
438   ObjectId integer, # foreign key to anything
439   Creator integer NOT NULL DEFAULT 0  ,
440   Created DATETIME NULL  ,
441   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
442   LastUpdated DATETIME NULL  ,
443   PRIMARY KEY (id)
444 ) TYPE=InnoDB;
445
446 CREATE INDEX Attributes1 on Attributes(Name);
447 CREATE INDEX Attributes2 on Attributes(ObjectType, ObjectId);
448
449 # }}}
450
451 # {{{ Sessions
452
453 # sessions is used by Apache::Session to keep sessions in the database.
454 # We should have a reaper script somewhere.
455
456 CREATE TABLE sessions (
457     id char(32) NOT NULL,
458     a_session LONGTEXT,
459     LastUpdated TIMESTAMP,
460     PRIMARY KEY (id)
461 );
462
463 # }}}