dbupdate.xml 22.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2007 Volker Krause <vkrause@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.

-->


<!--
  Akonadi Database Schema Update Description

  update element:
    text: SQL statement to execute for update
    version attribute: the new schmema version
    abortOnFailure attribute: if true, the update must succeed, otherwise failures are ignored
31
32
33

  Please note: if you're adding a column to the db then you DON'T need to add an update
  statement here. Add your column to akonadidb.xml instead: it will be added to the db automagically.
34
35
36
37
-->
<updates>

  <update version="2" abortOnFailure="false">
38
39
40
41
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable DROP COLUMN existCount;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable DROP COLUMN recentCount;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable DROP COLUMN unseenCount;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable DROP COLUMN firstUnseen;</raw-sql>
42
43
  </update>

44
  <update version="3" abortOnFailure="false">
45
    <raw-sql backends="mysql,psql,sqlite">UPDATE LocationTable SET subscribed = true;</raw-sql>
46
47
  </update>

48
  <update version="4" abortOnFailure="false">
49
50
51
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable DROP COLUMN cachePolicyId;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE ResourceTable DROP COLUMN cachePolicyId;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">DROP TABLE CachePolicyTable;</raw-sql>
52
53
  </update>

54
  <update version="8" abortOnFailure="false">
55
56
57
58
    <raw-sql backends="mysql,psql,sqlite">UPDATE PartTable SET name = 'PLD:ENVELOPE' WHERE name = 'ENVELOPE';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">UPDATE PartTable SET name = 'PLD:RFC822' WHERE name = 'RFC822';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">UPDATE PartTable SET name = 'PLD:HEAD' WHERE name = 'HEAD';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">UPDATE PartTable SET name = concat( 'ATR:', name ) WHERE substr( name, 1, 4 ) != 'PLD:';</raw-sql>
59
60
  </update>

61
62
63
  <!-- the initializer runs first, so we will have all the new tables and columns already
       therefore we have to clean that up first -->
  <update version="10" abortOnFailure="true">
64
65
66
67
68
69
70
71
72
73
74
75
76
    <raw-sql backends="mysql,psql,sqlite">DROP TABLE CollectionTable;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationTable RENAME TO CollectionTable;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PimItemTable DROP COLUMN collectionId;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PimItemTable CHANGE locationId collectionId BIGINT;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">DROP TABLE CollectionAttributeTable;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationAttributeTable CHANGE locationId collectionId BIGINT;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationAttributeTable RENAME TO CollectionAttributeTable;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">DROP TABLE CollectionMimeTypeRelation;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationMimeTypeRelation CHANGE Location_Id Collection_Id BIGINT NOT NULL DEFAULT '0';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationMimeTypeRelation RENAME TO CollectionMimeTypeRelation;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">DROP TABLE CollectionPimItemRelation;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationPimItemRelation CHANGE Location_Id Collection_Id BIGINT NOT NULL DEFAULT '0';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE LocationPimItemRelation RENAME TO CollectionPimItemRelation;</raw-sql>
77
78
  </update>

79
  <update version="12" abortOnFailure="false">
80
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PartTable CHANGE datasize datasize BIGINT;</raw-sql>
81
82
83
  </update>

  <update version="13" abortOnFailure="true">
84
85
    <raw-sql backends="mysql,psql,sqlite">UPDATE CollectionTable SET parentId = NULL WHERE parentId = 0;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE CollectionTable CHANGE parentId parentId BIGINT DEFAULT NULL;</raw-sql>
86
  </update>
87

88
  <update version="14" abortOnFailure="false">
89
90
    <raw-sql backends="mysql,psql,sqlite">UPDATE ResourceTable SET isVirtual = true WHERE name = 'akonadi_nepomuktag_resource';</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">UPDATE ResourceTable SET isVirtual = true WHERE name = 'akonadi_search_resource';</raw-sql>
91
92
  </update>

93
  <update version="15" abortOnFailure="false">
94
95
    <raw-sql backends="mysql,psql,sqlite">UPDATE CollectionTable SET queryString = remoteId WHERE resourceId = 1 AND parentId IS NOT NULL;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">UPDATE CollectionTable SET queryLanguage = 'SPARQL' WHERE resourceId = 1 AND parentId IS NOT NULL;</raw-sql>
96
97
  </update>

98
  <update version="16" abortOnFailure="false">
99
100
101
102
103
104
105
106
107
108
109
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE CollectionAttributeTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE CollectionMimeTypeRelation CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE CollectionPimItemRelation CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE CollectionTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE FlagTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE MimeTypeTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PartTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PimItemFlagRelation CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE PimitemTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE ResourceTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">ALTER TABLE SchemaVersionTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;</raw-sql>
110
  </update>
