-- Follow-up: global labels support
CREATE TABLE IF NOT EXISTS labels (
  id INT AUTO_INCREMENT PRIMARY KEY,
  account_id INT NOT NULL,
  name VARCHAR(100) NOT NULL,
  color VARCHAR(20) DEFAULT '#1a3a6f',
  date_created DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_label_account_name (account_id, name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS entity_labels (
  id INT AUTO_INCREMENT PRIMARY KEY,
  account_id INT NOT NULL,
  entity_type VARCHAR(50) NOT NULL,
  entity_id INT NOT NULL,
  label_id INT NOT NULL,
  date_created DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_entity_label (account_id, entity_type, entity_id, label_id),
  KEY idx_entity (account_id, entity_type, entity_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
