aboutsummaryrefslogtreecommitdiff
path: root/sql/tools
diff options
context:
space:
mode:
Diffstat (limited to 'sql/tools')
-rw-r--r--sql/tools/Makefile.am36
-rw-r--r--sql/tools/README10
-rw-r--r--sql/tools/characters_item_duplicates_remove.sql22
-rw-r--r--sql/tools/characters_pet_data_cleanup.sql3
4 files changed, 71 insertions, 0 deletions
diff --git a/sql/tools/Makefile.am b/sql/tools/Makefile.am
new file mode 100644
index 00000000000..f489b83088b
--- /dev/null
+++ b/sql/tools/Makefile.am
@@ -0,0 +1,36 @@
+# Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+## Process this file with automake to produce Makefile.in
+
+## Sub-directories to parse
+
+## Change installation location
+# datadir = mangos/sql/tools
+pkgdatadir = $(datadir)/mangos/sql/tools
+
+## Files to be installed
+# Install basic SQL files to datadir
+pkgdata_DATA = \
+ characters_item_duplicates_remove.sql \
+ characters_pet_data_cleanup.sql \
+ README
+
+## Additional files to include when running 'make dist'
+EXTRA_DIST = \
+ characters_item_duplicates_remove.sql \
+ characters_pet_data_cleanup.sql \
+ README
diff --git a/sql/tools/README b/sql/tools/README
new file mode 100644
index 00000000000..de60305cece
--- /dev/null
+++ b/sql/tools/README
@@ -0,0 +1,10 @@
+= MaNGOS -- README =
+
+Copyright (c) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+
+See the COPYING file for copying conditions.
+
+== Database tools ==
+This folder contains SQL files which can be used for cleanup DB from corrupted or outdated data in safe way.
+This tools must be used _only_ when mangos server stopped.
+But you can safely use its any times while server shutdown.
diff --git a/sql/tools/characters_item_duplicates_remove.sql b/sql/tools/characters_item_duplicates_remove.sql
new file mode 100644
index 00000000000..9cdd8738ecd
--- /dev/null
+++ b/sql/tools/characters_item_duplicates_remove.sql
@@ -0,0 +1,22 @@
+DROP TABLE IF EXISTS item_test;
+CREATE TABLE item_test
+SELECT w.`item_guid`,w.`source`,w.`count` FROM
+ (SELECT u.`item_guid`,u.`source`,COUNT(u.`item_guid`) as `count` FROM
+ ((SELECT c.`item` as `item_guid`, 'i' as `source` FROM character_inventory c) UNION
+ (SELECT a.`itemguid` as `item_guid`, 'a' as `source` FROM auctionhouse a) UNION
+ (SELECT m.`item_guid` as `item_guid`, 'm' as `source` FROM mail_items m) UNION
+ (SELECT g.`item_guid` as `item_guid`, 'g' as `source` FROM guild_bank_item g)
+ ) as u
+ GROUP BY u.`item_guid`
+ ) as w
+ WHERE w.`count` > 1;
+
+DELETE FROM auctionhouse WHERE itemguid IN (SELECT item_guid FROM item_test WHERE `source`='i');
+DELETE FROM mail_items WHERE item_guid IN (SELECT item_guid FROM item_test WHERE `source`='i');
+DELETE FROM guild_bank_item WHERE item_guid IN (SELECT item_guid FROM item_test WHERE `source`='i');
+
+DELETE FROM mail_items WHERE item_guid IN (SELECT item_guid FROM item_test WHERE `source`='a');
+DELETE FROM guild_bank_item WHERE item_guid IN (SELECT item_guid FROM item_test WHERE `source`='a');
+
+DELETE FROM guild_bank_item WHERE item_guid IN (SELECT item_guid FROM item_test WHERE `source`='m');
+DROP TABLE IF EXISTS item_test;
diff --git a/sql/tools/characters_pet_data_cleanup.sql b/sql/tools/characters_pet_data_cleanup.sql
new file mode 100644
index 00000000000..f4454ca856f
--- /dev/null
+++ b/sql/tools/characters_pet_data_cleanup.sql
@@ -0,0 +1,3 @@
+DELETE FROM pet_aura WHERE guid NOT IN (SELECT id FROM character_pet);
+DELETE FROM pet_spell WHERE guid NOT IN (SELECT id FROM character_pet);
+DELETE FROM pet_spell_cooldown WHERE guid NOT IN (SELECT id FROM character_pet);