111
112
113
114

  <!-- change all string based columns to use BINARY flag, this makes the comparison operator
       finally work -->
  <update version="17" abortOnFailure="false">
115
116
117
118
119
120
121
122
123
124
125
126
    <raw-sql backends="mysql">ALTER TABLE ResourceTable CHANGE name name VARCHAR(255) BINARY UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE remoteId remoteId VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE remoteRevision remoteRevision VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE name name VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE cachePolicyLocalParts cachePolicyLocalParts VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryString queryString VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryLanguage queryLanguage VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE MimeTypeTable CHANGE name name VARCHAR(255) BINARY UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PimItemTable CHANGE remoteId remoteId VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PimItemTable CHANGE remoteRevision remoteRevision VARCHAR(255) BINARY;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE FlagTable CHANGE name name VARCHAR(255) BINARY UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PartTable CHANGE name name VARCHAR(255) BINARY;</raw-sql>
127
  </update>
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

  <!-- change all string based columns to VARBINARY to make indexes and comparison operator work -->
  <update version="18" abortOnFailure="false">
    <raw-sql backends="mysql">ALTER TABLE ResourceTable CHANGE name name VARBINARY(255) UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE remoteId remoteId VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE remoteRevision remoteRevision VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE name name VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE cachePolicyLocalParts cachePolicyLocalParts VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryString queryString VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryLanguage queryLanguage VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE MimeTypeTable CHANGE name name VARBINARY(255) UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PimItemTable CHANGE remoteId remoteId VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PimItemTable CHANGE remoteRevision remoteRevision VARBINARY(255);</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE FlagTable CHANGE name name VARBINARY(255) UNIQUE;</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PartTable CHANGE name name VARBINARY(255);</raw-sql>
  </update>
144
  <update version="19" abortOnFailure="false">
145
146
    <raw-sql backends="mysql,psql,sqlite">UPDATE PimItemFlagRelation SET Flag_id=(SELECT id FROM FlagTable WHERE name='\\SEEN') WHERE Flag_id=(SELECT id FROM FlagTable WHERE name='\\Seen');</raw-sql>
    <raw-sql backends="mysql,psql,sqlite">DELETE FROM FlagTable WHERE name='\\Seen';</raw-sql>
147
  </update>
148
149
150
151
152

  <!-- wider query column (only affects MySQL) -->
  <update version="20" abortOnFailure="false">
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryString queryString VARBINARY(1024);</raw-sql>
  </update>
153
154
155
156
157

  <!-- even wider query column (only affects MySQL) -->
  <update version="21" abortOnFailure="false">
    <raw-sql backends="mysql">ALTER TABLE CollectionTable CHANGE queryString queryString VARBINARY(32768);</raw-sql>
  </update>
158
159
160
161
162
163
164
165
166
167

  <!-- fix previously wrongly used 32bit column type on n:m helper tables (TODO: also needed for the other backends) -->
  <update version="22" abortOnFailure="false">
    <raw-sql backends="mysql">ALTER TABLE PimItemFlagRelation CHANGE PimItem_id PimItem_id BIGINT NOT NULL</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE PimItemFlagRelation CHANGE Flag_id Flag_id BIGINT NOT NULL</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionMimeTypeRelation CHANGE Collection_id Collection_id BIGINT NOT NULL</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionMimeTypeRelation CHANGE MimeType_id MimeType_id BIGINT NOT NULL</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionPimItemRelation CHANGE Collection_id Collection_id BIGINT NOT NULL</raw-sql>
    <raw-sql backends="mysql">ALTER TABLE CollectionPimItemRelation CHANGE PimItem_id PimItem_id BIGINT NOT NULL</raw-sql>
  </update>
168
169

  <update version="23" abortOnFailure="false">
170
    <raw-sql backends="mysql,psql">UPDATE CollectionTable SET isVirtual = true WHERE resourceId IN (SELECT id FROM ResourceTable WHERE isVirtual = true)</raw-sql>
Daniel Vrátil's avatar
Daniel Vrátil committed
171
    <raw-sql backends="sqlite">UPDATE CollectionTable SET isVirtual = 1 WHERE resourceId IN (SELECT id FROM ResourceTable WHERE isVirtual = 1)</raw-sql>
