summaryrefslogtreecommitdiff
path: root/sql-files/convert_guild_tables.sql
blob: 9763f5928a2bbee4cdb0486fb5ab9c1f8d7fc967 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
###################################################################################################
# This one is also necessary, since foreign keys may only reference
# InnoDB tables.

ALTER TABLE `char` TYPE=InnoDB;

###################################################################################################
# Add the new guild column char_id and populate it with Guild Master ids
# Note that the auto-fill is case sensitive!

ALTER TABLE `guild` ADD COLUMN `char_id` int(11) NOT NULL DEFAULT '10000' AFTER `name`;
UPDATE `guild`,`char` SET `guild`.`char_id`=`char`.`char_id` WHERE `guild`.`master` = `char`.`name`;

###################################################################################################
# Now we go on altering stuff - dropping old keys (just in case),
# converting table types, and then creating new keys.

ALTER TABLE guild DROP PRIMARY KEY;
ALTER TABLE guild TYPE=InnoDB;
ALTER TABLE guild 
 ADD PRIMARY KEY  (guild_id,char_id),
 MODIFY COLUMN `guild_id` INTEGER NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 10000,
 ADD KEY char_id (char_id),
 ADD UNIQUE KEY guild_id (guild_id),
 ADD CONSTRAINT `guild_ibfk_1` FOREIGN KEY (`char_id`) REFERENCES `char` 
(`char_id`) ON DELETE CASCADE;

ALTER TABLE guild_alliance DROP INDEX `guild_id`;
ALTER TABLE guild_alliance TYPE=InnoDB;
ALTER TABLE guild_alliance
 ADD PRIMARY KEY  (guild_id,alliance_id),
 ADD KEY alliance_id (alliance_id),
 ADD CONSTRAINT `guild_alliance_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE,
 ADD CONSTRAINT `guild_alliance_ibfk_2` FOREIGN KEY (`alliance_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE;

ALTER TABLE guild_castle DROP PRIMARY KEY, DROP INDEX `guild_id`;
ALTER TABLE guild_castle TYPE=InnoDB;
ALTER TABLE guild_castle
 ADD PRIMARY KEY  (castle_id);

ALTER TABLE guild_expulsion DROP INDEX `guild_id`;
ALTER TABLE guild_expulsion TYPE=InnoDB;
ALTER TABLE guild_expulsion
 ADD  PRIMARY KEY  (guild_id,name),
 ADD CONSTRAINT `guild_expulsion_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE;

ALTER TABLE guild_member DROP INDEX `guild_id`, DROP INDEX `account_id`; 
ALTER TABLE guild_member TYPE=InnoDB;
ALTER TABLE guild_member DROP INDEX `char_id`;
ALTER TABLE guild_member
 ADD  PRIMARY KEY  (guild_id,char_id),
 ADD  KEY char_id (char_id),
 ADD  CONSTRAINT `guild_member_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE,
 ADD  CONSTRAINT `guild_member_ibfk_2` FOREIGN KEY (`char_id`) 
REFERENCES `char` (`char_id`) ON DELETE CASCADE;

ALTER TABLE guild_position DROP INDEX `guild_id`;
ALTER TABLE guild_position TYPE=InnoDB;
ALTER TABLE guild_position
 ADD  PRIMARY KEY  (guild_id,position),
ADD  KEY guild_id (guild_id),
ADD CONSTRAINT `guild_position_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE;

ALTER TABLE guild_skill DROP INDEX `guild_id`;
ALTER TABLE guild_skill TYPE=InnoDB;
ALTER TABLE guild_skill
 ADD  PRIMARY KEY  (guild_id,id),
 ADD  CONSTRAINT `guild_skill_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE;

ALTER TABLE guild_storage DROP INDEX `guild_id`;
ALTER TABLE guild_storage TYPE=InnoDB;
ALTER TABLE guild_storage
 ADD  KEY guild_id (guild_id),
 ADD  CONSTRAINT `guild_storage_ibfk_1` FOREIGN KEY (`guild_id`) 
REFERENCES `guild` (`guild_id`) ON DELETE CASCADE;