<?php
/**
 * Generated: 2014-03-14 12:00:47
 * @author Rtn_Module_Tool
 */

class Main_Faq_Module_Initer_DB {

	static $sql_before = "
		SET foreign_key_checks = 0;
	";
	static $sql_after = "
		SET foreign_key_checks = 1;
	";

	static function init() {
		empty(static::$sql_before) || R::exec(static::$sql_before);
		
		$q = <<<EOF
			DROP TABLE IF EXISTS `faqgroup`;
			CREATE TABLE `faqgroup` (
			  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
			  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
			  `active` tinyint(1) unsigned DEFAULT NULL,
			  PRIMARY KEY (`id`)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


			DROP TABLE IF EXISTS `faqqa`;
			CREATE TABLE `faqqa` (
			  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
			  `faqgroup_id` tinyint(3) unsigned DEFAULT NULL,
			  `question` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
			  `answer` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
			  `active` tinyint(1) unsigned DEFAULT NULL,
			  PRIMARY KEY (`id`)
			) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
			
			CREATE OR REPLACE VIEW viewfaqqa AS
			SELECT
				faqqa.*,
				faqgroup.name AS groupname
			FROM
				faqqa
			JOIN
				faqgroup ON (faqgroup.id = faqqa.faqgroup_id)			
EOF;
		
		R::exec($q);
		
		empty(static::$sql_after) || R::exec(static::$sql_after);
	}

}