feat: Move database migration execution from update command to post-restart ready event.

This commit is contained in:
syntaxbullet
2025-12-18 17:29:37 +01:00
parent 1d650bb2c7
commit 71fefb3a14
2 changed files with 50 additions and 33 deletions

View File

@@ -20,10 +20,37 @@ const event: Event<Events.ClientReady> = {
// Validate context freshness (e.g., ignore if older than 5 minutes)
if (Date.now() - context.timestamp < 5 * 60 * 1000) {
const channel = await c.channels.fetch(context.channelId);
if (channel && channel.isSendable()) {
await channel.send({
embeds: [createSuccessEmbed("Bot is back online! Redeploy successful.", "System Online")]
});
let migrationOutput = "";
let success = true;
if (context.runMigrations) {
try {
const { exec } = await import("child_process");
const { promisify } = await import("util");
const execAsync = promisify(exec);
// Send intermediate update if possible, though ready event should be fast.
// Maybe just run it and report result.
const { stdout: dbOut } = await execAsync("bun run db:push:local");
migrationOutput = dbOut;
} catch (dbErr: any) {
success = false;
migrationOutput = `Migration Failed: ${dbErr.message}`;
console.error("Migration Error:", dbErr);
}
}
if (context.runMigrations) {
await channel.send({
embeds: [createSuccessEmbed(`Bot is back online!\n\n**DB Migration Output:**\n\`\`\`\n${migrationOutput}\n\`\`\``, success ? "Update Successful" : "Update Completed with/Errors")]
});
} else {
await channel.send({
embeds: [createSuccessEmbed("Bot is back online! Redeploy successful.", "System Online")]
});
}
}
}