Fügt eine neue Skriptfunktion zum Bereinigen von Benutzertoken hinzu und aktualisiert die Logik zum Synchronisieren des UserToken-Modells. Implementiert eine neue Controller-Methode zum Löschen von Datumsangaben für Clubs und passt die Routen entsprechend an. Ergänzt die Benutzeroberfläche in DiaryView.vue um die Möglichkeit, ein Datum zu löschen, und aktualisiert die Logik zur Überprüfung der Datumsaktualität.

This commit is contained in:
Torsten Schulz (local)
2025-09-01 09:33:54 +02:00
parent 51d3087006
commit f21ad3d8a3
8 changed files with 178 additions and 6 deletions

View File

@@ -0,0 +1,90 @@
import mysql from 'mysql2/promise';
import dotenv from 'dotenv';
dotenv.config();
const dbConfig = {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME || 'trainingdiary',
};
async function getIndexSummary(connection, table) {
const [rows] = await connection.execute(`SHOW INDEX FROM \`${table}\``);
const summary = rows.reduce((acc, r) => {
const key = r.Key_name;
acc[key] = acc[key] || { unique: r.Non_unique === 0, columns: [] };
acc[key].columns.push(r.Column_name);
return acc;
}, {});
return summary;
}
async function cleanupUserTokenKeys() {
let connection;
const table = 'UserToken';
try {
console.log('Connecting to DB:', dbConfig);
connection = await mysql.createConnection(dbConfig);
console.log(`\nBefore cleanup (indexes on ${table}):`);
let before = await getIndexSummary(connection, table);
Object.entries(before).forEach(([name, info]) => {
console.log(` - ${name} ${info.unique ? '(UNIQUE)' : ''} -> [${info.columns.join(', ')}]`);
});
// Drop all non-PRIMARY indexes on UserToken
const [indexes] = await connection.execute(`SHOW INDEX FROM \`${table}\``);
const keyNames = Array.from(new Set(indexes.map(i => i.Key_name))).filter(k => k !== 'PRIMARY');
for (const keyName of keyNames) {
try {
await connection.execute(`DROP INDEX \`${keyName}\` ON \`${table}\``);
console.log(`Dropped index: ${keyName}`);
} catch (err) {
console.warn(`Could not drop ${keyName}: ${err.code || err.message}`);
}
}
// Re-create minimal, deterministic indexes
// Unique on token (column is 'token')
try {
await connection.execute(`CREATE UNIQUE INDEX \`uniq_UserToken_token\` ON \`${table}\` (\`token\`)`);
console.log('Created UNIQUE index: uniq_UserToken_token (token)');
} catch (err) {
console.warn('Could not create uniq_UserToken_token:', err.code || err.message);
}
// Helpful index on user_id if column exists
try {
const [cols] = await connection.execute(`SHOW COLUMNS FROM \`${table}\` LIKE 'user_id'`);
if (cols && cols.length > 0) {
await connection.execute(`CREATE INDEX \`idx_UserToken_user_id\` ON \`${table}\` (\`user_id\`)`);
console.log('Created INDEX: idx_UserToken_user_id (user_id)');
} else {
console.log('Column user_id not found, skip creating idx_UserToken_user_id');
}
} catch (err) {
console.warn('Could not create idx_UserToken_user_id:', err.code || err.message);
}
console.log(`\nAfter cleanup (indexes on ${table}):`);
const after = await getIndexSummary(connection, table);
Object.entries(after).forEach(([name, info]) => {
console.log(` - ${name} ${info.unique ? '(UNIQUE)' : ''} -> [${info.columns.join(', ')}]`);
});
console.log('\nDone.');
} catch (err) {
console.error('Cleanup failed:', err);
process.exitCode = 1;
} finally {
if (connection) await connection.end();
}
}
cleanupUserTokenKeys();