summaryrefslogtreecommitdiffstats
path: root/docs/development/devtools/db-migrator-smoke.rst
blob: 5467377945167b0a33925f2590b51dc4a1b174a8 (plain)
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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
.. This work is licensed under a  Creative Commons Attribution
.. 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0

Policy DB Migrator Smoke Tests
##############################

Prerequisites
*************

Check number of files in each release

.. code::
  :number-lines:

    ls 0800/upgrade/*.sql | wc -l = 96
    ls 0900/upgrade/*.sql | wc -l = 13
    ls 1000/upgrade/*.sql | wc -l = 9
    ls 0800/downgrade/*.sql | wc -l = 96
    ls 0900/downgrade/*.sql | wc -l = 13
    ls 1000/downgrade/*.sql | wc -l = 9

Upgrade scripts
===============

.. code::
  :number-lines:

    /opt/app/policy/bin/prepare_upgrade.sh policyadmin
    /opt/app/policy/bin/db-migrator -s policyadmin -o upgrade # upgrade to Jakarta version (latest)
    /opt/app/policy/bin/db-migrator -s policyadmin -o upgrade -t 0900 # upgrade to Istanbul
    /opt/app/policy/bin/db-migrator -s policyadmin -o upgrade -t 0800 # upgrade to Honolulu

.. note::
   You can also run db-migrator upgrade with the -t and -f options

Downgrade scripts
=================

.. code::
  :number-lines:

    /opt/app/policy/bin/prepare_downgrade.sh policyadmin
    /opt/app/policy/bin/db-migrator -s policyadmin -o downgrade -t 0900 # downgrade to Istanbul
    /opt/app/policy/bin/db-migrator -s policyadmin -o downgrade -t 0800 # downgrade to Honolulu
    /opt/app/policy/bin/db-migrator -s policyadmin -o downgrade -t 0 # delete all tables

Db migrator initialization script
=================================

Update /oom/kubernetes/policy/resources/config/db_migrator_policy_init.sh with the appropriate upgrade/downgrade calls.

The policy version you are deploying should either be an upgrade or downgrade from the current db migrator schema version.

Every time you modify db_migrator_policy_init.sh you will have to undeploy, make and redeploy before updates are applied.

1. Fresh Install
****************

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 118
   * - Tables in policyadmin
     - 70
   * - Records Added
     - 118
   * - schema_version
     - 1000

2. Downgrade to Honolulu (0800)
*******************************

Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts" tagged as Honolulu

Make/Redeploy to run downgrade.

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 13
   * - Tables in policyadmin
     - 73
   * - Records Added
     - 13
   * - schema_version
     - 0800

3. Upgrade to Istanbul (0900)
*****************************

Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts".

Make/Redeploy to run upgrade.

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 13
   * - Tables in policyadmin
     - 75
   * - Records Added
     - 13
   * - schema_version
     - 0900

4. Upgrade to Istanbul (0900) without any information in the migration schema
*****************************************************************************

Ensure you are on release 0800. (This may require running a downgrade before starting the test)

Drop db-migrator tables in migration schema:

.. code::
  :number-lines:

    DROP TABLE schema_versions;
    DROP TABLE policyadmin_schema_changelog;

Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts".

Make/Redeploy to run upgrade.

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 13
   * - Tables in policyadmin
     - 75
   * - Records Added
     - 13
   * - schema_version
     - 0900

5. Upgrade to Istanbul (0900) after failed downgrade
****************************************************

Ensure you are on release 0900.

Rename pdpstatistics table in policyadmin schema:

.. code::

    RENAME TABLE pdpstatistics TO backup_pdpstatistics;

Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"

Make/Redeploy to run downgrade

This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)

Rename backup_pdpstatistic table in policyadmin schema:

.. code::

    RENAME TABLE backup_pdpstatistics TO pdpstatistics;

Modify db_migrator_policy_init.sh - Remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"

Make/Redeploy to run upgrade

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 11
   * - Tables in policyadmin
     - 75
   * - Records Added
     - 11
   * - schema_version
     - 0900

6. Downgrade to Honolulu (0800) after failed downgrade
******************************************************

Ensure you are on release 0900.

Add timeStamp column to papdpstatistics_enginestats:

.. code::

    ALTER TABLE jpapdpstatistics_enginestats ADD COLUMN timeStamp datetime DEFAULT NULL NULL AFTER UPTIME;

Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"

Make/Redeploy to run downgrade

This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)

Remove timeStamp column from jpapdpstatistics_enginestats:

.. code::

    ALTER TABLE jpapdpstatistics_enginestats DROP COLUMN timeStamp;

The config job will retry 5 times. If you make your fix before this limit is reached you won't need to redeploy.

Redeploy to run downgrade

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 14
   * - Tables in policyadmin
     - 73
   * - Records Added
     - 14
   * - schema_version
     - 0800

7. Downgrade to Honolulu (0800) after failed upgrade
****************************************************

Ensure you are on release 0800.

Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"

Update pdpstatistics:

.. code::

    ALTER TABLE pdpstatistics ADD COLUMN POLICYUNDEPLOYCOUNT BIGINT DEFAULT NULL NULL AFTER POLICYEXECUTEDSUCCESSCOUNT;

Make/Redeploy to run upgrade

This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)

Once the retry count has been reached, update pdpstatistics:

.. code::

    ALTER TABLE pdpstatistics DROP COLUMN POLICYUNDEPLOYCOUNT;

Modify db_migrator_policy_init.sh - Remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"

Make/Redeploy to run downgrade

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 7
   * - Tables in policyadmin
     - 73
   * - Records Added
     - 7
   * - schema_version
     - 0800

8. Upgrade to Istanbul (0900) after failed upgrade
**************************************************

Ensure you are on release 0800.

Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"

Update PDP table:

.. code::

    ALTER TABLE pdp ADD COLUMN LASTUPDATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER HEALTHY;

Make/Redeploy to run upgrade

This should result in an error (last row in policyadmin_schema_changelog will have a success value of 0)

Update PDP table:

.. code::

    ALTER TABLE pdp DROP COLUMN LASTUPDATE;

The config job will retry 5 times. If you make your fix before this limit is reached you won't need to redeploy.

Redeploy to run upgrade

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 14
   * - Tables in policyadmin
     - 75
   * - Records Added
     - 14
   * - schema_version
     - 0900

9. Downgrade to Honolulu (0800) with data in pdpstatistics and jpapdpstatistics_enginestats
*******************************************************************************************

Ensure you are on release 0900.

Check pdpstatistics and jpapdpstatistics_enginestats are populated with data.

.. code::
  :number-lines:

    SELECT count(*) FROM pdpstatistics;
    SELECT count(*) FROM jpapdpstatistics_enginestats;

Modify db_migrator_policy_init.sh - remove any lines referencing upgrade and add the 2 lines under "Downgrade scripts"

Make/Redeploy to run downgrade

Check the tables to ensure the number  records is the same.

.. code::
  :number-lines:

    SELECT count(*) FROM pdpstatistics;
    SELECT count(*) FROM jpapdpstatistics_enginestats;

Check pdpstatistics to ensure the primary key has changed:

.. code::

    SELECT column_name, constraint_name FROM information_schema.key_column_usage WHERE table_name='pdpstatistics';

Check jpapdpstatistics_enginestats to ensure id column has been dropped and timestamp column added.

.. code::

    SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'jpapdpstatistics_enginestats';

Check the pdp table to ensure the LASTUPDATE column has been dropped.

.. code::

    SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'pdp';


.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 13
   * - Tables in policyadmin
     - 73
   * - Records Added
     - 13
   * - schema_version
     - 0800

10. Upgrade to Istanbul (0900) with data in pdpstatistics and jpapdpstatistics_enginestats
******************************************************************************************

Ensure you are on release 0800.

Check pdpstatistics and jpapdpstatistics_enginestats are populated with data.

.. code::
  :number-lines:

    SELECT count(*) FROM pdpstatistics;
    SELECT count(*) FROM jpapdpstatistics_enginestats;

Modify db_migrator_policy_init.sh - remove any lines referencing downgrade and add the 2 lines under "Upgrade scripts"

Make/Redeploy to run upgrade

Check the tables to ensure the number  records is the same.

.. code::
  :number-lines:

    SELECT count(*) FROM pdpstatistics;
    SELECT count(*) FROM jpapdpstatistics_enginestats;

Check pdpstatistics to ensure the primary key has changed:

.. code::

    SELECT column_name, constraint_name FROM information_schema.key_column_usage WHERE table_name='pdpstatistics';

Check jpapdpstatistics_enginestats to ensure timestamp column has been dropped and id column added.

.. code::

    SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'jpapdpstatistics_enginestats';

Check the pdp table to ensure the LASTUPDATE column has been added and the value has defaulted to the CURRENT_TIMESTAMP.

.. code::

    SELECT table_name, column_name, data_type, column_default FROM information_schema.columns WHERE table_name = 'pdp';

.. list-table::
   :widths: 60 20
   :header-rows: 0

   * - Number of files run
     - 13
   * - Tables in policyadmin
     - 75
   * - Records Added
     - 13
   * - schema_version
     - 0900

.. note::
   The number of records added may vary depnding on the number of retries.

With addition of Postgres support to db-migrator, these tests can be also performed on a Postgres version of database.
In addition, scripts running the aforementioned scenarios can be found under `smoke-tests` folder on db-migrator code base.

End of Document