5.5 KiB
5.5 KiB
Database Schema Migration - Players Tab Fix
Summary
Fixed all database queries in the web-map editor to use the correct accounts + characters schema instead of the deprecated players table.
Schema Changes
Old Schema (Deprecated)
playerstable withtelegram_idas primary key- Columns:
intelligence,weight_capacity,volume_capacity accountstable withis_banned,ban_reason,premium_until
New Schema (Current)
accountstable:id,email,premium_expires_at,created_atcharacterstable:id,account_id(FK),name,level,xp,hp,stamina,strength,agility,endurance,intellect,unspent_points,location_id,is_deadinventorytable:character_id(FK),item_id,quantity,is_equipped,unique_item_id(FK to unique_items)unique_itemstable:id,item_id,durability,max_durability,tier,unique_stats
Files Modified
1. /opt/dockers/echoes_of_the_ashes/web-map/server.py
Changes:
- ✅ Changed import from
bot.databasetoapi.database - ✅ Updated all SQL queries to use
charactersandaccountstables - ✅ Changed column names:
telegram_id→id(character ID)intelligence→intellectpremium_until→premium_expires_atcharacter_name→name
- ✅ Updated API endpoints:
/api/editor/player/<int:telegram_id>→/api/editor/player/<int:character_id>/api/editor/account/<int:telegram_id>→/api/editor/account/<int:account_id>
- ✅ Fixed inventory queries to use
character_idand join withunique_itemstable - ✅ Updated player count query for live stats (line 1080)
- ✅ Fixed delete account to use CASCADE (accounts → characters → inventory)
- ✅ Updated reset player to use correct default values
Endpoints Fixed:
GET /api/editor/players- List all characters with account infoGET /api/editor/player/<character_id>- Get character details + inventoryPOST /api/editor/player/<character_id>- Update character statsPOST /api/editor/player/<character_id>/inventory- Update inventoryPOST /api/editor/player/<character_id>/equipment- Update equipmentDELETE /api/editor/account/<account_id>/delete- Delete accountPOST /api/editor/player/<character_id>/reset- Reset character
2. /opt/dockers/echoes_of_the_ashes/web-map/editor_enhanced.js
Changes:
- ✅ Updated
renderPlayerList()to useplayer.idinstead ofplayer.telegram_id - ✅ Changed dataset attribute:
dataset.telegramId→dataset.characterId - ✅ Updated
selectPlayer()function parameter and API call - ✅ Fixed player editor display to show:
- Character ID instead of Telegram ID
- Account email
- Correct timestamp handling (character_created_at * 1000)
- ✅ Updated action buttons to use correct IDs:
- Ban/Unban: uses
account_id - Reset: uses character
id - Delete: uses
account_id
- Ban/Unban: uses
- ✅ Fixed
deletePlayer()to find player byaccount_id - ✅ Updated status badge logic to use
is_premiumboolean
Testing Checklist
Backend Tests
- Start containers:
docker compose up -d - Check logs:
docker logs echoes_of_the_ashes_map - Test API endpoints:
# Login first curl -X POST http://localhost:8080/api/login \ -H "Content-Type: application/json" \ -d '{"password":"admin123"}' \ -c cookies.txt # Get players list curl http://localhost:8080/api/editor/players -b cookies.txt # Get specific player (replace 1 with actual character ID) curl http://localhost:8080/api/editor/player/1 -b cookies.txt
Frontend Tests
- Navigate to
http://localhost:8080/editor - Login with password (default:
admin123) - Click "👥 Players" tab
- Verify:
- Player list loads correctly
- Search by name works
- Filter by status (All/Active/Banned/Premium) works
- Clicking a player loads their details
- Character stats display correctly
- Inventory shows (read-only)
- Equipment shows (read-only)
- Account info displays (email, premium status)
- Test actions:
- Edit character stats and save
- Reset player (confirm it clears inventory)
- Delete account (confirm double-confirmation)
Known Limitations
-
Ban functionality: Accounts table doesn't have
is_bannedorban_reasoncolumns in new schema- Ban/Unban buttons will return "not implemented" message
- Need to add these columns to accounts table if ban feature is needed
-
Inventory editing: Currently read-only display
- Full CRUD for inventory would require more complex UI
- Unique items support needs proper unique_items table integration
-
Equipment slots: New schema uses
is_equippedflag in inventory- No separate
equipped_itemstable - Equipment is just inventory items with
is_equipped=true
- No separate
Rebuild Instructions
# Rebuild map container with fixes
docker compose build echoes_of_the_ashes_map
# Restart container
docker compose up -d echoes_of_the_ashes_map
# Check logs
docker logs -f echoes_of_the_ashes_map
Rollback Plan
If issues occur:
# Restore from container (files are already synced)
./sync_from_containers.sh
# Or restore from git
git checkout web-map/server.py web-map/editor_enhanced.js
Additional Notes
- All changes are backward compatible with existing data
- No database migrations needed (schema already exists)
- Frontend gracefully handles missing data (email, premium status)
- Timestamps are handled correctly (Unix timestamps in DB, converted to Date objects in JS)