CREATE TABLE `rq_puzzle` (
  `puzzle_id` int(11) NOT NULL,
  `puzzle_name` text CHARACTER SET utf8,
  `created_by` int(11) DEFAULT NULL,
  `created_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1 for active and 0 for deactive'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `rq_puzzle`
  ADD PRIMARY KEY (`puzzle_id`);

ALTER TABLE `rq_puzzle`
  MODIFY `puzzle_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;





CREATE TABLE `rq_puzzle_files` (
  `file_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `area_id` int(11) NOT NULL,
  `area` varchar(50) CHARACTER SET utf8 NOT NULL,
  `file_type` varchar(50) CHARACTER SET utf8 NOT NULL,
  `file_name` varchar(80) CHARACTER SET utf8 NOT NULL,
  `created_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `status` tinyint(1) NOT NULL DEFAULT '2' COMMENT '0: banned, 1: published, 2: pending'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `rq_puzzle_files`
  ADD PRIMARY KEY (`file_id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `area_id` (`area_id`),
  ADD KEY `area` (`area`),
  ADD KEY `file_type` (`file_type`),
  ADD KEY `file_name` (`file_name`),
  ADD KEY `created_time` (`created_time`);

ALTER TABLE `rq_puzzle_files`
  MODIFY `file_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;






CREATE TABLE `rq_puzzle_files_lang` (
  `file_id` int(11) NOT NULL,
  `lang` varchar(10) CHARACTER SET utf8 NOT NULL,
  `title` varchar(255) CHARACTER SET utf8 NOT NULL,
  `caption` text CHARACTER SET utf8 NOT NULL,
  `link` text CHARACTER SET utf8 NOT NULL,
  `link_target` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0: _self, 1: _blank'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;






CREATE TABLE `rq_puzzle_files_priority` (
  `file_id` int(11) NOT NULL,
  `priority` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `rq_puzzle_files_priority`
  ADD KEY `file_id` (`file_id`),
  ADD KEY `priority` (`priority`);






CREATE TABLE `rq_puzzle_users` (
  `id` int(11) NOT NULL,
  `puzzle_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `rq_puzzle_users`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `rq_puzzle_users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
