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)
);
-- 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'));
--- /dev/null
+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;