-- 21.06.2018 -> added one column and one index
ALTER TABLE `s1_artefacts` ADD `del` TINYINT(1) NULL DEFAULT '0' AFTER `lastupdate`;
ALTER TABLE `testtravian`.`s1_artefacts` ADD INDEX `active-owner-conquered-del` (`active`, `owner`, `conquered`, `del`);

-- 21.05.2018 -> added three indexes
ALTER TABLE `s1_forum_cat` ADD INDEX `display_to_alliances` (`display_to_alliances`(11));
ALTER TABLE `s1_forum_cat` ADD INDEX `display_to_users` (`display_to_users`(11)); 
ALTER TABLE `s1_forum_cat` ADD INDEX `sorting` (`sorting`);

-- 20.05.2018 -> dropped eight columns
ALTER TABLE `s1_forum_topic`
  DROP `alliance0`,
  DROP `player0`,
  DROP `coor0`,
  DROP `report0`;

ALTER TABLE `s1_forum_post`
  DROP `alliance0`,
  DROP `player0`,
  DROP `coor0`,
  DROP `report0`;

-- 19.05.2018 -> added two new columns
ALTER TABLE s1_forum_cat ADD (`display_to_alliances` text,  `display_to_users` text)
  
-- 18.05.2018 -> added a new column
ALTER TABLE s1_forum_cat ADD `sorting` int(11) NOT NULL AFTER `id`

-- 16.05.2018 -> dropped four columns
ALTER TABLE `s1_raidlist` DROP `t7`, DROP `t8`, DROP `t9`, DROP `t10`;

