- Implemented `validatePlayer` and `normalizeTabInfo` functions in `database/validate.js` for player data validation and normalization. - Added error handling for required fields and enforced data types and constraints. - Introduced standardization for characteristics and skills. feat: Create script for extracting rules from PDF files - Developed `extract-rules.js` to extract text from PDF rulebooks and categorize rules. - Integrated `pdftotext` for PDF processing and created a searchable rules database. - Implemented rule categorization and indexing for efficient searching. feat: Implement RulesTab component for rule searching - Created `RulesTab.jsx` for searching and displaying rules with filtering options. - Added recent searches and quick reference buttons for user convenience. - Integrated API calls for fetching rules and displaying results dynamically. feat: Add test script for Rules API - Created `test-rules.js` to test the functionality of the Rules API endpoints. - Included tests for search and stats endpoints to ensure proper response handling.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const { playerHelpers } = require('../sqlite-db');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function backupDb() {
|
|
const ts = new Date().toISOString().replace(/[:.]/g,'');
|
|
const src = path.join(__dirname, '..', 'sqlite', 'deathwatch.db');
|
|
const dst = path.join(__dirname, '..', 'sqlite', `deathwatch.db.pre_delete_tests.${ts}.bak`);
|
|
if (fs.existsSync(src)) {
|
|
fs.copyFileSync(src, dst);
|
|
console.log('Backup created:', dst);
|
|
return dst;
|
|
}
|
|
console.log('No sqlite DB found at', src);
|
|
return null;
|
|
}
|
|
|
|
function isTestName(name) {
|
|
if (!name) return false;
|
|
return /test|dummy|sample|example|dev/i.test(name);
|
|
}
|
|
|
|
function run() {
|
|
const backup = backupDb();
|
|
const players = playerHelpers.getAll();
|
|
const toDelete = players.filter(p => isTestName(p.name));
|
|
console.log('Found', toDelete.length, 'test-like players');
|
|
const deleted = [];
|
|
for (const p of toDelete) {
|
|
try {
|
|
const ok = playerHelpers.delete(p.name);
|
|
if (ok) deleted.push(p.name);
|
|
} catch (err) {
|
|
console.error('Failed to delete', p.name, err);
|
|
}
|
|
}
|
|
console.log('Deleted', deleted.length, 'players');
|
|
if (backup) console.log('DB backup at', backup);
|
|
if (deleted.length) console.log('Deleted names:', deleted.join(', '));
|
|
}
|
|
|
|
run();
|