LP#1426133: Set merge_profile_id_seq explicitly
authorRemington Steed <rjs7@calvin.edu>
Thu, 26 Feb 2015 21:21:48 +0000 (16:21 -0500)
committerBen Shum <bshum@biblio.org>
Fri, 27 Feb 2015 15:23:09 +0000 (10:23 -0500)
Many database tables need to explicitly set the id sequence (often to
100) to provide room for stock data with static ids. This commit does so
for vandelay.merge_profile, and also updates the ids of any non-stock
profiles (both in the merge_profile table and in related settings).

Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.redo_vandelay_merge_profile_sequence.sql [new file with mode: 0644]

index 5abcaaf..fa7fcc3 100644 (file)
@@ -12646,6 +12646,8 @@ INSERT INTO vandelay.merge_profile (id, owner, name, replace_spec)
 INSERT INTO vandelay.merge_profile (id, owner, name, preserve_spec) 
     VALUES (2, 1, oils_i18n_gettext(2, 'Full Overlay', 'vmp', 'name'), '901c');
 
+SELECT SETVAL('vandelay.merge_profile'::TEXT, 100);
+
 -- user activity seed data --
 
 INSERT INTO config.usr_activity_type (id, ewho, ewhat, ehow, egroup, label) VALUES
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.redo_vandelay_merge_profile_sequence.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.redo_vandelay_merge_profile_sequence.sql
new file mode 100644 (file)
index 0000000..bf0f5c9
--- /dev/null
@@ -0,0 +1,24 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+--stock evergreen comes with 2 merge profiles; move any custom profiles
+UPDATE vandelay.merge_profile SET id = id + 100 WHERE id > 2;
+
+--update the same ids in org unit settings, stored in double quotes
+UPDATE actor.org_unit_setting
+    SET value = '"' || merge_profile_id+100 || '"'
+       FROM (
+               SELECT id, (regexp_matches(value, '"(\d+)"'))[1]::int as merge_profile_id FROM actor.org_unit_setting
+               WHERE name IN (
+                       'acq.upload.default.vandelay.low_quality_fall_thru_profile',
+                       'acq.upload.default.vandelay.merge_profile'
+               )
+       ) as foo
+       WHERE actor.org_unit_setting.id = foo.id
+       AND foo.merge_profile_id > 2;
+
+--set sequence's next value to 100, or more if necessary
+SELECT SETVAL('vandelay.merge_profile_id_seq', GREATEST(100, (SELECT MAX(id) FROM vandelay.merge_profile)));
+
+COMMIT;