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
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { stagingHelpers, rulesHelpers, logToFile } = require('../mariadb');
|
|
|
|
// List staged sanitized rules
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const rows = await stagingHelpers.getAll();
|
|
res.json(rows);
|
|
} catch (e) {
|
|
logToFile('staging:list:error', e && e.message);
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
// Approve staged rules: insert into rules table (appends) and clear staging
|
|
router.post('/approve', async (req, res) => {
|
|
try {
|
|
const rows = await stagingHelpers.getAll();
|
|
let inserted = 0;
|
|
|
|
for (const rule of rows) {
|
|
const ruleData = {
|
|
title: rule.title || '',
|
|
content: rule.content || '',
|
|
page_num: rule.page || '',
|
|
source: 'sanitized',
|
|
source_abbr: 'SAN',
|
|
category: rule.category || null,
|
|
rulebook: 'staging'
|
|
};
|
|
|
|
const result = await rulesHelpers.create(ruleData);
|
|
if (result) {
|
|
inserted++;
|
|
await stagingHelpers.delete(rule.id);
|
|
}
|
|
}
|
|
|
|
res.json({ success: true, inserted });
|
|
} catch (e) {
|
|
logToFile('staging:approve:error', e && e.stack ? e.stack : e);
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
// Clear staging without approving
|
|
router.delete('/', async (req, res) => {
|
|
try {
|
|
const rows = await stagingHelpers.getAll();
|
|
for (const rule of rows) {
|
|
await stagingHelpers.delete(rule.id);
|
|
}
|
|
res.json({ success: true });
|
|
} catch (e) {
|
|
logToFile('staging:clear:error', e && e.message);
|
|
res.status(500).json({ error: e.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|