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:
2026-09-06 23:52:25 +02:00
parent 93892197ad
commit 87407fe604
40 changed files with 405 additions and 485 deletions
+10 -10
View File
@@ -6,7 +6,7 @@ const { DefaultError } = require("../errors/errors")
async function getUser(identifier, requirePassword = false) {
try {
const sql = `SELECT * FROM players WHERE uuid = ? OR email = ? OR username = ?`
const rows = await database.query(sql, [identifier, identifier, identifier])
const rows = await database.pool.query(sql, [identifier, identifier, identifier])
const user = rows[0]
if (!user) {
throw new DefaultError(404, "User not found")
@@ -28,7 +28,7 @@ async function register(email, username, password) {
const sql = `INSERT INTO players (email, username, password, uuid) VALUES (?, ?, ?, ?)`
const uuid = crypto.randomUUID()
const hashedPassword = await bcrypt.hash(password, 10)
const result = await database.query(sql, [email, username, hashedPassword, uuid])
const result = await database.pool.query(sql, [email, username, hashedPassword, uuid])
if (result.affectedRows > 0) {
return { code: 200, email, username, uuid }
} else {
@@ -42,7 +42,7 @@ async function register(email, username, password) {
async function insertClientSession(accessToken, clientToken, uuid) {
try {
const sql = `INSERT INTO clientSessions (accessToken, clientToken, uuid) VALUES (?, ?, ?)`
const result = await database.query(sql, [accessToken, clientToken, uuid])
const result = await database.pool.query(sql, [accessToken, clientToken, uuid])
if (result.affectedRows > 0) {
return { code: 204, accessToken, clientToken }
@@ -57,7 +57,7 @@ async function insertClientSession(accessToken, clientToken, uuid) {
async function getPlayerProperties(uuid) {
try {
const sql = `SELECT * FROM playersProperties WHERE uuid = ?`
const properties = await database.query(sql, [uuid])
const properties = await database.pool.query(sql, [uuid])
if (properties.length === 0) {
throw new DefaultError(404, "Properties not found for this user.", "InternalServerError")
@@ -71,7 +71,7 @@ async function getPlayerProperties(uuid) {
async function getClientSession(accessToken, clientToken) {
try {
const sql = `SELECT * FROM clientSessions WHERE accessToken = ? AND clientToken = ?`
const rows = await database.query(sql, [accessToken, clientToken])
const rows = await database.pool.query(sql, [accessToken, clientToken])
const session = rows[0]
if (session) {
@@ -90,7 +90,7 @@ async function getClientSession(accessToken, clientToken) {
async function validateClientSession(accessToken, clientToken) {
try {
const sql = `SELECT * FROM clientSessions WHERE accessToken = ? AND clientToken = ?`
const rows = await database.query(sql, [accessToken, clientToken])
const rows = await database.pool.query(sql, [accessToken, clientToken])
const session = rows[0]
if (session) {
@@ -109,7 +109,7 @@ async function validateClientSession(accessToken, clientToken) {
async function validateClientSessionWithoutClientToken(accessToken) {
try {
const sql = `SELECT * FROM clientSessions WHERE accessToken = ?`
const rows = await database.query(sql, [accessToken])
const rows = await database.pool.query(sql, [accessToken])
const session = rows[0]
if (session) {
@@ -128,7 +128,7 @@ async function validateClientSessionWithoutClientToken(accessToken) {
async function invalidateClientSession(accessToken, clientToken) {
try {
const sql = `DELETE FROM clientSessions WHERE accessToken = ? AND clientToken = ?`
const result = await database.query(sql, [accessToken, clientToken])
const result = await database.pool.query(sql, [accessToken, clientToken])
if (result.affectedRows > 0) {
return {
@@ -146,7 +146,7 @@ async function invalidateClientSession(accessToken, clientToken) {
async function revokeAccessTokens(uuid) {
try {
const sql = `DELETE FROM clientSessions WHERE uuid = ?`
const result = await database.query(sql, [uuid])
const result = await database.pool.query(sql, [uuid])
if (result.affectedRows > 0) {
return {
@@ -163,7 +163,7 @@ async function revokeAccessTokens(uuid) {
async function getUsernamesRules() {
try {
const rows = await database.query("SELECT rule, type FROM usernameRules")
const rows = await database.pool.query("SELECT rule, type FROM usernameRules")
return rows.map(row => {
if (row.type === 1) {
return { type: "regex", pattern: new RegExp(row.rule, "i") }