-- Migration 109: Product price history
-- Track changes to product pricing

CREATE TABLE IF NOT EXISTS product_price_history (
    id SERIAL PRIMARY KEY,
    product_id INTEGER NOT NULL REFERENCES products(id) ON DELETE CASCADE,
    price_type VARCHAR(50) NOT NULL DEFAULT 'sales_price',
    old_price DECIMAL(10,2),
    new_price DECIMAL(10,2),
    note TEXT,
    changed_by VARCHAR(255),
    changed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_product_price_history_product
    ON product_price_history(product_id);

CREATE INDEX IF NOT EXISTS idx_product_price_history_changed_at
    ON product_price_history(changed_at);
