62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
import PromotionalGift from '../models/falukant/type/promotional_gift.js';
|
|
import { sequelize } from '../utils/sequelize.js';
|
|
|
|
// Mapping basierend auf initializeFalukantTypes.js
|
|
const seedValues = {
|
|
'Gold Coin': 100,
|
|
'Silk Scarf': 50,
|
|
'Exotic Perfume': 200,
|
|
'Crystal Pendant': 150,
|
|
'Leather Journal': 75,
|
|
'Fine Wine': 120,
|
|
'Artisan Chocolate': 40,
|
|
'Pearl Necklace': 300,
|
|
'Rare Painting': 500,
|
|
'Silver Watch': 250,
|
|
'Cat': 70,
|
|
'Dog': 150,
|
|
'Horse': 1000
|
|
};
|
|
|
|
async function repair() {
|
|
console.log('Repair promotional_gift values - starting');
|
|
try {
|
|
await sequelize.authenticate();
|
|
console.log('DB connection ok');
|
|
|
|
// Liste aller problematischen Einträge
|
|
const [rows] = await sequelize.query("SELECT id, name, value FROM falukant_type.promotional_gift WHERE value IS NULL OR value <= 0");
|
|
if (!rows.length) {
|
|
console.log('No invalid promotional_gift rows found. Nothing to do.');
|
|
return process.exit(0);
|
|
}
|
|
|
|
console.log(`Found ${rows.length} invalid promotional_gift rows:`);
|
|
for (const r of rows) console.log(` id=${r.id} name='${r.name}' value=${r.value}`);
|
|
|
|
// Update rows where we have a seed mapping
|
|
let updated = 0;
|
|
for (const r of rows) {
|
|
const seed = seedValues[r.name];
|
|
if (seed && Number(seed) > 0) {
|
|
await PromotionalGift.update({ value: seed }, { where: { id: r.id } });
|
|
console.log(` updated id=${r.id} name='${r.name}' -> value=${seed}`);
|
|
updated++;
|
|
} else {
|
|
console.warn(` no seed value for id=${r.id} name='${r.name}' - skipping`);
|
|
}
|
|
}
|
|
|
|
console.log(`Done. Updated ${updated} rows. Remaining invalid: `);
|
|
const [left] = await sequelize.query("SELECT id, name, value FROM falukant_type.promotional_gift WHERE value IS NULL OR value <= 0");
|
|
for (const l of left) console.log(` id=${l.id} name='${l.name}' value=${l.value}`);
|
|
console.log('If any remain, inspect and adjust manually.');
|
|
process.exit(0);
|
|
} catch (err) {
|
|
console.error('Repair failed:', err);
|
|
process.exit(2);
|
|
}
|
|
}
|
|
|
|
repair();
|