Files
dwroller/database/migrate-inventory-to-gear.js
Alex d84ca39e61 refactor: Migrate database from SQLite to MariaDB
Database Migration:
- Add MariaDB connection configuration and initialization (mariadb.js)
- Create MariaDB schema update script (mariadb-schema-update.sql)
- Add migration scripts for SQLite to MariaDB transition:
  * migrate-sqlite-to-mariadb.js: Main migration script
  * migrate-inventory-to-gear.js: Inventory schema migration
- Remove SQLite-specific implementation files and databases

Route Updates:
- Update all route handlers to use MariaDB instead of SQLite
- Migrate routes: playerRoutes, sessionRoutes, shopRoutes, bestiaryRoutes, rulesRoutes, rulesStagingRoutes, weaponsRoutes
- Remove SQLite-specific route files (playerRoutes-sqlite.js, sessionRoutes-sqlite.js)
- Update server.js to initialize MariaDB and register new weapon routes

Backend Scripts:
- Remove old SQLite migration scripts (migrate-to-sqlite.js, server-sqlite.js)
- Delete obsolete database utility scripts from backup-scripts/

Frontend Updates:
- Update logger utility for improved error handling and debugging
- Enhance PlayerManagement component with better state management
- Improve RequisitionShop component for MariaDB integration
- Update DeathwatchRoller with performance improvements
- Add login test suite (login.test.js)
- Add XP progression utility (xpProgression.js)
- Update dependencies in package.json and package-lock.json

This migration improves:
- Database scalability and performance
- Transaction support for complex operations
- Better data integrity and ACID compliance
- Simplified deployment and backup procedures
2025-12-11 19:20:44 +01:00

57 lines
1.8 KiB
JavaScript

const { playerHelpers } = require('./mariadb');
async function migrateInventoryToGear() {
try {
console.log('Starting inventory to gear migration...');
const players = await playerHelpers.getAll();
for (const player of players) {
if (player.tabInfo && player.tabInfo.inventory && player.tabInfo.inventory.length > 0) {
console.log(`Migrating inventory for ${player.name}...`);
const updatedTabInfo = { ...player.tabInfo };
// Initialize gear if it doesn't exist
if (!updatedTabInfo.gear) {
updatedTabInfo.gear = [];
}
// Move inventory items to gear
for (const invItem of updatedTabInfo.inventory) {
const gearItem = {
name: invItem.name,
qty: invItem.count || invItem.quantity || 1
};
// Check if item already exists in gear
const existingGearIndex = updatedTabInfo.gear.findIndex(g => g.name === gearItem.name);
if (existingGearIndex >= 0) {
// Update existing item quantity
updatedTabInfo.gear[existingGearIndex].qty += gearItem.qty;
} else {
// Add new item to gear
updatedTabInfo.gear.push(gearItem);
}
}
// Clear inventory since we moved everything to gear
updatedTabInfo.inventory = [];
// Update player
await playerHelpers.update(player.name, { ...player, tabInfo: updatedTabInfo });
console.log(` Moved ${player.tabInfo.inventory.length} items to gear`);
}
}
console.log('Migration completed!');
} catch (error) {
console.error('Migration failed:', error);
}
process.exit(0);
}
migrateInventoryToGear();