172
  </update>
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
  <update version="24" abortOnFailure="false">
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER remoteId TYPE text USING convert_from(remoteId,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER remoteRevision TYPE text USING convert_from(remoteRevision,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER name TYPE text USING convert_from(name,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER cachePolicyLocalParts TYPE text USING convert_from(cachePolicyLocalParts,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER queryString TYPE text USING convert_from(queryString,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE CollectionTable ALTER queryLanguage TYPE text USING convert_from(queryLanguage,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE FlagTable ALTER name TYPE text USING convert_from(name,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE MimeTypeTable ALTER name TYPE text USING convert_from(name,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE PartTable ALTER name TYPE text USING convert_from(name,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE PimItemTable ALTER remoteId TYPE text USING convert_from(remoteId,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE PimItemTable ALTER remoteRevision TYPE text USING convert_from(remoteRevision,'utf8');</raw-sql>
    <raw-sql backends="psql">ALTER TABLE ResourceTable ALTER name TYPE text USING convert_from(name,'utf8');</raw-sql>
  </update>
188

189
  <!-- adapt to new part type table layout
190
191
    (1) perform complex update by populating PartTypeTable and updating partTypeId column in PartTable
    (2) drop the old part name column in the part table
192
193
  -->
  <update version="25" abortOnFailure="true">
194
    <complex-update backends="mysql,psql,sqlite" />
195
  </update>
196

197
198
199
200
201
  <update version="26" abortOnFailure="false">
    <raw-sql backends="mysql,psql,sqlite">UPDATE CollectionTable SET queryAttributes = 'QUERYLANGUAGE SPARQL' WHERE queryLanguage = 'SPARQL';</raw-sql>
    <raw-sql backends="mysql,psql">ALTER TABLE CollectionTable DROP COLUMN queryLanguage;</raw-sql>
  </update>

202
203
204
205
206
  <update version="28" abortOnFailure="false">
    <raw-sql backends="mysql,psql,sqlite">UPDATE CollectionTable SET enabled = subscribed;</raw-sql>
    <raw-sql backends="mysql,psql">ALTER TABLE CollectionTable DROP COLUMN subscribed;</raw-sql>
  </update>

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  <!--
   Update 30 fixes missing constraints on relation tables in PostgreSQL.
   We cannot just let DbInitializer create the foreign keys there, because data
   in the relation tables might reference rows from other tables that no longer
   exist.
  -->
  <update version="30" abortOnFailure="false">
    <!-- PimItemFlagRelation -->
    <raw-sql backends="psql">DELETE FROM PimItemFlagRelation WHERE pimItem_id IN (
                                SELECT pimItem_id FROM PimItemFlagRelation
                                LEFT JOIN PimItemTable ON PimItemFlagRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL)
    </raw-sql>
    <raw-sql backends="psql">DELETE FROM PimItemFlagRelation WHERE flag_id IN (
                                SELECT flag_id FROM PimItemFlagRelation
                                LEFT JOIN FlagTable ON PimItemFlagRelation.flag_id = FlagTable.id
                                WHERE FlagTable.id IS NULL)
    </raw-sql>
    <!-- PimItemTagRelation -->
    <raw-sql backends="psql">DELETE FROM PimItemTagRelation WHERE pimItem_id IN (
                                SELECT pimItem_id FROM PimItemTagRelation
                                LEFT JOIN PimItemTable ON PimItemTagRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL)
    </raw-sql>
    <raw-sql backends="psql">DELETE FROM PimItemTagRelation WHERE tag_id IN (
                                SELECT tag_id FROM PimItemTagRelation
                                LEFT JOIN TagTable ON PimItemTagRelation.tag_id = TagTable.id
                                WHERE TagTable.id IS NULL)
    </raw-sql>
    <!-- CollectionMimeTypeRelation -->
    <raw-sql backends="psql">DELETE FROM CollectionMimeTypeRelation WHERE collection_id IN (
                                SELECT collection_id FROM CollectionMimeTypeRelation
                                LEFT JOIN CollectionTable ON CollectionMimeTypeRelation.collection_id = CollectionTable.id
                                WHERE CollectionTable.id IS NULL)
    </raw-sql>
    <raw-sql backends="psql">DELETE FROM CollectionMimeTypeRelation WHERE mimeType_id IN (
                                SELECT mimeType_id FROM CollectionMimeTypeRelation
                                LEFT JOIN MimeTypeTable ON CollectionMimeTypeRelation.mimeType_id = MimeTypeTable.id
                                WHERE MimeTypeTable.id IS NULL)
    </raw-sql>
    <!-- CollectionPimItemRelation -->
    <raw-sql backends="psql">DELETE FROM CollectionPimItemRelation WHERE collection_id IN (
                                SELECT collection_id FROM CollectionPimItemRelation
                                LEFT JOIN CollectionTable ON CollectionPimItemRelation.collection_id = CollectionTable.id
                                WHERE CollectionTable.id IS NULL)
    </raw-sql>
    <raw-sql backends="psql">DELETE FROM CollectionPimItemRelation WHERE pimItem_id IN (
                                SELECT pimItem_id FROM CollectionPimItemRelation
                                LEFT JOIN PimItemTable ON CollectionPimItemRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL)
    </raw-sql>
  </update>
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  <!--
   Update 31 fixes missing constraints on relation tables in MySQL.
   We cannot just let DbInitializer create the foreign keys there, because data
   in the relation tables might reference rows from other tables that no longer
   exist.
  -->
  <update version="31" abortOnFailure="false">
    <!-- PimItemFlagRelation -->
    <raw-sql backends="mysql">DELETE FROM PimItemFlagRelation WHERE pimItem_id IN (
                                SELECT id FROM (
                                SELECT pimItem_id AS id FROM PimItemFlagRelation
                                LEFT JOIN PimItemTable ON PimItemFlagRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL) x)
    </raw-sql>
    <raw-sql backends="mysql">DELETE FROM PimItemFlagRelation WHERE flag_id IN (
                                SELECT id FROM (
                                SELECT flag_id AS id FROM PimItemFlagRelation
                                LEFT JOIN FlagTable ON PimItemFlagRelation.flag_id = FlagTable.id
                                WHERE FlagTable.id IS NULL) x)
    </raw-sql>
    <!-- PimItemTagRelation -->
    <raw-sql backends="mysql">DELETE FROM PimItemTagRelation WHERE pimItem_id IN (
                                SELECT id FROM (
                                SELECT pimItem_id AS id FROM PimItemTagRelation
                                LEFT JOIN PimItemTable ON PimItemTagRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL) x)
    </raw-sql>
    <raw-sql backends="mysql">DELETE FROM PimItemTagRelation WHERE tag_id IN (
                                SELECT id FROM (
                                SELECT tag_id AS id FROM PimItemTagRelation
                                LEFT JOIN TagTable ON PimItemTagRelation.tag_id = TagTable.id
                                WHERE TagTable.id IS NULL) x)
    </raw-sql>
    <!-- CollectionMimeTypeRelation -->
    <raw-sql backends="mysql">DELETE FROM CollectionMimeTypeRelation WHERE collection_id IN (
                                SELECT id FROM (
                                SELECT collection_id AS id  FROM CollectionMimeTypeRelation
                                LEFT JOIN CollectionTable ON CollectionMimeTypeRelation.collection_id = CollectionTable.id
                                WHERE CollectionTable.id IS NULL) x)
    </raw-sql>
    <raw-sql backends="mysql">DELETE FROM CollectionMimeTypeRelation WHERE mimeType_id IN (
                                SELECT id FROM (
                                SELECT mimeType_id AS id FROM CollectionMimeTypeRelation
                                LEFT JOIN MimeTypeTable ON CollectionMimeTypeRelation.mimeType_id = MimeTypeTable.id
                                WHERE MimeTypeTable.id IS NULL) x)
    </raw-sql>
    <!-- CollectionPimItemRelation -->
    <raw-sql backends="mysql">DELETE FROM CollectionPimItemRelation WHERE collection_id IN (
                                SELECT id FROM (
                                SELECT collection_id AS id FROM CollectionPimItemRelation
                                LEFT JOIN CollectionTable ON CollectionPimItemRelation.collection_id = CollectionTable.id
                                WHERE CollectionTable.id IS NULL) x)
    </raw-sql>
    <raw-sql backends="mysql">DELETE FROM CollectionPimItemRelation WHERE pimItem_id IN (
                                SELECT id FROM (
                                SELECT pimItem_id AS id FROM CollectionPimItemRelation
                                LEFT JOIN PimItemTable ON CollectionPimItemRelation.pimItem_id = PimItemTable.id
                                WHERE PimItemTable.id IS NULL) x)
    </raw-sql>
  </update>
319
  <update version="33" abortOnFailure="false">
320
321
    <raw-sql backends="psql">SELECT setval('tagtypetable_id_seq', (SELECT max(id) FROM TagTypeTable))</raw-sql>
    <raw-sql backends="psql">SELECT setval('relationtypetable_id_seq', (SELECT max(id) FROM RelationTypeTable))</raw-sql>
322
  </update>
323
324

  <update version="35" abortOnFailure="true">
325
    <raw-sql backends="mysql,sqlite">UPDATE PartTable SET storage = external;</raw-sql>
326
327
    <raw-sql backends="mysql">ALTER TABLE PartTable DROP COLUMN external;</raw-sql>
    <!-- TODO: SQLITE: drop the column as well, but SQLite does not have DROP COLUMN //-->
328
329
    <raw-sql backends="psql">UPDATE PartTable SET storage = cast(external as integer);</raw-sql>
    <raw-sql backends="psql">ALTER TABLE PartTable DROP COLUMN external;</raw-sql>
330
  </update>
331
</updates>