# from 1086 to 1088

ALTER TABLE traits ADD shader varchar(32);
ALTER TABLE character_quests DROP notes;

# from 1088 to 1090

ALTER TABLE accounts ADD (spam_points tinyint(1) default '0');
ALTER TABLE accounts MODIFY COLUMN spam_points tinyint(1) default '0' AFTER banned_until;

ALTER TABLE characters ADD (animal_affinity text);
ALTER TABLE characters ADD (familiar_id int(10) NOT NULL DEFAULT '0');

DELETE FROM movement_base where name='Fly';
UPDATE movement_base SET family=4 where id=4 and id=5;

#ALTER TABLE skills ADD (category varchar(255) NOT NULL default 'VARIOUS');
source skills.sql

UPDATE server_options set option_value=1090 where option_name='db_version';

#from 1090 to 1091

ALTER TABLE characters ADD (last_login datetime default NULL);
ALTER TABLE characters MODIFY COLUMN last_login datetime default NULL AFTER guild_private_notes;

UPDATE server_options SET option_value=1091 where option_name='db_version';

#from 1091 to 1092
ALTER TABLE characters ADD ( `character_type` int(10) unsigned default '0' );
ALTER TABLE characters MODIFY COLUMN character_type int(10) unsigned default '0' AFTER racegender_id;
ALTER TABLE characters ADD ( `owner_id` int(10) unsigned NOT NULL default '0' );

UPDATE server_options SET option_value=1092 where option_name='db_version';

#from 1092 to 1093

DROP TABLE movement_base;
DROP TABLE movement_require;
DROP TABLE movement_variant;
DROP TABLE movement_extras;
SOURCE movement_extras.sql;
SOURCE movement_require.sql;
SOURCE movement_variant.sql;
SOURCE movement_base.sql;

UPDATE server_options SET option_value=1093 where option_name='db_version';

ALTER TABLE tips MODIFY COLUMN tip varchar(64);
ALTER TABLE server_options MODIFY COLUMN option_value varchar(90);
ALTER TABLE guilds MODIFY COLUMN motd char(90);


#from 1093 to 1096

INSERT INTO item_categories VALUES (21,'Coins');

ALTER TABLE character_quests CHANGE completiondate remaininglockout int(10) default '0';
ALTER TABLE npc_triggers DROP COLUMN quest_id;
ALTER TABLE quests ADD COLUMN category varchar(30) NOT NULL DEFAULT '' AFTER quest_lockout_time;
ALTER TABLE quests ADD COLUMN prerequisite varchar(250) NOT NULL DEFAULT '' AFTER category;
ALTER TABLE quest_scripts ADD COLUMN quest_id int(10) unsigned NOT NULL DEFAULT '0' AFTER id;

UPDATE quests, quest_scripts  SET quests.category=quest_scripts.category where quests.id=quest_scripts.id;
UPDATE quest_scripts SET quest_id=id;

ALTER TABLE quest_scripts DROP COLUMN category;
ALTER TABLE quest_scripts DROP COLUMN name;
ALTER TABLE accounts MODIFY COLUMN security_level tinyint(3);

UPDATE server_options SET option_value=1096 where option_name='db_version';

#from 1096 to 1097
SOURCE command_access.sql;

#from 1097 to 1098

SOURCE bans.sql;

ALTER TABLE accounts DROP COLUMN banned_until;
ALTER TABLE accounts ADD COLUMN last_login_hostname varchar(255) default NULL AFTER last_login_ip;

UPDATE server_options SET option_value=1098 where option_name='db_version';

#from 1098 to 1099

ALTER TABLE item_stats MODIFY COLUMN id bigint(20);
ALTER TABLE hunt_locations MODIFY COLUMN itemid bigint(20);
ALTER TABLE natural_resources MODIFY COLUMN item_id_reward bigint(20);
ALTER TABLE spell_glyphs MODIFY COLUMN item_id bigint(20);
ALTER TABLE loot_rule_details MODIFY COLUMN item_stat_id bigint(20);

DROP TABLE command_group_assignment;
DROP TABLE command_groups;
SOURCE command_access.sql;

UPDATE server_options SET option_value=1099 where option_name='db_version';

#from 1099 to 1100

ALTER TABLE accounts ADD COLUMN advisor_points int(10) NOT NULL default '0' AFTER spam_points;
ALTER TABLE characters DROP COLUMN advisor_points;

UPDATE server_options SET option_value=1100 where option_name='db_version';

# Does not require a db version dump.
drop table sys_modules;
drop table sys_privileges;
drop table sys_privileges_list;
drop table sys_programs;

#from 1100 to 1101

DROP TABLE command_group_assignment;
DROP TABLE command_groups;
SOURCE command_access.sql;

