-- MySQL 5.7 compatible: run only lines for columns/tables that do not already exist.
ALTER TABLE campaign ADD COLUMN is_sent TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE campaign ADD COLUMN sent_at DATETIME NULL;
ALTER TABLE campaign ADD COLUMN sent_by INT NULL;
ALTER TABLE campaign ADD COLUMN customer_count INT NOT NULL DEFAULT 0;
ALTER TABLE audience ADD COLUMN customer_count INT NOT NULL DEFAULT 0;
ALTER TABLE communications ADD COLUMN campaign_id INT NULL;
ALTER TABLE communications ADD COLUMN source_type VARCHAR(30) NOT NULL DEFAULT 'direct';
CREATE TABLE quotation_items (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  quotation_id INT NOT NULL,
  item_id INT NOT NULL,
  quantity INT NOT NULL DEFAULT 1,
  unit_price DECIMAL(12,2) NOT NULL DEFAULT 0,
  line_total DECIMAL(12,2) NOT NULL DEFAULT 0,
  date_created DATETIME DEFAULT CURRENT_TIMESTAMP,
  KEY idx_quotation_items_q (quotation_id),
  KEY idx_quotation_items_item (item_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
