Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config/database): Added option to populate database when missing data #1180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/game/server/misc/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ export async function findOrGeneratePhoneNumber(identifier: string): Promise<str

playerLogger.debug(`Phone number generated > ${gennedNumber}`);

const updateQuery = `UPDATE ${config.database.playerTable} SET ${config.database.phoneNumberColumn} = ? WHERE ${config.database.identifierColumn} = ?`;
let dmlQuery: string | undefined = undefined;
if (config.database.addToTableWhenMissing && castRes.length === 0) {
playerLogger.debug(`Adding player to table`);
dmlQuery = `INSERT INTO ${config.database.playerTable} (${config.database.phoneNumberColumn}, ${config.database.identifierColumn}) VALUES (?, ?)`;
} else {
dmlQuery = `UPDATE ${config.database.playerTable} SET ${config.database.phoneNumberColumn} = ? WHERE ${config.database.identifierColumn} = ?`;
}



// Update profile with new generated number
const result = await DbInterface._rawExec(updateQuery, [gennedNumber, identifier]);
const result = await DbInterface._rawExec(dmlQuery, [gennedNumber, identifier]);

// Temporary bad typing, need to update dbInterface
if (!result || !result[0] || !(result[0] as ResultSetHeader).affectedRows) {
Expand Down
1 change: 1 addition & 0 deletions config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"payFunction": "myCheckerFunction"
},
"database": {
"addToTableWhenMissing": false,
"useIdentifierPrefix": false,
"playerTable": "users",
"identifierColumn": "identifier",
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"payFunction": "myCheckerFunction"
},
"database": {
"addToTableWhenMissing": false,
"useIdentifierPrefix": false,
"playerTable": "users",
"identifierColumn": "identifier",
Expand Down
1 change: 1 addition & 0 deletions typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface BankConfig {
}

interface DatabaseConfig {
addToTableWhenMissing: boolean;
playerTable: string;
identifierColumn: string;
identifierType: string;
Expand Down