-- v4.0.1：合伙人可见用户备注（与 HQ hq_remark 隔离）
-- Review 后再在生产执行。

CREATE TABLE IF NOT EXISTS `partner_user_note` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `partner_account_id` BIGINT UNSIGNED NOT NULL,
  `user_id` BIGINT UNSIGNED NOT NULL,
  `remark` VARCHAR(128) NOT NULL,
  `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_partner_user_note_partner_user` (`partner_account_id`, `user_id`),
  KEY `idx_partner_user_note_user` (`user_id`),
  CONSTRAINT `fk_partner_user_note_partner` FOREIGN KEY (`partner_account_id`) REFERENCES `partner_account`(`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_partner_user_note_user` FOREIGN KEY (`user_id`) REFERENCES `user_user`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='主合伙人对关联用户的备注';
