-- Migration: Link currency to all monetary tables
-- Adds intCurrencyId FK column to every table that stores monetary values
-- Default value is 1 (LKR - Sri Lankan Rupee) as defined in seed data

ALTER TABLE products
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE sales_orders
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE sales_items
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE purchase_orders
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE purchase_items
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE customer_returns
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE return_items
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE payments
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE cheques
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);

ALTER TABLE customers
    ADD COLUMN intCurrencyId INT DEFAULT 1,
    ADD FOREIGN KEY (intCurrencyId) REFERENCES currencies(intId);
