/
spacemanager.changelog-2.8.xml
283 lines (243 loc) · 13.1 KB
/
spacemanager.changelog-2.8.xml
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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
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
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
<changeSet id="1" author="behrmann">
<preConditions onFailMessage="Cannot upgrade directly from versions older than 1.9.5">
<or>
<not><tableExists tableName="srmspacemanagerschemaversion"/></not>
<sqlCheck expectedResult="3">SELECT version FROM srmspacemanagerschemaversion</sqlCheck>
<sqlCheck expectedResult="4">SELECT version FROM srmspacemanagerschemaversion</sqlCheck>
</or>
</preConditions>
<comment>Ensure that we only upgrade from schema version 3 or 4</comment>
</changeSet>
<changeSet id="2" author="behrmann">
<preConditions onFail="MARK_RAN" onFailMessage="Not creating space manager schema as it already exists (this is not an error)">
<not><tableExists tableName="srmspacemanagerschemaversion"/></not>
</preConditions>
<comment>Create base schema</comment>
<createTable tableName="srmspacemanagernextid">
<column name="nexttoken" type="bigint"/>
</createTable>
<insert tableName="srmspacemanagernextid">
<column name="nexttoken" value="0"/>
</insert>
<createTable tableName="srmlinkgroup">
<column name="id" type="bigint"><constraints primaryKey="true" nullable="false"/></column>
<column name="name" type="varchar(32672)"/>
<column name="freespaceinbytes" type="bigint"/>
<column name="lastupdatetime" type="bigint"/>
<column name="onlineallowed" type="int"/>
<column name="nearlineallowed" type="int"/>
<column name="replicaallowed" type="int"/>
<column name="outputallowed" type="int"/>
<column name="custodialallowed" type="int"/>
<column name="reservedspaceinbytes" type="bigint"/>
</createTable>
<createTable tableName="srmlinkgroupvos">
<column name="vogroup" type="varchar(32672)"><constraints primaryKey="true" nullable="false"/></column>
<column name="vorole" type="varchar(32672)"><constraints primaryKey="true" nullable="false"/></column>
<column name="linkgroupid" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
<addForeignKeyConstraint baseColumnNames="linkgroupid"
baseTableName="srmlinkgroupvos"
constraintName="fk_srmlinkgroupvos_l"
onDelete="RESTRICT"
referencedColumnNames="id"
referencedTableName="srmlinkgroup"/>
<createTable tableName="srmretentionpolicy">
<column name="id" type="int"><constraints primaryKey="true" nullable="false"/></column>
<column name="name" type="varchar(32672)"/>
</createTable>
<createTable tableName="srmaccesslatency">
<column name="id" type="int"><constraints primaryKey="true" nullable="false"/></column>
<column name="name" type="varchar(32672)"/>
</createTable>
<createTable tableName="srmspace">
<column name="id" type="bigint"><constraints primaryKey="true" nullable="false"/></column>
<column name="vogroup" type="varchar(32672)"/>
<column name="vorole" type="varchar(32672)"/>
<column name="retentionpolicy" type="int"/>
<column name="accesslatency" type="int"/>
<column name="linkgroupid" type="bigint"/>
<column name="sizeinbytes" type="bigint"/>
<column name="creationtime" type="bigint"/>
<column name="lifetime" type="bigint"/>
<column name="description" type="varchar(32672)"/>
<column name="state" type="int"/>
<column name="usedspaceinbytes" type="bigint"/>
<column name="allocatedspaceinbytes" type="bigint"/>
</createTable>
<addForeignKeyConstraint baseColumnNames="linkgroupid"
baseTableName="srmspace"
constraintName="fk_srmspace_l"
referencedColumnNames="id"
referencedTableName="srmlinkgroup"/>
<addForeignKeyConstraint baseColumnNames="accesslatency"
baseTableName="srmspace"
constraintName="fk_srmspace_a"
referencedColumnNames="id"
referencedTableName="srmaccesslatency"/>
<addForeignKeyConstraint baseColumnNames="retentionpolicy"
baseTableName="srmspace"
constraintName="fk_srmspace_r"
referencedColumnNames="id"
referencedTableName="srmretentionpolicy"/>
<createIndex tableName="srmspace" indexName="srmspace_linkgroupid_idx">
<column name="linkgroupid"/>
</createIndex>
<createIndex tableName="srmspace" indexName="srmspace_state_idx">
<column name="state"/>
</createIndex>
<createIndex tableName="srmspace" indexName="srmspace_description_idx">
<column name="description"/>
</createIndex>
<createIndex tableName="srmspace" indexName="srmspace_lifetime_idx">
<column name="lifetime"/>
</createIndex>
<createIndex tableName="srmspace" indexName="srmspace_creationtime_idx">
<column name="creationtime"/>
</createIndex>
<createTable tableName="srmspacefile">
<column name="id" type="bigint"><constraints primaryKey="true" nullable="false"/></column>
<column name="vogroup" type="varchar(32672)"/>
<column name="vorole" type="varchar(32672)"/>
<column name="spacereservationid" type="bigint"/>
<column name="sizeinbytes" type="bigint"/>
<column name="creationtime" type="bigint"/>
<column name="lifetime" type="bigint"/>
<column name="pnfspath" type="varchar(32672)"/>
<column name="pnfsId" type="varchar(32672)"/>
<column name="state" type="int"/>
<column name="deleted" type="int"/>
</createTable>
<addForeignKeyConstraint baseColumnNames="spacereservationid"
baseTableName="srmspacefile"
constraintName="fk_srmspacefile_l"
referencedColumnNames="id"
referencedTableName="srmspace"/>
<createIndex tableName="srmspacefile" indexName="srmspacefile_spaceresrevationid_idx">
<column name="spacereservationid"/>
</createIndex>
<createIndex tableName="srmspacefile" indexName="srmspacefile_state_idx">
<column name="state"/>
</createIndex>
<createIndex tableName="srmspacefile" indexName="srmspacefile_pnfspath_idx">
<column name="pnfspath"/>
</createIndex>
<createIndex tableName="srmspacefile" indexName="srmspacefile_pnfsid_idx">
<column name="pnfsid"/>
</createIndex>
<createIndex tableName="srmspacefile" indexName="srmspacefile_creationtime_idx">
<column name="creationtime"/>
</createIndex>
<createIndex tableName="srmspacefile" indexName="srmspacefile_lifetime_idx">
<column name="lifetime"/>
</createIndex>
<rollback/>
</changeSet>
<changeSet id="3" author="behrmann">
<preConditions onFail="MARK_RAN" onFailMessage="Not creating srmspacefile_pnfspath_state_idx as it already exists (this is not an error)">
<not><indexExists indexName="srmspacefile_pnfspath_state_idx"/></not>
</preConditions>
<comment>Create compound index on pnfspath and state field</comment>
<createIndex tableName="srmspacefile" indexName="srmspacefile_pnfspath_state_idx">
<column name="pnfspath"/>
<column name="state"/>
</createIndex>
<rollback/>
</changeSet>
<changeSet id="4" author="behrmann">
<preConditions onFail="MARK_RAN" onFailMessage="Not dropping srmspacemanagerschemaversion table as it does not exist (this is not an error)">
<tableExists tableName="srmspacemanagerschemaversion"/>
</preConditions>
<comment>Drop old schema management table</comment>
<dropTable tableName="srmspacemanagerschemaversion"/>
<rollback>
<createTable tableName="srmspacemanagerschemaversion">
<column name="version" type="int"/>
</createTable>
<insert tableName="srmspacemanagerschemaversion">
<column name="version" value="4"/>
</insert>
</rollback>
</changeSet>
<changeSet id="5" author="behrmann">
<comment>Add non-null constraints to required fields</comment>
<addNotNullConstraint tableName="srmlinkgroup" columnName="freespaceinbytes"/>
<addNotNullConstraint tableName="srmlinkgroup" columnName="reservedspaceinbytes"/>
<addNotNullConstraint tableName="srmspace" columnName="sizeinbytes"/>
<addNotNullConstraint tableName="srmspace" columnName="usedspaceinbytes"/>
<addNotNullConstraint tableName="srmspace" columnName="allocatedspaceinbytes"/>
<addNotNullConstraint tableName="srmspace" columnName="linkgroupid"/>
<addNotNullConstraint tableName="srmspace" columnName="state"/>
<addNotNullConstraint tableName="srmspacefile" columnName="sizeinbytes"/>
<addNotNullConstraint tableName="srmspacefile" columnName="spacereservationid"/>
<addNotNullConstraint tableName="srmspacefile" columnName="state"/>
</changeSet>
<changeSet id="6" author="behrmann">
<comment>Use auto-increment primary keys</comment>
<addAutoIncrement tableName="srmlinkgroup" columnName="id" columnDataType="bigint"/>
<addAutoIncrement tableName="srmspace" columnName="id" columnDataType="bigint"/>
<addAutoIncrement tableName="srmspacefile" columnName="id" columnDataType="bigint"/>
<rollback/>
</changeSet>
<changeSet id="7" author="behrmann" dbms="postgresql">
<!-- A workaround to https://liquibase.jira.com/browse/CORE-1705 -->
<comment>Postgresql specific auto increment sequences initialization</comment>
<sql>
SELECT setval('srmlinkgroup_id_seq', (SELECT max(id) FROM srmlinkgroup));
SELECT setval('srmspace_id_seq', (SELECT max(id) FROM srmspace));
SELECT setval('srmspacefile_id_seq', (SELECT max(id) FROM srmspacefile));
</sql>
<!-- This rollback really belongs to changeset 6. It is however postgresql
specific, so we put it here. -->
<rollback>
DROP SEQUENCE srmlinkgroup_id_seq CASCADE;
DROP SEQUENCE srmspace_id_seq CASCADE;
DROP SEQUENCE srmspacefile_id_seq CASCADE;
</rollback>
</changeSet>
<changeSet id="8" author="behrmann">
<comment>Drop sequence table</comment>
<dropTable tableName="srmspacemanagernextid"/>
<rollback>
<createTable tableName="srmspacemanagernextid">
<column name="nexttoken" type="bigint"/>
</createTable>
<insert tableName="srmspacemanagernextid">
<column name="nexttoken" value="0"/>
</insert>
<sql>
UPDATE srmspacemanagernextid SET nexttoken =
GREATEST(nexttoken,
GREATEST(COALESCE((SELECT max(id) FROM srmlinkgroup), 0),
COALESCE((SELECT max(id) FROM srmspace), 0),
COALESCE((SELECT max(id) FROM srmspacefile), 0)) + 1)
</sql>
</rollback>
</changeSet>
<changeSet id="9" author="behrmann">
<comment>Drop index on pnfsid column</comment>
<dropIndex tableName="srmspacefile" indexName="srmspacefile_pnfsid_idx"/>
<rollback>
<createIndex tableName="srmspacefile" indexName="srmspacefile_pnfsid_idx">
<column name="pnfsid"/>
</createIndex>
</rollback>
</changeSet>
<changeSet id="10" author="behrmann">
<comment>Change pnfsid column to VARCHAR(36)</comment>
<modifyDataType tableName="srmspacefile" columnName="pnfsid" newDataType="varchar(36)"/>
<rollback>
<modifyDataType tableName="srmspacefile" columnName="pnfsid" newDataType="varchar(32672)"/>
</rollback>
</changeSet>
<changeSet id="11" author="behrmann">
<comment>Add unique constraint (and thus index) on pnfsid column</comment>
<addUniqueConstraint tableName="srmspacefile" columnNames="pnfsid" constraintName="srmspacefile_pnfsid_unique"/>
</changeSet>
</databaseChangeLog>