LP#1666512 - Only insert if not already existing
authorBen Shum <ben@evergreener.net>
Fri, 15 Sep 2017 03:16:32 +0000 (23:16 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 4 Oct 2017 16:04:03 +0000 (12:04 -0400)
This repatch was requested by Galen Charlton to make it easier for
upgrades to avoid adding the entries or failing if the entries already
existed.

Also drops the unnecessary i18n tagging for the billing type names
since it does not work with applying upgrade scripts (only for sourcing
db.seed data for translation to PO file)

Signed-off-by: Ben Shum <ben@evergreener.net>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/src/sql/Pg/upgrade/XXXX.data.add_possibly_missing_billing_types.sql

index a9d3d5c..256c558 100644 (file)
@@ -7,11 +7,16 @@ SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 -- add them here.  It's okay if they fail, so this should probably be 
 -- run outside a transaction if added to the version-upgrade scripts.
 
-INSERT INTO config.billing_type (id, name, owner) VALUES
-    ( 7, oils_i18n_gettext(7, 'Damaged Item', 'cbt', 'name'), 1);
-INSERT INTO config.billing_type (id, name, owner) VALUES
-    ( 8, oils_i18n_gettext(8, 'Damaged Item Processing Fee', 'cbt', 'name'), 1);
-INSERT INTO config.billing_type (id, name, owner) VALUES
-    ( 9, oils_i18n_gettext(9, 'Notification Fee', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner)
+    SELECT 7, 'Damaged Item', 1
+    WHERE NOT EXISTS (SELECT 1 FROM config.billing_type WHERE name = 'Damaged Item');
+
+INSERT INTO config.billing_type (id, name, owner)
+    SELECT 8, 'Damaged Item Processing Fee', 1
+    WHERE NOT EXISTS (SELECT 1 FROM config.billing_type WHERE name = 'Damaged Item Processing Fee');
+
+INSERT INTO config.billing_type (id, name, owner)
+    SELECT 9, 'Notification Fee', 1
+    WHERE NOT EXISTS (SELECT 1 FROM config.billing_type WHERE name = 'Notification Fee');
 
 COMMIT;