Skip to content

Database Setup & Migrations

How the four databases are created and how schema changes ship with the core.


The Four Databases

Database Schema source Purpose
realmd sql/logon.sql Accounts, realms (docs)
characters sql/characters.sql Player state (docs)
mangos (world) full dump + sql/migrations Game content (docs)
logs sql/logs.sql Audit logs (docs)

Getting the World Database

The world database ships as one complete dump. You have two options:

  1. Dump + migrations - import the base dump, then apply the files from sql/migrations in chronological order (see Migration System).
  2. Pre-applied release - download a full database build with all migrations already applied; just import and go.

Either way the schema matches what this wiki documents. For the client-side data folders (maps/, vmaps/, mmaps/, DBCs) use the extraction tools described in Maps & Pathfinding.


Migration System

Schema and data changes ship as timestamped SQL files in sql/migrations:

20210515110157_world.sql
20210615223353_world.sql
…
<timestamp>_characters.sql
<timestamp>_logon.sql
<timestamp>_logs.sql

Each file wraps its changes in an add_migration() stored procedure that inserts the migration ID into the target database's migrations table only if it has not been applied yet, making the files safely re-runnable:

DROP PROCEDURE IF EXISTS add_migration;
DELIMITER ??
CREATE PROCEDURE `add_migration`()
BEGIN
DECLARE v INT DEFAULT 1;
SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20210515110157');
IF v = 0 THEN
INSERT INTO `migrations` VALUES ('20210515110157');
-- Add your query below.
...
-- End of migration.
END IF;
END??
DELIMITER ;
CALL add_migration();
DROP PROCEDURE IF EXISTS add_migration;

Each database keeps its own applied-ID list: migrations in the characters DB, plus equivalents in realmd, logs and world.

Creating a New Migration

Two helpers live in sql/:

  • make_migration.py - writes migrations/<UTC-timestamp>_world.sql pre-filled with the wrapper.
  • touch_migration.sh - bash equivalent of the above (also writes world migrations).

Workflow for contributors:

  1. Run the helper to create the file.
  2. Put your SQL between the marked comments.
  3. Name every table with its schema prefix if ambiguous and keep statements idempotent where possible.
  4. Submit with your pull request - never edit older migrations.

Applying Migrations

Migrations are plain SQL files; apply them with any client in chronological order:

mysql -u mangos -p mangos < sql/migrations/20210515110157_world.sql

The server also checks the migrations table at startup and reports any required migrations that have not been applied yet.


Verifying Your Setup

  • Table counts per schema should match the documentation indexes: world, characters, realmd, logs.
  • Watch the server log at startup for LOG_DBERROR messages - they call out missing loot ids, invalid conditions and other data problems (see the individual table pages).