4aa41e46151bb2a036e492fc4c769bb2947be106
[policy/parent.git] / docs / development / devtools / db-migrator-smoke.rst
1 .. This work is licensed under a  Creative Commons Attribution
2 .. 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
4
5 Policy DB Migrator Smoke Tests
6 ##############################
7
8 Prerequisites
9 *************
10
11 Check number of files in each release
12
13 .. code::
14   :number-lines:
15
16     ls 0800/upgrade/*.sql | wc -l = 96
17     ls 0900/upgrade/*.sql | wc -l = 13
18     ls 0800/downgrade/*.sql | wc -l = 96
19     ls 0900/downgrade/*.sql | wc -l = 13
20
21 Upgrade scripts
22 ===============
23
24 .. code::
25   :number-lines:
26
27     /opt/app/policy/bin/prepare_upgrade.sh policyadmin
28     /opt/app/policy/bin/db-migrator -s policyadmin -o upgrade
29
30 .. note::
31    You can also run db-migrator upgrade with the -t and -f options
32
33 Downgrade scripts
34 =================
35
36 .. code::
37   :number-lines:
38
39     /opt/app/policy/bin/prepare_downgrade.sh policyadmin
40     /opt/app/policy/bin/db-migrator -s policyadmin -o downgrade -f 0900 -t 0800
41
42 Db migrator initialization script
43 =================================
44
45 Update /oom/kubernetes/policy/resources/config/db_migrator_policy_init.sh with the appropriate upgrade/downgrade calls.
46
47 The policy version you are deploying should either be an upgrade or downgrade from the current db migrator schema version.
48
49 Every time you modify db_migrator_policy_init.sh you will have to undeploy, make and redeploy before updates are applied.
50
51 1. Fresh Install
52 ****************
53
54 .. list-table::
55    :widths: 60 20
56    :header-rows: 0
57
58    * - Number of files run
59      - 109
60    * - Tables in policyadmin
61      - 75
62    * - Records Added
63      - 109
64    * - schema_version
65      - 0900
66
67 2. Downgrade to Honolulu (0800)
68 *******************************
69
70 Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"
71
72 Make/Redeploy to run downgrade.
73
74 .. list-table::
75    :widths: 60 20
76    :header-rows: 0
77
78    * - Number of files run
79      - 13
80    * - Tables in policyadmin
81      - 73
82    * - Records Added
83      - 13
84    * - schema_version
85      - 0800
86
87 3. Upgrade to Istanbul (0900)
88 *****************************
89
90 Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts".
91
92 Make/Redeploy to run upgrade.
93
94 .. list-table::
95    :widths: 60 20
96    :header-rows: 0
97
98    * - Number of files run
99      - 13
100    * - Tables in policyadmin
101      - 75
102    * - Records Added
103      - 13
104    * - schema_version
105      - 0900
106
107 4. Upgrade to Istanbul (0900) without any information in the migration schema
108 *****************************************************************************
109
110 Ensure you are on release 0800. (This may require running a downgrade before starting the test)
111
112 Drop db-migrator tables in migration schema:
113
114 .. code::
115   :number-lines:
116
117     DROP TABLE schema_versions;
118     DROP TABLE policyadmin_schema_changelog;
119
120 Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts".
121
122 Make/Redeploy to run upgrade.
123
124 .. list-table::
125    :widths: 60 20
126    :header-rows: 0
127
128    * - Number of files run
129      - 13
130    * - Tables in policyadmin
131      - 75
132    * - Records Added
133      - 13
134    * - schema_version
135      - 0900
136
137 5. Upgrade to Istanbul (0900) after failed downgrade
138 ****************************************************
139
140 Ensure you are on release 0900.
141
142 Rename pdpstatistics table in policyadmin schema:
143
144 .. code::
145
146     RENAME TABLE pdpstatistics TO backup_pdpstatistics;
147
148 Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"
149
150 Make/Redeploy to run downgrade
151
152 This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)
153
154 Rename backup_pdpstatistic table in policyadmin schema:
155
156 .. code::
157
158     RENAME TABLE backup_pdpstatistics TO pdpstatistics;
159
160 Modify db_migrator_policy_init.sh - Remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"
161
162 Make/Redeploy to run upgrade
163
164 .. list-table::
165    :widths: 60 20
166    :header-rows: 0
167
168    * - Number of files run
169      - 11
170    * - Tables in policyadmin
171      - 75
172    * - Records Added
173      - 11
174    * - schema_version
175      - 0900
176
177 6. Downgrade to Honolulu (0800) after failed downgrade
178 ******************************************************
179
180 Ensure you are on release 0900.
181
182 Add timeStamp column to papdpstatistics_enginestats:
183
184 .. code::
185
186     ALTER TABLE jpapdpstatistics_enginestats ADD COLUMN timeStamp datetime DEFAULT NULL NULL AFTER UPTIME;
187
188 Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"
189
190 Make/Redeploy to run downgrade
191
192 This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)
193
194 Remove timeStamp column from jpapdpstatistics_enginestats:
195
196 .. code::
197
198     ALTER TABLE jpapdpstatistics_enginestats DROP COLUMN timeStamp;
199
200 The config job will retry 5 times. If you make your fix before this limit is reached you won't need to redeploy.
201
202 Redeploy to run downgrade
203
204 .. list-table::
205    :widths: 60 20
206    :header-rows: 0
207
208    * - Number of files run
209      - 14
210    * - Tables in policyadmin
211      - 73
212    * - Records Added
213      - 14
214    * - schema_version
215      - 0800
216
217 7. Downgrade to Honolulu (0800) after failed upgrade
218 ****************************************************
219
220 Ensure you are on release 0800.
221
222 Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"
223
224 Update pdpstatistics:
225
226 .. code::
227
228     ALTER TABLE pdpstatistics ADD COLUMN POLICYUNDEPLOYCOUNT BIGINT DEFAULT NULL NULL AFTER POLICYEXECUTEDSUCCESSCOUNT;
229
230 Make/Redeploy to run upgrade
231
232 This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)
233
234 Once the retry count has been reached, update pdpstatistics:
235
236 .. code::
237
238     ALTER TABLE pdpstatistics DROP COLUMN POLICYUNDEPLOYCOUNT;
239
240 Modify db_migrator_policy_init.sh - Remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"
241
242 Make/Redeploy to run downgrade
243
244 .. list-table::
245    :widths: 60 20
246    :header-rows: 0
247
248    * - Number of files run
249      - 7
250    * - Tables in policyadmin
251      - 73
252    * - Records Added
253      - 7
254    * - schema_version
255      - 0800
256
257 8. Upgrade to Istanbul (0900) after failed upgrade
258 **************************************************
259
260 Ensure you are on release 0800.
261
262 Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"
263
264 Update PDP table:
265
266 .. code::
267
268     ALTER TABLE pdp ADD COLUMN LASTUPDATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER HEALTHY;
269
270 Make/Redeploy to run upgrade
271
272 This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)
273
274 Update PDP table:
275
276 .. code::
277
278     ALTER TABLE pdp DROP COLUMN LASTUPDATE;
279
280 The config job will retry 5 times. If you make your fix before this limit is reached you won't need to redeploy.
281
282 Redeploy to run upgrade
283
284 .. list-table::
285    :widths: 60 20
286    :header-rows: 0
287
288    * - Number of files run
289      - 14
290    * - Tables in policyadmin
291      - 75
292    * - Records Added
293      - 14
294    * - schema_version
295      - 0900
296
297 9. Downgrade to Honolulu (0800) with data in pdpstatistics and jpapdpstatistics_enginestats
298 *******************************************************************************************
299
300 Ensure you are on release 0900.
301
302 Check pdpstatistics and jpapdpstatistics_enginestats are populated with data.
303
304 .. code::
305   :number-lines:
306
307     SELECT count(*) FROM pdpstatistics;
308     SELECT count(*) FROM jpapdpstatistics_enginestats;
309
310 Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"
311
312 Make/Redeploy to run downgrade
313
314 Check the tables to ensure the number  records is the same.
315
316 .. code::
317   :number-lines:
318
319     SELECT count(*) FROM pdpstatistics;
320     SELECT count(*) FROM jpapdpstatistics_enginestats;
321
322 Check pdpstatistics to ensure the primary key has changed:
323
324 .. code::
325
326     SELECT column_name, constraint_name FROM information_schema.key_column_usage WHERE table_name='pdpstatistics';
327
328 Check jpapdpstatistics_enginestats to ensure id column has been dropped and timestamp column added.
329
330 .. code::
331
332     SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'jpapdpstatistics_enginestats';
333
334 Check the pdp table to ensure the LASTUPDATE column has been dropped.
335
336 .. code::
337
338     SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'pdp';
339
340
341 .. list-table::
342    :widths: 60 20
343    :header-rows: 0
344
345    * - Number of files run
346      - 13
347    * - Tables in policyadmin
348      - 73
349    * - Records Added
350      - 13
351    * - schema_version
352      - 0800
353
354 10. Upgrade to Istanbul (0900) with data in pdpstatistics and jpapdpstatistics_enginestats
355 ******************************************************************************************
356
357 Ensure you are on release 0800.
358
359 Check pdpstatistics and jpapdpstatistics_enginestats are populated with data.
360
361 .. code::
362   :number-lines:
363
364     SELECT count(*) FROM pdpstatistics;
365     SELECT count(*) FROM jpapdpstatistics_enginestats;
366
367 Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"
368
369 Make/Redeploy to run upgrade
370
371 Check the tables to ensure the number  records is the same.
372
373 .. code::
374   :number-lines:
375
376     SELECT count(*) FROM pdpstatistics;
377     SELECT count(*) FROM jpapdpstatistics_enginestats;
378
379 Check pdpstatistics to ensure the primary key has changed:
380
381 .. code::
382
383     SELECT column_name, constraint_name FROM information_schema.key_column_usage WHERE table_name='pdpstatistics';
384
385 Check jpapdpstatistics_enginestats to ensure timestamp column has been dropped and id column added.
386
387 .. code::
388
389     SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'jpapdpstatistics_enginestats';
390
391 Check the pdp table to ensure the LASTUPDATE column has been added and the value has defaulted to the CURRENT_TIMESTAMP.
392
393 .. code::
394
395     SELECT table_name, column_name, data_type, column_default FROM information_schema.columns WHERE table_name = 'pdp';
396
397 .. list-table::
398    :widths: 60 20
399    :header-rows: 0
400
401    * - Number of files run
402      - 13
403    * - Tables in policyadmin
404      - 75
405    * - Records Added
406      - 13
407    * - schema_version
408      - 0900
409
410 .. note::
411    The number of records added may vary depnding on the number of retries.
412
413 End of Document