<?php

/**
 * Generated: 2014-03-24 15:01:35
 * @author Rtn_Module_Tool
 */
class Bip_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 `category`;
CREATE TABLE `category` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` int(10) unsigned DEFAULT NULL,
  `active` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `level` tinyint(3) unsigned DEFAULT NULL,
  `order` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `category_id` (`category_id`),
  KEY `index_foreignkey_category_category` (`category_id`),
  CONSTRAINT `cons_fk_category_category_id_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			
			
			DROP TABLE IF EXISTS `biparticle`;
CREATE TABLE `biparticle` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(256) COLLATE utf8_unicode_ci DEFAULT NULL,
  `body` longtext COLLATE utf8_unicode_ci,
  `author` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `category_id` int(10) unsigned DEFAULT '0',
  `data` datetime DEFAULT NULL,
  `current` tinyint(3) unsigned DEFAULT '1',
  `active` tinyint(3) unsigned DEFAULT '0',
  `hidden` tinyint(3) unsigned DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			
			
			CREATE OR REPLACE VIEW viewbipintems AS
			SELECT
				biparticle.*,
				category.name AS groupname
			FROM
				biparticle
			JOIN
				category ON (category.id = biparticle.category_id);

DROP TABLE IF EXISTS `bipsearched`;
CREATE TABLE `bipsearched` (
  `id` int(30) NOT NULL AUTO_INCREMENT,
  `keyword` varchar(125) COLLATE utf8_unicode_ci DEFAULT '0',
  `data` datetime NOT NULL,
  `ip` varchar(200) COLLATE utf8_unicode_ci DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
					
EOF;

		R::exec($q);

		empty(static::$sql_after) || R::exec(static::$sql_after);
	}

}
