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