-- Initial setup file for Gochan
-- Deleted after setup is finished

CREATE DATABASE IF NOT EXISTS `DBNAME`;
USE `DBNAME`;

CREATE TABLE `DBPREFIXannouncements` (
	`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`subject` VARCHAR(45) NOT NULL,
	`message` TEXT NOT NULL,
	`poster` VARCHAR(45) NOT NULL,
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXbanlist` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`expired` TINYINT(1) DEFAULT '0',
	`allow_read` TINYINT(1) DEFAULT '1',
	`ip` CHAR(15) NOT NULL,
	`silent_ban` TINYINT(1) DEFAULT '0',
	`boards` VARCHAR(255) NOT NULL,
	`banned_by` VARCHAR(50) NOT NULL,
	`timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
	`expires` TIMESTAMP NOT NULL,
	`reason` VARCHAR(255) NOT NULL,
	`staff_note` VARCHAR(255) NOT NULL,
	`appeal` VARCHAR(255) NOT NULL,
	`appeal_at` TIMESTAMP NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXbannedhashes` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`checksum` VARCHAR(45) NOT NULL,
	`description` VARCHAR(45) NOT NULL,
	PRIMARY KEY(`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXbannedtripcodes` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(255) NOT NULL,
	`tripcode` CHAR(10) NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXboards` (
	`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`order` TINYINT UNSIGNED NOT NULL DEFAULT 0,
	`dir` VARCHAR(45) NOT NULL,
	`type` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`first_post` INT UNSIGNED NOT NULL DEFAULT 1,
	`upload_type` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`title` VARCHAR(45) NOT NULL,
	`subtitle` VARCHAR(64) NOT NULL DEFAULT '',
	`description` VARCHAR(64) NOT NULL DEFAULT '',
	`section` VARCHAR(45) NOT NULL,
	`max_image_size` INT UNSIGNED NOT NULL DEFAULT 4718592,
	`max_pages` TINYINT UNSIGNED NOT NULL DEFAULT 11,
	`locale` VARCHAR(10) NOT NULL DEFAULT 'en-us',
	`default_style` VARCHAR(45) NOT NULL,
	`locked` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`created_on` TIMESTAMP NOT NULL,
	`anonymous` VARCHAR(15) NOT NULL DEFAULT 'Anonymous',
	`forced_anon` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`max_age` INT(20) UNSIGNED NOT NULL DEFAULT 0,
--	`mark_page` TINYINT UNSIGNED NOT NULL DEFAULT 9,
	`autosage_after` INT(5) UNSIGNED NOT NULL DEFAULT 200,
	`no_images_after` INT(5) UNSIGNED NOT NULL,
	`max_message_length` INT(10) UNSIGNED NOT NULL DEFAULT 8192,
	`embeds_allowed` TINYINT(1) NOT NULL,
	`redirect_to_thread` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`show_id` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`require_file` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
	`enable_catalog` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;

CREATE TABLE `DBPREFIXembeds` (
	`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`filetype` CHAR(3) NOT NULL,
	`name` VARCHAR(45) NOT NULL,
	`video_url` VARCHAR(255) NOT NULL,
	`width` SMALLINT UNSIGNED NOT NULL,
	`height` SMALLINT UNSIGNED NOT NULL,
	`embed_code` TEXT NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXfiletypes` (
	`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`filetype` VARCHAR(10) NOT NULL,
	`mime` VARCHAR(45) NOT NULL,
	`thumb_image` VARCHAR(255) NOT NULL,
	`image_w` INT UNSIGNED NOT NULL DEFAULT 0,
	`image_h` INT UNSIGNED NOT NULL DEFAULT 0,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXfrontpage` (
	`id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
	`page` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
	`order` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
	`subject` VARCHAR(140) NOT NULL,
	`message` TEXT NOT NULL,
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`poster` VARCHAR(45) NOT NULL,
	`email` VARCHAR(45) NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXlinks` (
	`id` TINYINT NOT NULL AUTO_INCREMENT,
	`title` VARCHAR(45) NOT NULL,
	`url` VARCHAR(255) NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXloginattempts` (
	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
	`ip` CHAR(10) NOT NULL,
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXpollresults` (
	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
	`ip` CHAR(10) NOT NULL,
	`selection` VARCHAR(62) NOT NULL,
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXposts` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`boardid` TINYINT(3) UNSIGNED NOT NULL,
	`parentid` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`name` VARCHAR(45) NOT NULL,
	`tripcode` CHAR(10) NOT NULL,
	`email` VARCHAR(45) NOT NULL,
	`subject` VARCHAR(64) NOT NULL,
	`message` TEXT NOT NULL,
	`password` VARCHAR(45) NOT NULL,
	`filename` VARCHAR(45) NOT NULL DEFAULT '',
	`filename_original` VARCHAR(45) NOT NULL DEFAULT '',
	`file_checksum` VARCHAR(45) NOT NULL DEFAULT '',
	`filesize` INT(20) UNSIGNED NOT NULL DEFAULT 0,
	`image_w` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
	`image_h` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
	`thumb_w` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
	`thumb_h` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 0,
	`ip` CHAR(10) NOT NULL DEFAULT '',
	`tag` VARCHAR(5) NOT NULL DEFAULT '',
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`autosage` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`poster_authority` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`deleted_timestamp` TIMESTAMP DEFAULT "0000-00-00 00:00:00",
	`bumped` TIMESTAMP NOT NULL,
	`stickied` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`locked` TINYINT(1) NOT NULL DEFAULT 0,
	`reviewed` TINYINT(1) NOT NULL DEFAULT 0,
	`sillytag` TINYINT(1) NOT NULL DEFAULT 0,
	PRIMARY KEY (`id`),
	KEY `parentid` (`parentid`),
	KEY `bumped` (`bumped`),
	KEY `file_checksum` (`file_checksum`),
	KEY `stickied` (`stickied`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

CREATE TABLE `DBPREFIXreports` (
	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
	`board` VARCHAR(45) NOT NULL,
	`postid` INT(10) UNSIGNED NOT NULL,
	`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`ip` CHAR(15) NOT NULL,
	`reason` VARCHAR(255) NOT NULL,
	`cleared` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	`istemp` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXsections` (
	`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`order` TINYINT UNSIGNED NOT NULL DEFAULT 0,
	`hidden` TINYINT(1) UNSIGNED NOT NULL,
	`name` VARCHAR(45) NOT NULL,
	`abbreviation` VARCHAR(10) NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXsessions` (
	`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
	`key` CHAR(10) NOT NULL,
	`data` VARCHAR(45) NOT NULL,
	`expires` TIMESTAMP NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=MEMORY DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXstaff` (
	`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`username` VARCHAR(45) NOT NULL,
	`password_checksum` VARCHAR(120) NOT NULL,
	`salt` CHAR(3) NOT NULL,
	`rank` TINYINT(1) UNSIGNED NOT NULL,
	`boards` VARCHAR(128) NOT NULL DEFAULT 'all',
	`added_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`last_active` TIMESTAMP NOT NULL DEFAULT 0,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `DBPREFIXtempposts` SELECT * FROM DBPREFIXposts;

CREATE TABLE `DBPREFIXwordfilters` (
	`id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
	`from` VARCHAR(75) NOT NULL,
	`to` VARCHAR(75) NOT NULL,
	`boards` TEXT NOT NULL,
	`regex` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;