-- Apply before deploying the course terms gate. Safe to run more than once.
CREATE TABLE IF NOT EXISTS `course_terms_acceptance_tb` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `course_id` int(11) NOT NULL COMMENT 'news_tb.id of the shared slide course',
  `terms_version` varchar(80) NOT NULL,
  `terms_detail` longtext NOT NULL COMMENT 'Snapshot of section_tb.id=26 at acceptance',
  `accepted` tinyint(1) NOT NULL DEFAULT 0,
  `accepted_at` datetime NOT NULL COMMENT 'Asia/Ho_Chi_Minh',
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_course` (`user_id`, `course_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