UPDATE server_options SET option_value=1101 where option_name='db_version';

#from 1101 to 1102

ALTER TABLE item_stats ADD COLUMN cstr_id_part_mesh int(10) NOT NULL default '0' AFTER cstr_id_part;
UPDATE server_options SET option_value=1102 where option_name='db_version';

#from 1102 to 1103

DROP TABLE command_group_assignment;
DROP TABLE command_groups;
SOURCE command_access.sql;

UPDATE characters SET mod_hitpoints = base_hitpoints_max WHERE (character_type = 1 OR character_type = 2) AND base_hitpoints_max > 0.0;

UPDATE server_options SET option_value=1103 where option_name='db_version';

#from 1103 to 1104

ALTER TABLE sectors ADD COLUMN rain_min_fade_in int(10) unsigned NOT NULL DEFAULT '0' AFTER rain_max_drops;
ALTER TABLE sectors ADD COLUMN rain_max_fade_in int(10) unsigned NOT NULL DEFAULT '0' AFTER rain_min_fade_in;
ALTER TABLE sectors ADD COLUMN rain_min_fade_out int(10) unsigned NOT NULL DEFAULT '0' AFTER rain_max_fade_in;
ALTER TABLE sectors ADD COLUMN rain_max_fade_out int(10) unsigned NOT NULL DEFAULT '0' AFTER rain_min_fade_out;

UPDATE server_options SET option_value=1104 where option_name='db_version';

#from 1104 to 1105

ALTER TABLE characters
  ADD COLUMN help_event_flags int(11) unsigned NULL DEFAULT 0 COMMENT 'Bit field of which instruction events have played for him.';
ALTER TABLE `tips`
  CHANGE COLUMN `id` `id` int(10) unsigned NULL auto_increment;
ALTER TABLE `tips`
  CHANGE COLUMN `tip` `tip` varchar(255) NOT NULL DEFAULT '';


INSERT INTO `tips` VALUES (1001,'Welcome to the world of Yliakum, a huge underground cave with many strange and wonderful sights.  Use your arrow keys to walk around and explore.');
INSERT INTO `tips` VALUES (1002,'You can move using the arrow keys, or strafe using WASD keys.  Holding Shift makes you run.  Movement takes your stamina, which means you get tired faster running than walking.  Next, find the merchant named Thorian and right-click him.');
INSERT INTO `tips` VALUES (1003,'When you right-click another player or npc in the game, that is called \"targeting.\"  You always have to target what you are focused on so that PlaneShift knows your intent when attacking, chatting or inspecting.');
INSERT INTO `tips` VALUES (1004,'To talk to any NPC, target him/her and talk normally in the chat window.  Say \'hello\' to the NPC now and see if he responds in your chat window.');
INSERT INTO `tips` VALUES (1005,'Congratulations, you now have a quest assigned.  To help find rats, try targeting the sign behind Thorian to get directions.');


UPDATE server_options SET option_value=1105 where option_name='db_version';

#from 1105 to 1106

ALTER TABLE sectors ADD COLUMN rain_enabled char(1) NOT NULL DEFAULT 'N' AFTER name;
UPDATE sectors SET rain_enabled="Y" where rain_max_duration != 0;

UPDATE server_options SET option_value=1106 where option_name='db_version';

#from 1106 to 1107

DROP TABLE command_group_assignment;
DROP TABLE command_groups;
SOURCE command_access.sql;

#from 1107 to 1108
ALTER TABLE characters DROP COLUMN familiar_id;
SOURCE char_create_affinity.sql;

UPDATE server_options SET option_value=1108 where option_name='db_version';

#from 1108 to 1109

