Files
metin2-server/tools/player-deleted-sync/sync.sh
T
shenleiandClaude Opus 5.5 96f8486306 Five character slots (AVA2 ENABLE_PLAYER_PER_ACCOUNT5)
PLAYER_PER_ACCOUNT 5: player_index.pid5 in the login/empire/monarch
queries, char_change_empire sized by PLAYER_PER_ACCOUNT, slot check
relaxed; client gate mt20261029. tools/player-slots5 adds pid5.

tools/player-deleted-sync: PLAYER_DELETE copies with SELECT *, so
player_deleted must match player column for column; the conqueror
schema now adds its columns to player_deleted too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:33:51 +09:00

24 lines
1.5 KiB
Bash

#!/bin/sh
# db PLAYER_DELETE copies the row with INSERT INTO player_deleted SELECT * FROM player, so the two tables
# need the same columns in the same order. Appends the player columns player_deleted lacks (columns added
# to player by later schema changes, e.g. HEAD inventory_0..5/shopFlag, conqueror), then checks the order.
# sh sync.sh <player db> e.g. sh sync.sh player_sb
set -e
DB=${1:?player db}
Q="mysql -uroot -N $DB -e"
ALTER=$($Q "SELECT GROUP_CONCAT(CONCAT('ADD COLUMN \`', column_name, '\` ', column_type,
IF(is_nullable='NO', ' NOT NULL', ' NULL'),
IF(column_default IS NULL, '', CONCAT(' DEFAULT ', QUOTE(column_default))))
ORDER BY ordinal_position SEPARATOR ', ')
FROM information_schema.COLUMNS p WHERE table_schema=DATABASE() AND table_name='player'
AND column_name NOT IN (SELECT column_name FROM information_schema.COLUMNS WHERE table_schema=DATABASE() AND table_name='player_deleted')")
if [ "$ALTER" != NULL ]; then
echo "ALTER TABLE player_deleted $ALTER"
$Q "ALTER TABLE player_deleted $ALTER"
fi
BAD=$($Q "SELECT COUNT(*) FROM information_schema.COLUMNS p LEFT JOIN information_schema.COLUMNS d
ON d.table_schema=p.table_schema AND d.table_name='player_deleted' AND d.ordinal_position=p.ordinal_position
WHERE p.table_schema=DATABASE() AND p.table_name='player' AND (d.column_name IS NULL OR d.column_name<>p.column_name)")
[ "$BAD" = 0 ] || { echo "player_deleted column order differs from player in $BAD places" >&2; exit 1; }
echo "player_deleted matches player"