Add DDL-based DB init and bootstrap
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.
This commit is contained in:
@@ -4,10 +4,10 @@ const { DefaultError } = require("../errors/errors")
|
||||
|
||||
async function insertLegacyClientSessions(sessionId, uuid) {
|
||||
try {
|
||||
await database.query(`DELETE FROM legacyClientSessions WHERE uuid = ?`, [uuid])
|
||||
await database.pool.query(`DELETE FROM legacyClientSessions WHERE uuid = ?`, [uuid])
|
||||
|
||||
const sql = `INSERT INTO legacyClientSessions (sessionId, uuid) VALUES (?, ?)`
|
||||
const result = await database.query(sql, [sessionId, uuid])
|
||||
const result = await database.pool.query(sql, [sessionId, uuid])
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return { code: 200, sessionId, uuid }
|
||||
@@ -22,7 +22,7 @@ async function insertLegacyClientSessions(sessionId, uuid) {
|
||||
async function validateLegacyClientSession(sessionId, uuid) {
|
||||
try {
|
||||
const sql = `SELECT * FROM legacyClientSessions WHERE sessionId = ? AND uuid = ?`
|
||||
const rows = await database.query(sql, [sessionId, uuid])
|
||||
const rows = await database.pool.query(sql, [sessionId, uuid])
|
||||
|
||||
const session = rows[0]
|
||||
if (session) {
|
||||
@@ -44,7 +44,7 @@ async function validateLegacyClientSession(sessionId, uuid) {
|
||||
async function getBlockedServers() {
|
||||
try {
|
||||
const sql = `SELECT * FROM blockedServers`
|
||||
const blockedServers = await database.query(sql)
|
||||
const blockedServers = await database.pool.query(sql)
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
@@ -63,7 +63,7 @@ async function getActiveSkin(uuid) {
|
||||
JOIN textures t ON ps.assetHash = t.hash
|
||||
WHERE ps.playerUuid = ? AND ps.isSelected = 1
|
||||
`
|
||||
const rows = await database.query(sql, [uuid])
|
||||
const rows = await database.pool.query(sql, [uuid])
|
||||
const skin = rows[0]
|
||||
if (!skin) {
|
||||
throw new DefaultError(404, "Not found", "Not found")
|
||||
@@ -82,7 +82,7 @@ async function getActiveCape(uuid) {
|
||||
JOIN textures t ON pc.assetHash = t.hash
|
||||
WHERE pc.playerUuid = ? AND pc.isSelected = 1
|
||||
`
|
||||
const rows = await database.query(sql, [uuid])
|
||||
const rows = await database.pool.query(sql, [uuid])
|
||||
const cape = rows[0]
|
||||
if (!cape) {
|
||||
throw new DefaultError(404, "Not found", "Not found")
|
||||
@@ -97,7 +97,7 @@ async function getProfileActionsList(uuid) {
|
||||
try {
|
||||
const cleanUuid = uuid.replace(/-/g, "")
|
||||
const sql = "SELECT action FROM playerProfileActions WHERE uuid = ?"
|
||||
const rows = await database.query(sql, [cleanUuid])
|
||||
const rows = await database.pool.query(sql, [cleanUuid])
|
||||
|
||||
const actions = rows.map(row => row.action)
|
||||
|
||||
@@ -118,7 +118,7 @@ async function saveServerSession(uuid, accessToken, serverId, ip) {
|
||||
ip = VALUES(ip),
|
||||
createdAt = CURRENT_TIMESTAMP
|
||||
`
|
||||
const result = await database.query(sql, [uuid, accessToken, serverId, ip])
|
||||
const result = await database.pool.query(sql, [uuid, accessToken, serverId, ip])
|
||||
|
||||
return { code: 200, success: result.affectedRows > 0 }
|
||||
} catch (error) {
|
||||
@@ -134,7 +134,7 @@ async function getServerSession(uuid, serverId) {
|
||||
WHERE uuid = ? AND serverId = ?
|
||||
AND createdAt > (NOW() - INTERVAL 30 SECOND)
|
||||
`
|
||||
const rows = await database.query(sql, [uuid, serverId])
|
||||
const rows = await database.pool.query(sql, [uuid, serverId])
|
||||
const session = rows[0]
|
||||
|
||||
if (!session) {
|
||||
|
||||
Reference in New Issue
Block a user