-- Database upgrades (running all SQL commands below the matching "-- version: x" line)

-- version: 1

CREATE TABLE `support_ranks` (
`rank_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`rank_name` VARCHAR( 256 ) NOT NULL ,
`rank_access` INT( 4 ) NOT NULL ,
`rank_info` VARCHAR( 512 ) NOT NULL ,
`rank_order` SMALLINT( 4 ) NOT NULL
) ENGINE = MYISAM ;

ALTER TABLE `users` ADD `user_rank` INT( 11 ) NOT NULL AFTER `user_access`;

-- version: 2

ALTER TABLE `owner_history` CHANGE `owner_history_uid` `owner_history_to_uid` INT( 11 ) NOT NULL;
ALTER TABLE `owner_history` ADD `owner_history_from_uid` INT( 11 ) NOT NULL AFTER `owner_history_to_uid`;

-- version: 3

ALTER TABLE `channels`
  DROP `channel_scanstate`,
  DROP `channel_scanexcept`,
  DROP `channel_maxrepeat`,
  DROP `channel_repeatreaction`,
  DROP `channel_maxflood`,
  DROP `channel_floodtime`,
  DROP `channel_floodreaction`,
  DROP `channel_maxjoin`,
  DROP `channel_jointime`,
  DROP `channel_joinreaction`;

ALTER TABLE `channels`  
  ADD `channel_scanner` VARCHAR(50) NULL,  
  ADD `channel_spam_limit` SMALLINT(3) NULL,  
  ADD `channel_spam_reaction` TINYINT(1) NULL,  
  ADD `channel_spam_reaction_duration` MEDIUMINT(7) NULL,  
  ADD `channel_spam_except` SMALLINT(3) NULL,  
  ADD `channel_flood_limit` SMALLINT(3) NULL,  
  ADD `channel_flood_time` SMALLINT(3) NULL,  
  ADD `channel_flood_reaction` TINYINT(1) NULL,  
  ADD `channel_flood_reaction_duration` MEDIUMINT(7) NULL,  
  ADD `channel_flood_except` SMALLINT(3) NULL,  
  ADD `channel_join_limit` SMALLINT(3) NULL,  
  ADD `channel_join_time` SMALLINT(3) NULL,  
  ADD `channel_join_reaction` TINYINT(1) NULL,  
  ADD `channel_join_reaction_duration` MEDIUMINT(7) NULL,  
  ADD `channel_join_except` SMALLINT(3) NULL,  
  ADD `channel_botnet_bantime` MEDIUMINT(7) NULL,  
  ADD `channel_botnet_except` SMALLINT(3) NULL,  
  ADD `channel_caps_percent` TINYINT(3) NULL,  
  ADD `channel_caps_reaction` TINYINT(1) NULL,  
  ADD `channel_caps_reaction_duration` MEDIUMINT(7) NULL,  
  ADD `channel_caps_except` SMALLINT(3) NULL,  
  ADD `channel_digit_percent` TINYINT(3) NULL,  
  ADD `channel_digit_reaction` TINYINT(1) NULL,  
  ADD `channel_digit_reaction_duration` MEDIUMINT(7) NULL,  
  ADD `channel_digit_except` SMALLINT(3) NULL;
  
-- version: 4

ALTER TABLE `bots` ADD `queue` TINYINT( 1 ) NOT NULL AFTER `textbot` 

-- version: 5

CREATE TABLE `donotregister` (
`dnr_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`dnr_target` VARCHAR( 256 ) NOT NULL ,
`dnr_user` INT( 11 ) NOT NULL ,
`dnr_timeout` INT( 20 ) NOT NULL ,
`dnr_reason` TEXT NOT NULL ,
UNIQUE (
`dnr_target`
)
) ENGINE = MYISAM ;

-- version: 6

ALTER TABLE `fundata` CHANGE `uid` `user` VARCHAR( 50 ) NOT NULL;
ALTER TABLE `fundata` ADD INDEX ( `cid` );
ALTER TABLE `fundata` ADD INDEX ( `user` );
ALTER TABLE `fundata` ADD INDEX ( `name` );

