-- staff notes about a client, several per client (like WHMCS); sticky notes show on every admin page of the client and above its tickets
CREATE TABLE client_notes (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  client_id INT UNSIGNED NOT NULL,
  admin_id INT UNSIGNED NULL,
  note TEXT NOT NULL,
  sticky TINYINT(1) NOT NULL DEFAULT 0,
  created_at DATETIME NOT NULL,
  updated_at DATETIME NOT NULL,
  KEY client (client_id, sticky)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- the old single notes field becomes the first note; sticky, because it was shown above tickets until now
INSERT INTO client_notes (client_id, note, sticky, created_at, updated_at) SELECT id, TRIM(notes), 1, NOW(), NOW() FROM clients WHERE TRIM(notes) <> '';
UPDATE clients SET notes = '' WHERE notes <> '';
