From d83e4cb9a5d12230a1d255dcd2c9f167c5cc4751 Mon Sep 17 00:00:00 2001 From: gumi Date: Fri, 27 Mar 2020 23:31:00 -0400 Subject: set the vault account id in an account variable --- src/routers/vault/index.js | 3 +- src/routers/vault/middlewares/evol/account.js | 7 +++++ src/routers/vault/middlewares/legacy/account.js | 18 ++++++++++-- src/routers/vault/models/evol/char_reg_num_db.js | 33 ++++++++++++++++++++++ .../vault/models/evol/global_acc_reg_num_db.js | 33 ++++++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 src/routers/vault/models/evol/char_reg_num_db.js create mode 100644 src/routers/vault/models/evol/global_acc_reg_num_db.js diff --git a/src/routers/vault/index.js b/src/routers/vault/index.js index c0bc788..c20e2d2 100644 --- a/src/routers/vault/index.js +++ b/src/routers/vault/index.js @@ -26,6 +26,8 @@ const models = { "login", "char", "char_reservation", + "global_acc_reg_num_db", + "char_reg_num_db", ], }; @@ -111,7 +113,6 @@ module.exports = exports = class Vault { await this.sequelize.vault.sync({alter: {drop: false}}); // update SQL tables - this.api.locals.sequelize = this.sequelize; // for access to sequelize.fn console.info("Vault: database ready"); return Promise.resolve(true); diff --git a/src/routers/vault/middlewares/evol/account.js b/src/routers/vault/middlewares/evol/account.js index a889462..fd6fce9 100644 --- a/src/routers/vault/middlewares/evol/account.js +++ b/src/routers/vault/middlewares/evol/account.js @@ -58,6 +58,13 @@ const new_account = async (req, res, next) => { email: `${session.vault}@vault`, // setting an actual email is pointless }); + // store the vault account id as a global account var + await req.app.locals.evol.global_acc_reg_num_db.create({ + accountId: evol_acc.accountId, + key: "##VAULT", index: 0, + value: session.vault, + }); + req.app.locals.vault.account_log.create({ vaultId: session.vault, accountType: "EVOL", diff --git a/src/routers/vault/middlewares/legacy/account.js b/src/routers/vault/middlewares/legacy/account.js index 50874ed..8a541f5 100644 --- a/src/routers/vault/middlewares/legacy/account.js +++ b/src/routers/vault/middlewares/legacy/account.js @@ -225,6 +225,13 @@ const migrate = async (req, res, next) => { email: `${session.vault}@vault`, // setting an actual email is pointless }); + // store the vault account id as a global account var + await req.app.locals.evol.global_acc_reg_num_db.create({ + accountId: evol_acc.accountId, + key: "##VAULT", index: 0, + value: session.vault, + }); + req.app.locals.vault.migration_log.create({ vaultId: session.vault, legacyId: legacy.accountId, @@ -238,8 +245,6 @@ const migrate = async (req, res, next) => { vaultId: session.vault, }); - // TODO: set an account variable with the original legacy account id - const evol_account = new EvolAccount(evol_acc.accountId, evol_acc.userid); evol_account.legacyId = legacy.accountId; evol_account.legacyAccount = legacy; @@ -277,7 +282,14 @@ const migrate = async (req, res, next) => { continue; } - // TODO: set a variable in the char with the original legacy char id + // update the Legacy flags: + // for now we're only using a single bit but this can be expanded when + // we need it in the future + await req.app.locals.evol.char_reg_num_db.create({ + charId: evol_char.charId, + key: "LEGACY", index: 0, + value: 0b00000000_00000000_00000000_00000001, // set the Legacy bit + }); // remove the name reservation req.app.locals.evol.char_reservation.destroy({ diff --git a/src/routers/vault/models/evol/char_reg_num_db.js b/src/routers/vault/models/evol/char_reg_num_db.js new file mode 100644 index 0000000..a38df42 --- /dev/null +++ b/src/routers/vault/models/evol/char_reg_num_db.js @@ -0,0 +1,33 @@ +const { DataTypes } = require("sequelize"); // from npm registry + +module.exports = { + fields: { + charId: { + type: DataTypes.INTEGER.UNSIGNED, + primaryKey: true, + allowNull: false, + }, + key: { + type: DataTypes.STRING.BINARY, + primaryKey: true, + allowNull: false, + }, + index: { + type: DataTypes.INTEGER.UNSIGNED, + primaryKey: true, + allowNull: false, + defaultValue: 0, + }, + value: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, + }, + }, + options: { + engine: "InnoDB", + indexes: [ + { fields: ["char_id"] }, + ], + } +}; diff --git a/src/routers/vault/models/evol/global_acc_reg_num_db.js b/src/routers/vault/models/evol/global_acc_reg_num_db.js new file mode 100644 index 0000000..2a77fdd --- /dev/null +++ b/src/routers/vault/models/evol/global_acc_reg_num_db.js @@ -0,0 +1,33 @@ +const { DataTypes } = require("sequelize"); // from npm registry + +module.exports = { + fields: { + accountId: { + type: DataTypes.INTEGER.UNSIGNED, + primaryKey: true, + allowNull: false, + }, + key: { + type: DataTypes.STRING.BINARY, + primaryKey: true, + allowNull: false, + }, + index: { + type: DataTypes.INTEGER.UNSIGNED, + primaryKey: true, + allowNull: false, + defaultValue: 0, + }, + value: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, + }, + }, + options: { + engine: "InnoDB", + indexes: [ + { fields: ["account_id"] }, + ], + } +}; -- cgit v1.2.3-60-g2f50