ALTER TABLE characters CHANGE COLUMN `experience_points` `experience_points` int(10) unsigned default '0';
ALTER TABLE hunt_locations CHANGE COLUMN `itemid` `itemid` int(10) NOT NULL default '0';
ALTER TABLE item_instances CHANGE COLUMN id id int(10) unsigned NOT NULL auto_increment;
ALTER TABLE item_instances CHANGE COLUMN parent_item_id parent_item_id int(10) unsigned default '0';
ALTER TABLE item_stats CHANGE COLUMN `id` `id` int(10) unsigned NOT NULL auto_increment;
ALTER TABLE loot_rule_details CHANGE COLUMN item_stat_id item_stat_id int(10) unsigned NOT NULL DEFAULT '0';
ALTER TABLE natural_resources CHANGE COLUMN item_id_reward item_id_reward int(10) unsigned DEFAULT '0';
ALTER TABLE npc_spawn_rules CHANGE COLUMN min_spawn_time min_spawn_time int(10) unsigned NOT NULL DEFAULT '0';
ALTER TABLE npc_spawn_rules CHANGE COLUMN max_spawn_time max_spawn_time int(10) unsigned NOT NULL DEFAULT '0';
ALTER TABLE spell_glyphs CHANGE COLUMN item_id item_id int(10) unsigned NOT NULL DEFAULT '0';
ALTER TABLE trade_autocontainers CHANGE COLUMN item_instance_id item_instance_id int(10) unsigned DEFAULT '0';
ALTER TABLE trade_autocontainers CHANGE COLUMN garbage_item_id garbage_item_id int(10) unsigned DEFAULT '0';
ALTER TABLE trade_combinations CHANGE COLUMN result_id result_id int(10) unsigned NOT NULL;
ALTER TABLE trade_combinations CHANGE COLUMN item_id item_id int(10) unsigned NOT NULL;
ALTER TABLE trade_patterns CHANGE COLUMN designitem_id designitem_id int(10) unsigned;
ALTER TABLE trade_transformations CHANGE COLUMN result_id result_id int(10) unsigned NOT NULL;
ALTER TABLE trade_transformations CHANGE COLUMN item_id item_id int(10) unsigned NOT NULL;
ALTER TABLE trade_transformations CHANGE COLUMN workitem_id workitem_id int(10) unsigned NOT NULL;
ALTER TABLE trade_transformations CHANGE COLUMN equipment_id equipment_id int(10) unsigned;
ALTER TABLE trade_transformations CHANGE COLUMN garbage_id garbage_id int(10) unsigned;

UPDATE server_options SET option_value=1109 where option_name='db_version';

#from 1109 to 1110

### Create character_relationships table
CREATE TABLE `character_relationships` 
( 
	character_id int(11) NOT NULL default '0' 			COMMENT 'character id from the characters table' ,
	related_id int(11) NOT NULL default '0'             COMMENT 'character id of the related character' ,
	relationship_type varchar(15) NOT NULL default ''   COMMENT 'one of three values currently `familiar`, `buddy`, or `spouse` ' ,
	spousename  varchar(30) default NULL                COMMENT 'used for marriages, historical data in case of deletion' ,
	
	PRIMARY KEY (`character_id`, `relationship_type`, `related_id` ), 
	KEY ( `character_id` ),
	KEY (`related_id`, `relationship_type`) 
); 

### Copy Buddies
INSERT INTO character_relationships ( character_id, related_id, relationship_type )
SELECT player_id, player_buddy, 'buddy' FROM buddy_list;
DROP TABLE buddy_list;

### Copy Marriage Data
ALTER TABLE characters ADD COLUMN old_lastname VARCHAR(30) NOT NULL DEFAULT '' AFTER lastname;
UPDATE characters c, character_marriage_details cmd SET c.old_lastname = cmd.old_lastname
	WHERE cmd.character_id = c.id;
	
INSERT INTO character_relationships ( character_id, related_id, relationship_type, spousename )
	SELECT character_id, spouse.id, 'spouse', CONCAT( spouse.name, ' ', spouse.lastname )
	FROM character_marriage_details cmd, characters spouse
	WHERE STRCMP( cmd.spousename , CONCAT( spouse.name, ' ', spouse.lastname ) ) = 0;
	
DROP TABLE character_marriage_details;

### Copy Pet Data
INSERT INTO character_relationships ( character_id, related_id, relationship_type )
	SELECT owner_id, id, 'familiar'
	FROM characters
	WHERE owner_id <> 0;
	
ALTER TABLE characters DROP COLUMN owner_id;


UPDATE server_options SET option_value=1110 where option_name='db_version';

#from 1110 to 1111

source tribes.sql
source tribe_members.sql

UPDATE server_options SET option_value=1111 where option_name='db_version';

### 1111 to 1112 - Keith

#add item quality tracking columns
ALTER TABLE `item_stats` CHANGE COLUMN `item_quality` `item_max_quality` int(4) NULL DEFAULT 100;

ALTER TABLE `item_instances` DROP COLUMN `item_decay`;
ALTER TABLE `item_instances` ADD COLUMN `decay_resistance` float(3,2) NOT NULL DEFAULT 0.0 AFTER `loc_yrot`;

ALTER TABLE `item_stats` DROP COLUMN `decay_resistance`;
ALTER TABLE `item_stats` ADD COLUMN `decay_rate` float(3,2) NOT NULL DEFAULT 0.1 AFTER `flags`;

# Set all current items to defaults
update item_stats set decay_rate=0.1;
update item_stats set item_max_quality=50;
update item_instances set decay_resistance=0;
update item_instances set item_quality=50;

UPDATE server_options SET option_value=1112 where option_name='db_version';

