Skip to content

Commit 616fcfe

Browse files
committed
roms: Add type and system prop, and migration script.
1 parent d1c6e0f commit 616fcfe

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/app/roms/rom.document.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface RomDocument extends GameReferenceDocument, PrettyIdDocument, Fi
3030
bytes: number;
3131
crc: number;
3232
modified_at: Date;
33+
type?: string;
34+
system?: string;
3335
}>;
3436
version: string;
3537
languages: string[];

src/app/roms/rom.schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const romFields = {
4444
bytes: { type: Number },
4545
crc: { type: Number },
4646
modified_at: { type: Date },
47+
type: { type: String },
48+
system: { type: String },
4749
}],
4850
version: { type: String },
4951
languages: { type: [String] },
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* VPDB - Virtual Pinball Database
3+
* Copyright (C) 2019 freezy <[email protected]>
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License
7+
* as published by the Free Software Foundation; either version 2
8+
* of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
import { logger } from '../../app/common/logger';
21+
import { state } from '../../app/state';
22+
import { apiCache } from '../../app/common/api.cache';
23+
24+
/**
25+
* Updates most ROM files with the type, so we know which is the main ROM,
26+
* which is the sound ROM etc.
27+
*
28+
* @see https://github.com/vpdb/vpx-js/issues/130
29+
*/
30+
export async function up() {
31+
32+
// read the parsed types
33+
const romTypes = require('../../../data/rom-types.json');
34+
35+
// fetch all roms
36+
const roms = await state.models.Rom.find({}).exec();
37+
logger.info(null, '[migrate-23] Updating %s ROMs with file types...', roms.length);
38+
39+
// loop through roms and rom files
40+
let count = 0;
41+
for (const rom of roms) {
42+
if (!romTypes[rom.id]) {
43+
continue;
44+
}
45+
for (const romFile of rom.rom_files) {
46+
const romType = romTypes[rom.id][romFile.filename.toLowerCase()];
47+
if (!romType) {
48+
continue;
49+
}
50+
51+
// update with new data
52+
romFile.type = romType.type;
53+
if (romType.romType) {
54+
romFile.system = romType.romType;
55+
}
56+
count++;
57+
}
58+
await rom.save();
59+
}
60+
logger.info(null, '[migrate-23] Updated %s ROM files!', count);
61+
62+
// clear all caches
63+
await apiCache.invalidateAll();
64+
logger.info(null, '[migrate-23] Cache invalidated.');
65+
}

0 commit comments

Comments
 (0)