|
17 | 17 |
|
18 | 18 |
|
19 | 19 | def upgrade(): |
20 | | - # Skip widgets whose position values are missing or not numeric, e.g. rows |
21 | | - # written through the API with options = '{}'. Without the filter the cast |
22 | | - # yields NULL, jsonb_set() returns NULL for a NULL new_value, and the update |
23 | | - # fails the NOT NULL constraint on widgets.options. |
| 20 | + # Skip widgets that have no position values, e.g. rows written through the |
| 21 | + # API with options = '{}'. Without the filter the cast yields NULL, |
| 22 | + # jsonb_set() returns NULL for a NULL new_value, and the update fails the |
| 23 | + # NOT NULL constraint on widgets.options. |
24 | 24 | op.execute(""" |
25 | 25 | UPDATE widgets |
26 | 26 | SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int * 2)::jsonb) |
27 | | - WHERE options->'position'->>'col' ~ '^-?[0-9]+$'; |
| 27 | + WHERE options->'position'->>'col' IS NOT NULL; |
28 | 28 | UPDATE widgets |
29 | 29 | SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int * 2)::jsonb) |
30 | | - WHERE options->'position'->>'sizeX' ~ '^-?[0-9]+$'; |
| 30 | + WHERE options->'position'->>'sizeX' IS NOT NULL; |
31 | 31 | """) |
32 | 32 |
|
33 | 33 |
|
34 | 34 | def downgrade(): |
35 | 35 | op.execute(""" |
36 | 36 | UPDATE widgets |
37 | 37 | SET options = jsonb_set(options, '{position,col}', to_json((options->'position'->>'col')::int / 2)::jsonb) |
38 | | - WHERE options->'position'->>'col' ~ '^-?[0-9]+$'; |
| 38 | + WHERE options->'position'->>'col' IS NOT NULL; |
39 | 39 | UPDATE widgets |
40 | 40 | SET options = jsonb_set(options, '{position,sizeX}', to_json((options->'position'->>'sizeX')::int / 2)::jsonb) |
41 | | - WHERE options->'position'->>'sizeX' ~ '^-?[0-9]+$'; |
| 41 | + WHERE options->'position'->>'sizeX' IS NOT NULL; |
42 | 42 | """) |
0 commit comments