Add bootstrap entrypoint and migrate DB schema setup to SQL files. Introduces bootstrap.js, many data/ddl/*.sql files, and a new runDDL() in modules/database.js (exports pool and runDDL). Remove legacy modules/databaseGlobals.js. Update repositories and code to use database.pool.query calls. Bump package version and set main to bootstrap.js. Clean up server.js to remove inline DB/cert init (now handled by bootstrap). Overall: refactor DB initialization to run ordered SQL DDL files and centralize startup logic.
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
const utils = require("../modules/utils")
|
|
const database = require("../modules/database")
|
|
|
|
async function createLinkAttempt(OAuth2LinkId, playerUuid) {
|
|
try {
|
|
const sql = `
|
|
INSERT INTO oaauth2LinkAttempts (OAuth2LinkId, playerUuid)
|
|
VALUES (?, ?)
|
|
ON DUPLICATE KEY UPDATE playerUuid = VALUES(playerUuid), createdAt = NOW()
|
|
`
|
|
const result = await database.pool.query(sql, [OAuth2LinkId, playerUuid])
|
|
return result.affectedRows > 0
|
|
} catch (error) {
|
|
return utils.handleDBError(error)
|
|
}
|
|
}
|
|
|
|
async function popLinkAttempt(OAuth2LinkId) {
|
|
try {
|
|
const selectSql = "SELECT playerUuid FROM oaauth2LinkAttempts WHERE OAuth2LinkId = ?"
|
|
const rows = await database.pool.query(selectSql, [OAuth2LinkId])
|
|
|
|
if (rows.length === 0) return null
|
|
|
|
const playerUuid = rows[0].playerUuid
|
|
|
|
const deleteSql = "DELETE FROM oaauth2LinkAttempts WHERE OAuth2LinkId = ?"
|
|
await database.pool.query(deleteSql, [OAuth2LinkId])
|
|
|
|
return playerUuid
|
|
} catch (error) {
|
|
return utils.handleDBError(error)
|
|
}
|
|
}
|
|
|
|
async function unlinkProviderAccount(provider, playerUuid) {
|
|
try {
|
|
const sql = `DELETE FROM playersProperties WHERE name = '${provider}Id' AND uuid = ?`
|
|
const result = await database.pool.query(sql, [playerUuid])
|
|
|
|
return result.affectedRows > 0
|
|
} catch (error) {
|
|
return utils.handleDBError(error)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
popLinkAttempt,
|
|
createLinkAttempt,
|
|
unlinkProviderAccount
|
|
} |