root/trunk/sql/updates/0.8/4501.sql @ 2

Revision 2, 6.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1-- Add definitly a very usefull index to this creature table
2-- If this sql file fails because the index already exists, comment the following line
3ALTER TABLE `creature` ADD INDEX `index_id` (id);
4
5-- Add suport to creature table for equipment and model overwritting
6ALTER TABLE `creature` 
7    ADD COLUMN `equipment_id` int(11) NOT NULL default '0' AFTER `map`,
8    ADD COLUMN `modelid` int(11) unsigned default '0' AFTER `map`;
9
10-- Creation of creature_model_info table
11DROP TABLE IF EXISTS `creature_model_info`;
12CREATE TABLE `creature_model_info` (
13  `modelid` int(11) unsigned NOT NULL default '0',
14  `bounding_radius` float NOT NULL default '0',
15  `combat_reach` float NOT NULL default '0',
16  `gender` tinyint(2) unsigned NOT NULL default '2',
17  `modelid_other_gender` int(11) unsigned NOT NULL default '0',
18  PRIMARY KEY  (`modelid`)
19) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Creature System (Model related info)';
20
21-- Correct possible db problems
22UPDATE `creature_template` SET `bounding_radius`=0 WHERE `bounding_radius` IS NULL;
23UPDATE `creature_template` SET `combat_reach`=0 WHERE `combat_reach` IS NULL;
24UPDATE `creature_template` SET `modelid_m`=0 WHERE `modelid_m` IS NULL;
25UPDATE `creature_template` SET `modelid_f`=0 WHERE `modelid_f` IS NULL;
26
27-- All models defined in creature_template are used to build the table
28INSERT IGNORE INTO `creature_model_info` (`modelid`) SELECT DISTINCT `modelid_m` FROM `creature_template`;
29INSERT IGNORE INTO `creature_model_info` (`modelid`) SELECT DISTINCT `modelid_f` FROM `creature_template`;
30
31-- Copy the data from creature_template to creature_model_info
32UPDATE `creature_model_info`,`creature_template` SET
33    `creature_model_info`.`bounding_radius`=`creature_template`.`bounding_radius`,
34    `creature_model_info`.`combat_reach`=`creature_template`.`combat_reach`,
35    `creature_model_info`.`modelid_other_gender`=`creature_template`.`modelid_f`
36    WHERE `creature_model_info`.`modelid`=`creature_template`.`modelid_m`;
37
38UPDATE `creature_model_info`,`creature_template` SET
39    `creature_model_info`.`bounding_radius`=`creature_template`.`bounding_radius`,
40    `creature_model_info`.`combat_reach`=`creature_template`.`combat_reach`,
41    `creature_model_info`.`modelid_other_gender`=`creature_template`.`modelid_m`
42    WHERE `creature_model_info`.`modelid`=`creature_template`.`modelid_f`;
43
44-- Some changes in fields of creature_template
45ALTER TABLE `creature_template`
46    CHANGE `modelid_m` `modelid_A` int(11) unsigned NOT NULL default '0',
47    CHANGE `modelid_f` `modelid_H` int(11) unsigned NOT NULL default '0',
48    ADD COLUMN `faction_H` int(4) unsigned NOT NULL default '0' AFTER `faction`,
49    ADD COLUMN `equipment_id` int(11) unsigned NOT NULL default '0' AFTER `RacialLeader`,
50    ADD COLUMN `RegenHealth` tinyint(1) unsigned NOT NULL default '1' AFTER `RacialLeader`,
51    DROP COLUMN `bounding_radius`,
52    DROP COLUMN `combat_reach`,
53    -- This index is temporary and enable the population of creature_equip_template to be fast
54    ADD INDEX `idx_tmp` (`equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3`);
55
56ALTER TABLE `creature_template`
57    CHANGE `faction` `faction_A` int(4) unsigned NOT NULL default '0';
58
59-- Create table creature_equip_template with temporary auto-increment key
60DROP TABLE IF EXISTS `creature_equip_template`;
61CREATE TABLE `creature_equip_template` (
62  `entry` int(11) unsigned NOT NULL auto_increment COMMENT 'Unique entry',
63  `equipmodel1` int(11) unsigned NOT NULL default '0',
64  `equipmodel2` int(11) unsigned NOT NULL default '0',
65  `equipmodel3` int(11) unsigned NOT NULL default '0',
66  `equipinfo1` int(11) unsigned NOT NULL default '0',
67  `equipinfo2` int(11) unsigned NOT NULL default '0',
68  `equipinfo3` int(11) unsigned NOT NULL default '0',
69  `equipslot1`  int(11) NOT NULL default '0',
70  `equipslot2`  int(11) NOT NULL default '0',
71  `equipslot3`  int(11) NOT NULL default '0',
72  PRIMARY KEY  (`entry`)
73) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Creature System (Equipment)';
74
75-- Fill the creature_equip_template table with values from creature_template
76INSERT INTO `creature_equip_template` (`equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3`) 
77    (SELECT DISTINCT `equipmodel1`,`equipmodel2`,`equipmodel3`,`equipinfo1`,`equipinfo2`,`equipinfo3`,`equipslot1`,`equipslot2`,`equipslot3` FROM `creature_template` WHERE `equipmodel1`<>0 OR `equipmodel2`<>0 OR `equipmodel3`<>0);
78
79-- Then add to creature_template the id generated for equipements
80UPDATE `creature_template`,`creature_equip_template` SET
81    `creature_template`.`equipment_id`=`creature_equip_template`.`entry`
82    WHERE `creature_template`.`equipmodel1`=`creature_equip_template`.`equipmodel1` AND
83        `creature_template`.`equipmodel2`=`creature_equip_template`.`equipmodel2` AND
84        `creature_template`.`equipmodel3`=`creature_equip_template`.`equipmodel3` AND
85        `creature_template`.`equipinfo1`=`creature_equip_template`.`equipinfo1` AND
86        `creature_template`.`equipinfo2`=`creature_equip_template`.`equipinfo2` AND
87        `creature_template`.`equipinfo3`=`creature_equip_template`.`equipinfo3` AND
88        `creature_template`.`equipslot1`=`creature_equip_template`.`equipslot1` AND
89        `creature_template`.`equipslot2`=`creature_equip_template`.`equipslot2` AND
90        `creature_template`.`equipslot3`=`creature_equip_template`.`equipslot3`;
91
92-- Remove all equipment fields from creature_template, this will remove the temporary index
93ALTER TABLE `creature_template`
94    DROP COLUMN `equipmodel1`,
95    DROP COLUMN `equipmodel2`,
96    DROP COLUMN `equipmodel3`,
97    DROP COLUMN `equipinfo1`,
98    DROP COLUMN `equipinfo2`,
99    DROP COLUMN `equipinfo3`,
100    DROP COLUMN `equipslot1`,
101    DROP COLUMN `equipslot2`,
102    DROP COLUMN `equipslot3`;
103
104-- Make all modelid and faction fields filled
105UPDATE `creature_template` SET `modelid_A`=`modelid_H` WHERE `modelid_A`=0 AND `modelid_H`<>0;
106UPDATE `creature_template` SET `modelid_H`=`modelid_A` WHERE `modelid_H`=0 AND `modelid_A`<>0;
107UPDATE `creature_template` SET `faction_A`=`faction_H` WHERE `faction_A`=0 AND `faction_H`<>0;
108UPDATE `creature_template` SET `faction_H`=`faction_A` WHERE `faction_H`=0 AND `faction_A`<>0;
109
110-- Finaly remove the no more necessary auto-increment from creature_equip_template
111ALTER TABLE `creature_equip_template`
112    CHANGE `entry` `entry` int(11) unsigned NOT NULL default '0' COMMENT 'Unique entry';
Note: See TracBrowser for help on using the browser.