bf0f5c99f6c78eb0799ba9f9ad1578ff21c9a7b1
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.schema.redo_vandelay_merge_profile_sequence.sql
1 BEGIN;
2
3 --SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
4
5 --stock evergreen comes with 2 merge profiles; move any custom profiles
6 UPDATE vandelay.merge_profile SET id = id + 100 WHERE id > 2;
7
8 --update the same ids in org unit settings, stored in double quotes
9 UPDATE actor.org_unit_setting
10     SET value = '"' || merge_profile_id+100 || '"'
11         FROM (
12                 SELECT id, (regexp_matches(value, '"(\d+)"'))[1]::int as merge_profile_id FROM actor.org_unit_setting
13                 WHERE name IN (
14                         'acq.upload.default.vandelay.low_quality_fall_thru_profile',
15                         'acq.upload.default.vandelay.merge_profile'
16                 )
17         ) as foo
18         WHERE actor.org_unit_setting.id = foo.id
19         AND foo.merge_profile_id > 2;
20
21 --set sequence's next value to 100, or more if necessary
22 SELECT SETVAL('vandelay.merge_profile_id_seq', GREATEST(100, (SELECT MAX(id) FROM vandelay.merge_profile)));
23
24 COMMIT;