-- version: 7

ALTER TABLE `bot_binds` ADD `botid` INT( 11 ) NOT NULL AFTER `botclass`;
ALTER TABLE `bot_binds` ADD INDEX ( `botclass` );

-- version: 8

ALTER TABLE `bot_channels` CHANGE `trigger` `trigger` VARCHAR( 50 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT '+';

-- version: 9

ALTER TABLE `bot_binds` CHANGE `flags` `flags` INT( 10 ) NOT NULL ;

-- version: 10

CREATE TABLE IF NOT EXISTS `helpserv_requests` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `host` varchar(200) NOT NULL,
  `hand` varchar(50) NOT NULL,
  `nick` varchar(50) NOT NULL,
  `status` int(1) NOT NULL,
  `supporter` int(11) NOT NULL,
  `time` int(20) NOT NULL,
  `text` text NOT NULL,
  `log` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `helpserv_settings` (
  `helpserv_botid` int(11) NOT NULL,
  `helpserv_support` varchar(256) NOT NULL,
  `helpserv_public` varchar(256) DEFAULT NULL,
  `helpserv_intern` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`helpserv_botid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- version: 11

ALTER TABLE `helpserv_requests` ADD `botid` INT( 11 ) NOT NULL AFTER `id`;

-- version: 12

ALTER TABLE `helpserv_settings` ADD `helpserv_intern_announce` TINYINT( 1 ) NOT NULL;

-- version: 13

ALTER TABLE `channels` ADD `channel_canhalfop` SMALLINT( 3 ) NULL AFTER `channel_canop`;
ALTER TABLE `channels` ADD `channel_gethalfop` SMALLINT( 3 ) NULL AFTER `channel_getop`;
UPDATE `channels` SET `channel_canhalfop` = '150',
`channel_gethalfop` = '150' WHERE `channel_name` = 'defaults';

-- version: 14

ALTER TABLE `users` ADD `user_registered` INT( 20 ) NOT NULL ,
ADD `user_lastcheck` INT( 20 ) NOT NULL;

-- version: 15

CREATE TABLE IF NOT EXISTS `settings` (
  `name` varchar(100) NOT NULL,
  `value` text NOT NULL,
  PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- version: 16

CREATE TABLE IF NOT EXISTS `spamserv_badwords` (
  `badword_id` int(11) NOT NULL AUTO_INCREMENT,
  `badword_cid` int(11) NOT NULL,
  `badword_match` varchar(128) NOT NULL,
  `badword_uid` int(11) NOT NULL,
  `badword_use_default` tinyint(1) NOT NULL,
  `badword_exceptlevel` smallint(3) NOT NULL,
  `badword_scan_ops` tinyint(1) NOT NULL,
  `badword_scan_voice` tinyint(1) NOT NULL,
  `badword_use_default_reaction` tinyint(1) NOT NULL,
  `badword_reaction` tinyint(1) NOT NULL,
  `badword_reaction_time` int(20) NOT NULL,
  PRIMARY KEY (`badword_id`),
  KEY `badword_cid` (`badword_cid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `channels` ADD `channel_badword_reaction` TINYINT( 1 ) NULL ,
ADD `channel_badword_reaction_duration` MEDIUMINT( 7 ) NULL AFTER `channel_badword_reaction` ,
ADD `channel_badword_except` SMALLINT( 3 ) NULL AFTER `channel_badword_reaction_duration`;

UPDATE `channels` SET `channel_badword_reaction` = '0',
`channel_badword_reaction_duration` = '60',
`channel_badword_except` = '400' WHERE `channel_name` = 'defaults';

-- version: 17

ALTER TABLE `bots` ADD `oper_user` VARCHAR( 50 ) NULL AFTER `automodes` ,
ADD `oper_pass` VARCHAR( 50 ) NULL AFTER `oper_user`;

-- version: 18

ALTER TABLE `users` ADD `user_block_invites` TINYINT NOT NULL AFTER `user_reply_privmsg`;

-- version: 19

ALTER TABLE `bots` ADD `secret` TINYINT( 1 ) NOT NULL AFTER `queue`;

-- version: 20
