CREATE TABLE IF NOT EXISTS `categories` (
  `id` varchar(36) NOT NULL,
  `api_account_id` varchar(36) NOT NULL,
  `remote_category_id` varchar(120) NOT NULL,
  `name` varchar(160) NOT NULL,
  `sort_order` int NOT NULL DEFAULT 0,
  `raw_payload` json NULL,
  `last_synced_at` datetime NOT NULL,
  `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`id`),
  UNIQUE KEY `IDX_categories_account_remote` (`api_account_id`, `remote_category_id`),
  KEY `IDX_categories_account` (`api_account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `courses` (
  `id` varchar(36) NOT NULL,
  `api_account_id` varchar(36) NOT NULL,
  `category_id` varchar(36) NULL,
  `remote_category_id` varchar(120) NOT NULL DEFAULT '',
  `remote_course_id` varchar(160) NOT NULL,
  `name` varchar(255) NOT NULL,
  `is_favorite` tinyint NOT NULL DEFAULT 0,
  `enabled` tinyint NOT NULL DEFAULT 1,
  `raw_payload` json NULL,
  `last_synced_at` datetime NOT NULL,
  `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
  `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`id`),
  UNIQUE KEY `IDX_courses_account_remote_category` (`api_account_id`, `remote_course_id`, `remote_category_id`),
  KEY `IDX_courses_account` (`api_account_id`),
  KEY `IDX_courses_category` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