### 1112 to 1113 - Luca

ALTER TABLE tips CHANGE COLUMN tip tip text NOT NULL default '';
UPDATE server_options SET option_value=1113 where option_name='db_version';

### 1113 to 1114 - Keith

ALTER TABLE `item_categories` ADD COLUMN `item_stat_id_repair_tool` int(11) NULL;
ALTER TABLE `item_categories` ADD COLUMN `is_repair_tool_consumed` char(1) NULL DEFAULT 'Y';
ALTER TABLE `item_categories` ADD COLUMN `skill_id_repair` int(11) NULL;
UPDATE server_options SET option_value=1114 where option_name='db_version';


### 1114 to 1115 - Keith
ALTER TABLE `npc_bad_text` ADD COLUMN `triggertext` varchar(255) NULL AFTER `badtext`;
UPDATE `server_options` SET `option_value`='1115' WHERE `option_name`='db_version';


### 1115 to 1116 - Keith
ALTER TABLE item_stats ADD COLUMN `illum_definition` text NULL COMMENT 'This is used for map/sketch xml';
UPDATE `server_options` SET `option_value`='1116' WHERE `option_name`='db_version';

### 1116 to 1117 - Dave
ALTER TABLE accounts DROP COLUMN last_login_hostname;
ALTER TABLE bans DROP COLUMN host_mask;
ALTER TABLE bans ADD COLUMN ip_range CHAR(15) default NULL AFTER account;
UPDATE `server_options` SET `option_value`='1117' WHERE `option_name`='db_version';

### 1117 to 1118 - Dave
DROP TABLE command_group_assignment;
DROP TABLE command_groups;
SOURCE command_access.sql;
UPDATE `server_options` SET `option_value`='1118' WHERE `option_name`='db_version';

### 1118 to 1119 - Dave
DROP TABLE movement_base;
DROP TABLE movement_extras;
DROP TABLE movement_require;
DROP TABLE movement_variant;
SOURCE movement.sql;
UPDATE `server_options` SET `option_value`='1119' WHERE `option_name`='db_version';


### 1119 to 1120 - Acraig,  adding render_effect column to trades 
ALTER TABLE trade_transformations ADD COLUMN render_effect CHAR(32) default NULL AFTER animation;
UPDATE `server_options` SET `option_value`='1120' WHERE `option_name`='db_version';

### 1120 to 1121 - Michael - Added familiar types to complete familiar affinity
CREATE TABLE `familiar_types`
(
	`id` INT UNSIGNED NOT NULL ,
	`name` VARCHAR(30) NOT NULL,
	`type` VARCHAR(30) NOT NULL,
	`lifecycle` VARCHAR(30) NOT NULL,
	`attacktool` VARCHAR(30) NOT NULL,
	`attacktype` VARCHAR(30) NOT NULL,
	`magicalaffinity` VARCHAR(30) NOT NULL,
	`vision` INT NULL,   /* 1 = enhanced, 0 = normal, -1 = limited */
	`speed` INT NULL,    /* 1 = enhanced, 0 = normal, -1 = limited */
	`hearing` INT NULL,  /* 1 = enhanced, 0 = normal, -1 = limited */
	PRIMARY KEY (`id`)
) ENGINE=MyISAM ;
UPDATE `server_options` SET `option_value`='1121' WHERE `option_name`='db_version';

### 1121 to 1122 - Luca - changed natural res to use id of sector
alter table natural_resources drop column sector;
alter table natural_resources ADD COLUMN loc_sector_id int(10) unsigned NOT NULL default '0' AFTER id;
UPDATE `server_options` SET `option_value`='1122' WHERE `option_name`='db_version';

### 1122 to 1123 - Magodra - Added table for waypoints used in super clients (NPC Client).
source sc_waypoints.sql;
source sc_waypoint_links.sql;
UPDATE `server_options` SET `option_value`='1123' WHERE `option_name`='db_version';

### 1123 to 1124 - Magodra - Added tribe home
DROP table tribes; # Since tribes isn't deployed yet, assumes that there are now data.
source tribes.sql;
UPDATE `server_options` SET `option_value`='1124' WHERE `option_name`='db_version';

### 1124 to 1125 - Luca - added armor_id on the race definition to manage natural armor
alter table race_info add column `armor_id` int(10) default '0';
UPDATE `server_options` SET `option_value`='1125' WHERE `option_name`='db_version';

### 1125 to 1126 - acraig - Added helm column to races to have a helm group
ALTER TABLE race_info ADD  COLUMN `helm` varchar(16) default '';
UPDATE race_info SET helm='ylianm' WHERE race_id=13 OR race_id=11;
UPDATE server_options SET option_value=1126 where option_name='db_version';