-- 23.04.2018 -> new table
CREATE TABLE IF NOT EXISTS `s1_artefacts_chrono` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `artefactid` int(11) NULL,
  `uid` int(11) NULL,
  `vref` int(11) NULL,
  `conqueredtime` int(11) NULL,
  PRIMARY KEY (`id`),
  KEY `artefactid-conqueredtime` (`artefactid`,`conqueredtime`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

-- 7.01.2018 -> new column
ALTER TABLE s1_fdata ADD `ww_lastupdate` int(11) NULL DEFAULT NULL AFTER `wwname`;

-- 2.12.2017 -> new indexes
ALTER TABLE `s1_vdata` ADD INDEX(`exp1`);
ALTER TABLE `s1_vdata` ADD INDEX(`exp2`);
ALTER TABLE `s1_vdata` ADD INDEX(`exp3`);

-- 17.11.2017 -> query optimizations
ALTER TABLE `s1_prisoners` DROP INDEX `from`, ADD INDEX `from-t11` (`from`, `t11`);
ALTER TABLE `s1_enforcement` DROP INDEX `from`, ADD INDEX `from` (`from`, `hero`) USING BTREE;
ALTER TABLE `s1_forum_post` CHANGE `date` `date` INT NULL DEFAULT NULL;
ALTER TABLE `s1_market` DROP INDEX `vref-accept`, ADD INDEX `vref-accept-merchant` (`vref`, `accept`, `merchant`) USING BTREE;
ALTER TABLE `s1_mdata` ADD INDEX `target-viewed` (`target`, `viewed`);
ALTER TABLE `s1_ndata` ADD INDEX `uid-viewed` (`uid`, `viewed`);


-- 8.11.2017 -> query optimizations and cleanups
ALTER TABLE `s1_ww_attacks` ADD INDEX(`vid`);


-- 2.11.2017 -> Hero fixes
ALTER TABLE `s1_hero` ADD INDEX(`lastupdate`);
ALTER TABLE `s1_hero` DROP INDEX `uid`, ADD INDEX `uid` (`uid`, `dead`) USING BTREE;
ALTER TABLE `s1_hero` ADD INDEX(`inrevive`);
ALTER TABLE `s1_hero` ADD INDEX(`intraining`);


-- 31.10.2017 -> Embassy and alliance updates
ALTER TABLE `s1_ali_permission` ADD INDEX(`alliance`);
ALTER TABLE `s1_allimedal` ADD INDEX(`allyid`);
ALTER TABLE `s1_ali_permission` DROP INDEX `uid-alliance`, ADD UNIQUE `uid-alliance` (`uid`, `alliance`) USING BTREE;


-- 27.10.2017 -> SQL optimizations
ALTER TABLE `s1_route` ADD INDEX `uid-timestamp` (`uid`, `timestamp`);


-- 24.10.2017 -> SQL optimizations
ALTER TABLE `s1_users` ADD INDEX(`sit1`);
ALTER TABLE `s1_users` ADD INDEX(`sit2`);
ALTER TABLE `s1_ndata` ADD INDEX(`toWref`);
ALTER TABLE `s1_wdata` ADD INDEX `x-y` (`x`, `y`);
ALTER TABLE `s1_a2b` ADD INDEX `ckey` (`ckey`(25));
ALTER TABLE `s1_ali_permission` ADD INDEX `uid-alliance` (`uid`, `alliance`);
ALTER TABLE `s1_forum_cat` CHANGE `alliance` `alliance` INT NOT NULL;
ALTER TABLE `s1_forum_cat` ADD INDEX `alliance-forum_area` (`alliance`, `forum_area`);
ALTER TABLE `s1_forum_topic` CHANGE `cat` `cat` INT NOT NULL;
ALTER TABLE `s1_forum_topic` ADD INDEX `cat-stick` (`cat`, `stick`);
ALTER TABLE `s1_forum_edit` CHANGE `alliance` `alliance` INT NOT NULL;
ALTER TABLE `s1_forum_edit` ADD INDEX(`alliance`);
ALTER TABLE `s1_forum_post` CHANGE `topic` `topic` INT NOT NULL, CHANGE `owner` `owner` INT NOT NULL;
ALTER TABLE `s1_forum_topic` CHANGE `post_date` `post_date` INT NOT NULL;
ALTER TABLE `s1_forum_topic` CHANGE `owner` `owner` INT NOT NULL, CHANGE `alliance` `alliance` INT NOT NULL, CHANGE `ends` `ends` INT NOT NULL, CHANGE `close` `close` TINYINT NOT NULL, CHANGE `stick` `stick` TINYINT NOT NULL;
ALTER TABLE `s1_forum_topic` CHANGE `date` `date` INT NOT NULL;
ALTER TABLE `s1_ali_log` ADD INDEX(`aid`);
ALTER TABLE `s1_alidata` ADD INDEX(`tag`);
ALTER TABLE `s1_alidata` ADD INDEX(`name`);
ALTER TABLE `s1_alidata` ADD INDEX(`leader`);
ALTER TABLE `s1_ali_invite` ADD INDEX `alliance-accept` (`alliance`, `accept`);
ALTER TABLE `s1_ali_invite` ADD INDEX(`uid`);
ALTER TABLE `s1_users` ADD INDEX(`gold`);
ALTER TABLE `s1_farmlist` ADD INDEX(`owner`);
ALTER TABLE `s1_raidlist` CHANGE  `distance`  `distance` FLOAT NULL DEFAULT  '0';
ALTER TABLE `s1_raidlist` ADD INDEX `lid-distance` (`lid`, `distance`);
ALTER TABLE `s1_artefacts` ADD INDEX `size-type` (`size`, `type`);
ALTER TABLE `s1_odata` ADD INDEX(`maxstore`);
ALTER TABLE `s1_odata` ADD INDEX(`maxcrop`);


-- 23.10.2017 -> SQL optimizations
ALTER TABLE `s1_medal` ADD INDEX(`week`);
ALTER TABLE `s1_market` ADD INDEX `vref-accept` (`vref`, `accept`);
ALTER TABLE `s1_fdata` ADD INDEX(`f99`);
ALTER TABLE `s1_fdata` ADD INDEX(`f99t`);
ALTER TABLE `s1_diplomacy` ADD INDEX(`alli1`);
ALTER TABLE `s1_diplomacy` ADD INDEX(`alli2`);
ALTER TABLE `s1_diplomacy` ADD INDEX `type-accepted` (`type`, `accepted`);
ALTER TABLE `s1_wdata` ADD INDEX(`fieldtype`);


-- 22.10.2017 -> SQL optimizations
ALTER TABLE `s1_users` ADD INDEX(`tribe`);
ALTER TABLE `s1_users` ADD INDEX `timestamp-tribe` (`timestamp`, `tribe`);
ALTER TABLE `s1_users` DROP INDEX `username`;
ALTER TABLE `s1_users` ADD UNIQUE `username` (`username`);
ALTER TABLE `s1_activate` CHANGE `username` `username` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `s1_activate` ADD UNIQUE `username` (`username`);
ALTER TABLE `s1_activate` CHANGE `email` `email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `s1_activate` ADD UNIQUE(`email`);
ALTER TABLE `s1_users` CHANGE `email` `email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
-- YOU MAY NOT NEED THESE IF YOUR EMAILS FOR THESE 3 ACCOUNTS ARE ALREADY DIFFERENT FROM ONE ANOTHER
UPDATE `s1_users` SET `email` = 'support@travianz.game' WHERE `s1_users`.`id` = 1;
UPDATE `s1_users` SET `email` = 'nature@travianz.game' WHERE `s1_users`.`id` = 2;
UPDATE `s1_users` SET `email` = 'taskmaster@travianz.game' WHERE `s1_users`.`id` = 4;
-- END OF "YOU MAY NOT NEED THESE"
ALTER TABLE `s1_users` ADD UNIQUE `email` (`email`);
ALTER TABLE `s1_users` ADD INDEX(`access`);
ALTER TABLE `s1_active` ADD INDEX(`timestamp`);
ALTER TABLE `s1_odata` ADD INDEX(`clay`);
ALTER TABLE `s1_odata` ADD INDEX(`crop`);
ALTER TABLE `s1_odata` ADD INDEX(`iron`);
ALTER TABLE `s1_odata` ADD INDEX(`wood`);
ALTER TABLE `s1_vdata` ADD INDEX(`crop`);
ALTER TABLE `s1_vdata` ADD INDEX(`iron`);
ALTER TABLE `s1_vdata` ADD INDEX(`clay`);
ALTER TABLE `s1_vdata` ADD INDEX(`wood`);
ALTER TABLE `s1_deleting` ADD INDEX(`timestamp`);
ALTER TABLE `s1_movement` ADD INDEX `proc-sort_type-endtime` (`proc`, `sort_type`, `endtime`);
ALTER TABLE `s1_vdata` ADD INDEX(`starv`);
ALTER TABLE `s1_vdata` ADD INDEX(`loyalty`);
ALTER TABLE `s1_odata` ADD INDEX(`loyalty`);
ALTER TABLE `s1_artefacts` ADD INDEX `active-type-lastupdate` (`active`, `type`, `lastupdate`);


-- 22.10.2017 -> forum topics table and indexe changes
ALTER TABLE `s1_forum_post` CHANGE `topic` `topic` INT NULL DEFAULT NULL;
ALTER TABLE `s1_forum_post` CHANGE `owner` `owner` INT NULL DEFAULT NULL;
ALTER TABLE `s1_forum_post` ADD INDEX `topic-owner` (`topic`, `owner`);


-- 20.10.2017 -> changing MD5 for bcrypt password hashing algo
ALTER TABLE `s1_users` ADD `is_bcrypt` TINYINT(1) NOT NULL DEFAULT '0' AFTER `vactwoweeks`;