From 16d507991cac56d07aba8b5a98c4910ae2394ae4 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Wed, 24 Dec 2025 14:17:02 +0100 Subject: [PATCH] feat: Enhance update requirements check to include database migrations and rename related interfaces and methods. --- src/commands/admin/update.ts | 6 +++--- src/modules/admin/update.service.test.ts | 9 +++++---- src/modules/admin/update.service.ts | 13 +++++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/commands/admin/update.ts b/src/commands/admin/update.ts index 6351841..f54416e 100644 --- a/src/commands/admin/update.ts +++ b/src/commands/admin/update.ts @@ -52,15 +52,15 @@ export const update = createCommand({ components: [] }); - // 1. Check dependencies - const { needsInstall } = await UpdateService.checkDependencies(branch); + // 1. Check what the update requires + const { needsInstall, needsMigrations } = await UpdateService.checkUpdateRequirements(branch); // 2. Prepare context BEFORE update await UpdateService.prepareRestartContext({ channelId: interaction.channelId, userId: interaction.user.id, timestamp: Date.now(), - runMigrations: true, + runMigrations: needsMigrations, installDependencies: needsInstall }); diff --git a/src/modules/admin/update.service.test.ts b/src/modules/admin/update.service.test.ts index c916850..7eb0d17 100644 --- a/src/modules/admin/update.service.test.ts +++ b/src/modules/admin/update.service.test.ts @@ -95,16 +95,17 @@ describe("UpdateService", () => { }); }); - describe("checkDependencies", () => { - test("should detect package.json change", async () => { - const result = await UpdateService.checkDependencies("main"); + describe("checkUpdateRequirements", () => { + test("should detect package.json and schema.ts changes", async () => { + const result = await UpdateService.checkUpdateRequirements("main"); expect(result.needsInstall).toBe(true); + expect(result.needsMigrations).toBe(false); // mock doesn't include schema.ts expect(result.error).toBeUndefined(); }); test("should call git diff with correct branch", async () => { - await UpdateService.checkDependencies("develop"); + await UpdateService.checkUpdateRequirements("develop"); const lastCall = mockExec.mock.lastCall; expect(lastCall).toBeDefined(); diff --git a/src/modules/admin/update.service.ts b/src/modules/admin/update.service.ts index 5ba602c..c7823ce 100644 --- a/src/modules/admin/update.service.ts +++ b/src/modules/admin/update.service.ts @@ -19,8 +19,9 @@ export interface RestartContext { installDependencies: boolean; } -export interface DependencyCheckResult { +export interface UpdateCheckResult { needsInstall: boolean; + needsMigrations: boolean; error?: Error; } @@ -45,14 +46,18 @@ export class UpdateService { await execAsync(`git reset --hard origin/${branch}`); } - static async checkDependencies(branch: string): Promise { + static async checkUpdateRequirements(branch: string): Promise { try { const { stdout } = await execAsync(`git diff HEAD..origin/${branch} --name-only`); - return { needsInstall: stdout.includes("package.json") }; + return { + needsInstall: stdout.includes("package.json"), + needsMigrations: stdout.includes("schema.ts") || stdout.includes("drizzle/") + }; } catch (e) { - console.error("Failed to check dependencies:", e); + console.error("Failed to check update requirements:", e); return { needsInstall: false, + needsMigrations: false, error: e instanceof Error ? e : new Error(String(e)) }; }