seed value for canadian currencies are incorrect user/rogan/lp1807998cad_not_can
authorRogan Hamby <rogan.hamby@gmail.com>
Tue, 11 Dec 2018 20:24:42 +0000 (15:24 -0500)
committerRogan Hamby <rogan.hamby@gmail.com>
Tue, 11 Dec 2018 20:24:42 +0000 (15:24 -0500)
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/xxxx.cad_not_can.sql [new file with mode: 0644]

index 717f620..c91a320 100644 (file)
@@ -30,8 +30,8 @@ CREATE TABLE acq.currency_type (
 
 CREATE TABLE acq.exchange_rate (
     id              SERIAL  PRIMARY KEY,
-    from_currency   TEXT    NOT NULL REFERENCES acq.currency_type (code) DEFERRABLE INITIALLY DEFERRED,
-    to_currency     TEXT    NOT NULL REFERENCES acq.currency_type (code) DEFERRABLE INITIALLY DEFERRED,
+    from_currency   TEXT    NOT NULL REFERENCES acq.currency_type (code) ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
+    to_currency     TEXT    NOT NULL REFERENCES acq.currency_type (code) ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED,
     ratio           NUMERIC NOT NULL,
     CONSTRAINT exchange_rate_from_to_once UNIQUE (from_currency,to_currency)
 );
index e83dc04..b8f317a 100644 (file)
@@ -11914,10 +11914,10 @@ INSERT INTO action_trigger.environment (
 
 -- Use the ISO 4217 abbreviations for currency codes
 INSERT INTO acq.currency_type (code, label) VALUES ('USD', oils_i18n_gettext('USD', 'US Dollars', 'acqct', 'label'));
-INSERT INTO acq.currency_type (code, label) VALUES ('CAN', oils_i18n_gettext('CAN', 'Canadian Dollars', 'acqct', 'label'));
+INSERT INTO acq.currency_type (code, label) VALUES ('CAD', oils_i18n_gettext('CAD', 'Canadian Dollars', 'acqct', 'label'));
 INSERT INTO acq.currency_type (code, label) VALUES ('EUR', oils_i18n_gettext('EUR', 'Euros', 'acqct', 'label'));
 
-INSERT INTO acq.exchange_rate (from_currency,to_currency,ratio) VALUES ('USD','CAN',1.2);
+INSERT INTO acq.exchange_rate (from_currency,to_currency,ratio) VALUES ('USD','CAD',1.2);
 INSERT INTO acq.exchange_rate (from_currency,to_currency,ratio) VALUES ('USD','EUR',0.5);
 
 INSERT INTO acq.invoice_item_type (code,name) VALUES ('TAX',oils_i18n_gettext('TAX', 'Tax', 'aiit', 'name'));
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.cad_not_can.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.cad_not_can.sql
new file mode 100644 (file)
index 0000000..6965e32
--- /dev/null
@@ -0,0 +1,18 @@
+BEGIN;
+
+UPDATE acq.currency_type SET code = 'CAD' WHERE code = 'CAN';
+UPDATE acq.exchange_rate SET from_currency = 'CAD' WHERE code = 'CAN';
+UPDATE acq.exchange_rate SET to_currency = 'CAD' WHERE code = 'CAN';
+
+COMMIT;
+
+BEGIN;
+
+ALTER TABLE acq.exchange_rate 
+       DROP CONSTRAINT exchange_rate_from_currency_fkey
+       ,ADD CONSTRAINT exchange_rate_from_currency_fkey FOREIGN KEY (from_currency) REFERENCES acq.currency_type (code) ON UPDATE CASCADE;
+ALTER TABLE acq.exchange_rate 
+       DROP CONSTRAINT exchange_rate_to_currency_fkey
+       ,ADD CONSTRAINT exchange_rate_to_currency_fkey FOREIGN KEY (to_currency) REFERENCES acq.currency_type (code) ON UPDATE CASCADE;
+
+COMMIT;