Release 0.6.6
[grauphel.git] / tools / database.xsd
1 <?xml version="1.0"?>
2 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3            elementFormDefault="qualified" attributeFormDefault="unqualified">
4     <xs:element name="database">
5         <xs:annotation>
6             <xs:documentation>Database definition. These xml files were once
7                 used for MDB2 which was a major source of bugs and
8                 unmaintained. To keep compatibility the xml files definitions
9                 are now parsed and used to create Doctrine schemas. To trigger
10                 a database migration you need to increase your version number
11                 in your info.xml file
12             </xs:documentation>
13         </xs:annotation>
14         <xs:complexType>
15             <xs:sequence>
16                 <xs:element name="name" type="non-empty-string" minOccurs="0"
17                             maxOccurs="1">
18                     <xs:annotation>
19                         <xs:documentation>Value is ignored</xs:documentation>
20                     </xs:annotation>
21                 </xs:element>
22                 <xs:element name="create" type="xs:boolean" minOccurs="0"
23                             maxOccurs="1">
24                     <xs:annotation>
25                         <xs:documentation>Value is ignored</xs:documentation>
26                     </xs:annotation>
27                 </xs:element>
28                 <xs:element name="overwrite" type="xs:boolean" minOccurs="0"
29                             maxOccurs="1">
30                     <xs:annotation>
31                         <xs:documentation>Value is ignored</xs:documentation>
32                     </xs:annotation>
33                 </xs:element>
34                 <xs:element name="charset" type="non-empty-string"
35                             minOccurs="0"
36                             maxOccurs="1">
37                     <xs:annotation>
38                         <xs:documentation>Value is ignored</xs:documentation>
39                     </xs:annotation>
40                 </xs:element>
41                 <xs:element name="table" type="table" minOccurs="1"
42                             maxOccurs="unbounded">
43                     <xs:annotation>
44                         <xs:documentation>Each table contains a full database
45                             table
46                         </xs:documentation>
47                     </xs:annotation>
48                 </xs:element>
49             </xs:sequence>
50         </xs:complexType>
51     </xs:element>
52
53     <!-- basic types -->
54     <xs:simpleType name="non-empty-string">
55         <xs:restriction base="xs:string">
56             <xs:minLength value="1"/>
57         </xs:restriction>
58     </xs:simpleType>
59
60     <xs:complexType name="table">
61         <xs:sequence>
62             <xs:element name="name" type="non-empty-string" minOccurs="1"
63                         maxOccurs="1">
64                 <xs:annotation>
65                     <xs:documentation>Table name. You can and should use
66                         *dbprefix* before your table, e.g.
67                         *dbprefix*news_items. The value will be replaced with a
68                         configurable prefix and defaults to "oc_"
69                     </xs:documentation>
70                 </xs:annotation>
71             </xs:element>
72             <xs:element name="create" type="xs:boolean" minOccurs="0"
73                         maxOccurs="1">
74                 <xs:annotation>
75                     <xs:documentation>Value is ignored</xs:documentation>
76                 </xs:annotation>
77             </xs:element>
78             <xs:element name="overwrite" type="xs:boolean" minOccurs="0"
79                         maxOccurs="1">
80                 <xs:annotation>
81                     <xs:documentation>Value is ignored</xs:documentation>
82                 </xs:annotation>
83             </xs:element>
84             <xs:element name="charset" type="non-empty-string" minOccurs="0"
85                         maxOccurs="1">
86                 <xs:annotation>
87                     <xs:documentation>Value is ignored</xs:documentation>
88                 </xs:annotation>
89             </xs:element>
90             <xs:element name="declaration" type="declaration" minOccurs="1"
91                         maxOccurs="1">
92                 <xs:annotation>
93                     <xs:documentation>Contains the actual database columns and
94                         indices
95                     </xs:documentation>
96                 </xs:annotation>
97             </xs:element>
98         </xs:sequence>
99     </xs:complexType>
100
101     <xs:complexType name="declaration">
102         <xs:sequence>
103             <xs:element name="field" type="field" minOccurs="0"
104                         maxOccurs="unbounded">
105                 <xs:annotation>
106                     <xs:documentation>A list of columns</xs:documentation>
107                 </xs:annotation>
108             </xs:element>
109             <xs:element name="index" type="index" minOccurs="0"
110                         maxOccurs="unbounded">
111                 <xs:annotation>
112                     <xs:documentation>A list of indices on that table
113                     </xs:documentation>
114                 </xs:annotation>
115             </xs:element>
116         </xs:sequence>
117     </xs:complexType>
118
119     <xs:complexType name="field">
120         <xs:sequence>
121             <xs:element name="name" type="non-empty-string" minOccurs="1"
122                         maxOccurs="1">
123                 <xs:annotation>
124                     <xs:documentation>Column name</xs:documentation>
125                 </xs:annotation>
126             </xs:element>
127             <xs:element name="type" type="field-type" minOccurs="1"
128                         maxOccurs="1">
129                 <xs:annotation>
130                     <xs:documentation>Column types. Certain types like integer
131                         (aka smallint, integer, bigint), clob (aka text), text
132                         (aka string), timestamp (aka datetime) and numeric (aka
133                         decimal) are special to Nextcloud and will be
134                         translated to their doctrine equivalents. Everything
135                         else will be sent as is to doctrines type system. See
136                         http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html
137                         for a list of all types
138                     </xs:documentation>
139                 </xs:annotation>
140             </xs:element>
141             <xs:element name="length" type="xs:int" minOccurs="0"
142                         maxOccurs="1">
143                 <xs:annotation>
144                     <xs:documentation>Length of the type. This will not only
145                         define how long your text columns aka VARCHARs will be
146                         set but also determine the size of the integer field:
147                         &lt; 4 will be transformed to smallint, 4 will be
148                         transformed to integer and &gt; 4 will be transformed
149                         to bigint
150                     </xs:documentation>
151                 </xs:annotation>
152             </xs:element>
153             <xs:element name="unsigned" type="xs:boolean" minOccurs="0"
154                         maxOccurs="1">
155                 <xs:annotation>
156                     <xs:documentation>Can only be set for numeric values like
157                         float, integer, etc. and will make them unsigned
158                     </xs:documentation>
159                 </xs:annotation>
160             </xs:element>
161             <xs:element name="notnull" type="xs:boolean" minOccurs="0"
162                         maxOccurs="1">
163                 <xs:annotation>
164                     <xs:documentation>If a value should never be null
165                     </xs:documentation>
166                 </xs:annotation>
167             </xs:element>
168             <xs:element name="autoincrement" type="xs:boolean" minOccurs="0"
169                         maxOccurs="1">
170                 <xs:annotation>
171                     <xs:documentation>Can only be set for primary keys
172                     </xs:documentation>
173                 </xs:annotation>
174             </xs:element>
175             <xs:element name="default" type="xs:string" minOccurs="0"
176                         maxOccurs="1">
177                 <xs:annotation>
178                     <xs:documentation>Default value if given. Can also be empty
179                         in which case the default will be an empty string.
180                     </xs:documentation>
181                 </xs:annotation>
182             </xs:element>
183             <xs:element name="comments" type="non-empty-string" minOccurs="0"
184                         maxOccurs="1">
185                 <xs:annotation>
186                     <xs:documentation>Doctrine comment, can be ignored
187                     </xs:documentation>
188                 </xs:annotation>
189             </xs:element>
190             <xs:element name="primary" type="xs:boolean" minOccurs="0"
191                         maxOccurs="1">
192                 <xs:annotation>
193                     <xs:documentation>True for the primary key. For composed
194                         primary keys use a unique index.
195                     </xs:documentation>
196                 </xs:annotation>
197             </xs:element>
198             <xs:element name="precision" type="xs:int" minOccurs="0"
199                         maxOccurs="1">
200                 <xs:annotation>
201                     <xs:documentation>Total number of digits for a
202                         numerics/decimal type including decimal digits, e.g.
203                         precision 3 and scale 2 will only allow 3.21 but not
204                         23.21
205                     </xs:documentation>
206                 </xs:annotation>
207             </xs:element>
208             <xs:element name="scale" type="xs:int" minOccurs="0"
209                         maxOccurs="1">
210                 <xs:annotation>
211                     <xs:documentation>Scale for a numeric/decimal type, e.g. 2
212                         will save decimals with two decimal places: 3.21
213                     </xs:documentation>
214                 </xs:annotation>
215             </xs:element>
216         </xs:sequence>
217     </xs:complexType>
218
219     <xs:simpleType name="field-type">
220         <xs:restriction base="xs:string">
221             <!-- smallint and bigint are set by setting a length smaller or bigger than 4 -->
222             <xs:enumeration value="integer"/>
223             <!-- clob equals text -->
224             <xs:enumeration value="clob"/>
225             <!-- text equals string -->
226             <xs:enumeration value="text"/>
227             <!-- timestamp equals datetime -->
228             <xs:enumeration value="timestamp"/>
229             <!-- numeric equals decimal -->
230             <xs:enumeration value="numeric"/>
231             <!-- doctrine types minus Nextcloud mappings-->
232             <xs:enumeration value="smallint"/>
233             <xs:enumeration value="bigint"/>
234             <xs:enumeration value="decimal"/>
235             <xs:enumeration value="float"/>
236             <xs:enumeration value="string"/>
237             <xs:enumeration value="text"/>
238             <xs:enumeration value="guid"/>
239             <xs:enumeration value="binary"/>
240             <xs:enumeration value="blob"/>
241             <xs:enumeration value="boolean"/>
242             <xs:enumeration value="date"/>
243             <xs:enumeration value="datetime"/>
244             <xs:enumeration value="datetimetz"/>
245             <xs:enumeration value="time"/>
246             <xs:enumeration value="dateinterval"/>
247             <xs:enumeration value="json"/>
248             <!-- object and arrays are not covered since support is bad -->
249         </xs:restriction>
250     </xs:simpleType>
251
252     <xs:complexType name="index">
253         <xs:annotation>
254             <xs:documentation>Element for defining indices. Can also be used to
255                 define composite primary keys: simply add more than one field
256                 to an index and define it as unique
257             </xs:documentation>
258         </xs:annotation>
259         <xs:sequence>
260             <xs:element name="name" type="non-empty-string" minOccurs="1"
261                         maxOccurs="1">
262                 <xs:annotation>
263                     <xs:documentation>Index name. Should be unique
264                     </xs:documentation>
265                 </xs:annotation>
266             </xs:element>
267             <xs:element name="primary" type="xs:boolean" minOccurs="0"
268                         maxOccurs="1">
269                 <xs:annotation>
270                     <xs:documentation>True if the index is in fact a primary
271                         key. Will be ignored if the primary key is already set
272                         in the field section
273                     </xs:documentation>
274                 </xs:annotation>
275             </xs:element>
276             <xs:element name="unique" type="xs:boolean" minOccurs="0"
277                         maxOccurs="1">
278                 <xs:annotation>
279                     <xs:documentation>If the index for the field or combination
280                         of fields should be unique
281                     </xs:documentation>
282                 </xs:annotation>
283             </xs:element>
284             <xs:element name="field" type="index-field" minOccurs="1"
285                         maxOccurs="unbounded">
286                 <xs:annotation>
287                     <xs:documentation>List of index fields that are used to
288                         create the index
289                     </xs:documentation>
290                 </xs:annotation>
291             </xs:element>
292         </xs:sequence>
293     </xs:complexType>
294
295     <xs:complexType name="index-field">
296         <xs:sequence>
297             <xs:element name="name" type="non-empty-string" minOccurs="1"
298                         maxOccurs="1">
299                 <xs:annotation>
300                     <xs:documentation>Name of the column that should be
301                         indexed
302                     </xs:documentation>
303                 </xs:annotation>
304             </xs:element>
305             <xs:element name="sorting" type="index-sorting" minOccurs="0"
306                         maxOccurs="1">
307                 <xs:annotation>
308                     <xs:documentation>Value is ignored</xs:documentation>
309                 </xs:annotation>
310             </xs:element>
311         </xs:sequence>
312     </xs:complexType>
313
314     <xs:simpleType name="index-sorting">
315         <xs:restriction base="xs:string">
316             <xs:enumeration value="ascending"/>
317             <xs:enumeration value="descending"/>
318         </xs:restriction>
319     </xs:simpleType>
320 </xs:schema>