-- Migration 111: Product audit log
-- Track product changes (rename/delete)

CREATE TABLE IF NOT EXISTS product_audit_log (
    id SERIAL PRIMARY KEY,
    product_id INTEGER NOT NULL REFERENCES products(id) ON DELETE CASCADE,
    event_type VARCHAR(50) NOT NULL,
    user_id INTEGER,
    changes JSONB,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_product_audit_log_product
    ON product_audit_log(product_id);

CREATE INDEX IF NOT EXISTS idx_product_audit_log_created_at
    ON product_audit_log(created_at);
