feat: Enhance update requirements check to include database migrations and rename related interfaces and methods.

This commit is contained in:
syntaxbullet
2025-12-24 14:17:02 +01:00
parent e2aa5ee760
commit 16d507991c
3 changed files with 17 additions and 11 deletions

View File

@@ -52,15 +52,15 @@ export const update = createCommand({
components: [] components: []
}); });
// 1. Check dependencies // 1. Check what the update requires
const { needsInstall } = await UpdateService.checkDependencies(branch); const { needsInstall, needsMigrations } = await UpdateService.checkUpdateRequirements(branch);
// 2. Prepare context BEFORE update // 2. Prepare context BEFORE update
await UpdateService.prepareRestartContext({ await UpdateService.prepareRestartContext({
channelId: interaction.channelId, channelId: interaction.channelId,
userId: interaction.user.id, userId: interaction.user.id,
timestamp: Date.now(), timestamp: Date.now(),
runMigrations: true, runMigrations: needsMigrations,
installDependencies: needsInstall installDependencies: needsInstall
}); });

View File

@@ -95,16 +95,17 @@ describe("UpdateService", () => {
}); });
}); });
describe("checkDependencies", () => { describe("checkUpdateRequirements", () => {
test("should detect package.json change", async () => { test("should detect package.json and schema.ts changes", async () => {
const result = await UpdateService.checkDependencies("main"); const result = await UpdateService.checkUpdateRequirements("main");
expect(result.needsInstall).toBe(true); expect(result.needsInstall).toBe(true);
expect(result.needsMigrations).toBe(false); // mock doesn't include schema.ts
expect(result.error).toBeUndefined(); expect(result.error).toBeUndefined();
}); });
test("should call git diff with correct branch", async () => { test("should call git diff with correct branch", async () => {
await UpdateService.checkDependencies("develop"); await UpdateService.checkUpdateRequirements("develop");
const lastCall = mockExec.mock.lastCall; const lastCall = mockExec.mock.lastCall;
expect(lastCall).toBeDefined(); expect(lastCall).toBeDefined();

View File

@@ -19,8 +19,9 @@ export interface RestartContext {
installDependencies: boolean; installDependencies: boolean;
} }
export interface DependencyCheckResult { export interface UpdateCheckResult {
needsInstall: boolean; needsInstall: boolean;
needsMigrations: boolean;
error?: Error; error?: Error;
} }
@@ -45,14 +46,18 @@ export class UpdateService {
await execAsync(`git reset --hard origin/${branch}`); await execAsync(`git reset --hard origin/${branch}`);
} }
static async checkDependencies(branch: string): Promise<DependencyCheckResult> { static async checkUpdateRequirements(branch: string): Promise<UpdateCheckResult> {
try { try {
const { stdout } = await execAsync(`git diff HEAD..origin/${branch} --name-only`); 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) { } catch (e) {
console.error("Failed to check dependencies:", e); console.error("Failed to check update requirements:", e);
return { return {
needsInstall: false, needsInstall: false,
needsMigrations: false,
error: e instanceof Error ? e : new Error(String(e)) error: e instanceof Error ? e : new Error(String(e))
}; };
} }