From ad3b62dd9c4e7744c1dcd3b14cc1fa2f017c60e3 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Wed, 28 Sep 2022 18:46:36 -0400 Subject: [PATCH] Added NEX account migration script --- .../migration.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 migrations/add-console-type-to-nex-account/migration.js diff --git a/migrations/add-console-type-to-nex-account/migration.js b/migrations/add-console-type-to-nex-account/migration.js new file mode 100644 index 0000000..af581b4 --- /dev/null +++ b/migrations/add-console-type-to-nex-account/migration.js @@ -0,0 +1,32 @@ +const database = require('../../src/database'); +const { NEXAccount } = require('../../src/models/nex-account'); + +database.connect().then(async function () { + const nexAccounts = await NEXAccount.find({}); + const nexAccounts3DS = await NEXAccount.find({ device_type: '3ds' }); + const nexAccountsWiiU = await NEXAccount.find({ device_type: 'wiiu' }); + + console.log('NEX accounts:', nexAccounts.length); + console.log('NEX accounts (3DS):', nexAccounts3DS.length); + console.log('NEX accounts (WiiU):', nexAccountsWiiU.length); + + for (const nexAccount of nexAccounts) { + let deviceType = ''; + + if (nexAccount.owning_pid !== nexAccount.pid) { + // 3DS account + deviceType = '3ds'; + } else { + // WiiU account + deviceType = 'wiiu'; + } + + nexAccount.device_type = deviceType; + + await nexAccount.save(); + } + + console.log('Migrated accounts'); + + process.exit(0); +}); \ No newline at end of file