mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
On a database NexusDashboard (or a server's own changes) already migrated, 29, 30 and 40 logged an error for every column that was already there, and 40 and 57 added a second index on columns MariaDB had already indexed for the inline REFERENCES foreign keys of 0_initial.sql. Add those columns and indexes only when information_schema says they are missing. 40 also gives pet_names.owner_id values written before 23_store_character_id_as_objectid.sql the persistent bit, as 23 did for every other character id column, so they match characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 lines
1.4 KiB
SQL
18 lines
1.4 KiB
SQL
/* Who owns each named pet, written by the game when the name is set. NULL: not looked up yet (the dashboard fills
|
|
those in once from the characters' inventories); 0: no character has the pet any more. */
|
|
SET @dlu_column = (SELECT IF(COUNT(*) = 0, 'ALTER TABLE pet_names ADD COLUMN owner_id BIGINT NULL DEFAULT NULL', 'DO 0') FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'pet_names' AND column_name = 'owner_id');
|
|
PREPARE dlu_column_stmt FROM @dlu_column;
|
|
EXECUTE dlu_column_stmt;
|
|
DEALLOCATE PREPARE dlu_column_stmt;
|
|
/* Some servers added this column (and an index on it) themselves: only index it when nothing does yet */
|
|
SET @dlu_index = (SELECT IF(COUNT(*) = 0, 'CREATE INDEX pet_names_owner ON pet_names (owner_id)', 'DO 0') FROM information_schema.statistics
|
|
WHERE table_schema = DATABASE() AND table_name = 'pet_names' AND column_name = 'owner_id' AND seq_in_index = 1);
|
|
PREPARE dlu_index_stmt FROM @dlu_index;
|
|
EXECUTE dlu_index_stmt;
|
|
DEALLOCATE PREPARE dlu_index_stmt;
|
|
/* Those servers' character ids written before 23_store_character_id_as_objectid.sql, which did not convert this
|
|
column, have no persistent bit and match no character. Give them the bit, as 23 did for every other character id
|
|
column. Does nothing on a column just added (every row is NULL). */
|
|
UPDATE pet_names SET owner_id = owner_id | 0x1000000000000000 WHERE owner_id > 0 AND owner_id < 0x1000000000000000;
|