gfsd
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -434,6 +434,31 @@ process.on('uncaughtException', err => {
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for database & schema initialization to complete (auto-bootstrap if tables are missing)
|
||||
let dbReady = false;
|
||||
let dbAttempts = 0;
|
||||
while (!dbReady && dbAttempts < 30) {
|
||||
try {
|
||||
dbAttempts++;
|
||||
const tableCheck = await db`SELECT 1 FROM information_schema.tables WHERE table_name = 'items' LIMIT 1`;
|
||||
if (tableCheck.length === 0) {
|
||||
console.log('[BOOT] Database tables missing! Initializing schema from migrations/f0ckm_schema.sql...');
|
||||
await db.file('./migrations/f0ckm_schema.sql');
|
||||
console.log('[BOOT] Database schema initialization complete!');
|
||||
}
|
||||
dbReady = true;
|
||||
} catch (e) {
|
||||
if (dbAttempts === 1) {
|
||||
console.log(`[BOOT] Waiting for database connection... (${e.message})`);
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
}
|
||||
}
|
||||
if (dbReady) {
|
||||
console.log(`[BOOT] Database schema ready (took ${dbAttempts} attempt(s))`);
|
||||
} else {
|
||||
console.error('[BOOT] Database schema check timed out after 30 attempts!');
|
||||
}
|
||||
const timeout = 10000; // 10s module load timeout
|
||||
|
||||
// Ensure clients are resolved (Safe-guard for Docker/Node versions)
|
||||
@@ -469,23 +494,26 @@ process.on('uncaughtException', err => {
|
||||
self._trigger.set(trigger.name, new self.trigger(trigger));
|
||||
});
|
||||
|
||||
// Auto-migrate schema: ensure user_options & items columns exist
|
||||
const runMigration = async (query) => {
|
||||
try { await query; } catch (e) { /* ignore if table doesn't exist yet */ }
|
||||
};
|
||||
await runMigration(db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_file character varying(255) DEFAULT NULL`);
|
||||
await runMigration(db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_position character varying(50) DEFAULT 'center'`);
|
||||
await runMigration(db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_size character varying(50) DEFAULT 'cover'`);
|
||||
await runMigration(db`ALTER TABLE items ADD COLUMN IF NOT EXISTS expires_at bigint DEFAULT NULL`);
|
||||
await runMigration(db`ALTER TABLE items ADD COLUMN IF NOT EXISTS width integer DEFAULT NULL`);
|
||||
await runMigration(db`ALTER TABLE items ADD COLUMN IF NOT EXISTS height integer DEFAULT NULL`);
|
||||
await runMigration(db`ALTER TABLE items ADD COLUMN IF NOT EXISTS original_filename text DEFAULT NULL`);
|
||||
await runMigration(db`ALTER TABLE items ADD COLUMN IF NOT EXISTS title text DEFAULT NULL`);
|
||||
|
||||
// Initial halls cache (only if halls are enabled)
|
||||
if (cfg.websrv.halls_enabled !== false) {
|
||||
await updateHallsCache();
|
||||
}
|
||||
|
||||
// Auto-migrate schema: ensure user_options & items columns exist
|
||||
try {
|
||||
await db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_file character varying(255) DEFAULT NULL`;
|
||||
await db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_position character varying(50) DEFAULT 'center'`;
|
||||
await db`ALTER TABLE user_options ADD COLUMN IF NOT EXISTS banner_size character varying(50) DEFAULT 'cover'`;
|
||||
await db`ALTER TABLE items ADD COLUMN IF NOT EXISTS expires_at bigint DEFAULT NULL`;
|
||||
await db`ALTER TABLE items ADD COLUMN IF NOT EXISTS width integer DEFAULT NULL`;
|
||||
await db`ALTER TABLE items ADD COLUMN IF NOT EXISTS height integer DEFAULT NULL`;
|
||||
await db`ALTER TABLE items ADD COLUMN IF NOT EXISTS original_filename text DEFAULT NULL`;
|
||||
await db`ALTER TABLE items ADD COLUMN IF NOT EXISTS title text DEFAULT NULL`;
|
||||
} catch (e) {
|
||||
console.error('[BOOT] Schema migration error:', e.message);
|
||||
try {
|
||||
await updateHallsCache();
|
||||
} catch (e) {
|
||||
// ignore during early init
|
||||
}
|
||||
}
|
||||
|
||||
// Log feature flags
|
||||
@@ -1170,11 +1198,11 @@ process.on('uncaughtException', err => {
|
||||
let gitHash = process.env.GIT_HASH || 'unknown';
|
||||
if (gitHash === 'unknown') {
|
||||
try {
|
||||
const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
|
||||
const hash = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
|
||||
const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
||||
const hash = execSync('git rev-parse --short HEAD', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
||||
gitHash = `${branch}-${hash}`;
|
||||
} catch (e) {
|
||||
// console.warn('Could not get git hash:', e.message);
|
||||
// Not a git repository
|
||||
}
|
||||
}
|
||||
console.log('Git hash:', gitHash);
|
||||
|
||||
Reference in New Issue
Block a user