Skip to content

Commit 97f6861

Browse files
committed
feat: impl handleGenerateSQL
1 parent 30f3f2c commit 97f6861

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

bridge/src/handlers/projectHandlers.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,4 +827,32 @@ export class ProjectHandlers {
827827
this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) });
828828
}
829829
}
830+
async handleGenerateSQL(params: any, id: number | string) {
831+
try {
832+
const { projectId } = params || {};
833+
if (!projectId) {
834+
return this.rpc.sendError(id, {
835+
code: "BAD_REQUEST",
836+
message: "Missing projectId",
837+
});
838+
}
839+
840+
const { projectStoreInstance } = await import("../services/projectStore");
841+
const schemaFile = await projectStoreInstance.getSchema(projectId);
842+
if (!schemaFile) {
843+
return this.rpc.sendError(id, {
844+
code: "NOT_FOUND",
845+
message: "No schema snapshot found",
846+
});
847+
}
848+
849+
const { generateBaselineSQL } = await import("../utils/baselineMigration");
850+
const sql = generateBaselineSQL(schemaFile as any, "preview", "preview");
851+
852+
this.rpc.sendResponse(id, { ok: true, data: { sql } });
853+
} catch (e: any) {
854+
this.logger?.error({ e }, "project.generateSQL failed");
855+
this.rpc.sendError(id, { code: "IO_ERROR", message: String(e) });
856+
}
857+
}
830858
}

bridge/src/jsonRpcHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ export function registerDbHandlers(
260260
rpcRegister(rpc, "project.syncMigrations", (p, id) =>
261261
projectHandlers.handleSyncMigrations(p, id)
262262
);
263+
rpcRegister(rpc, "project.generateSQL", (p, id) =>
264+
projectHandlers.handleGenerateSQL(p, id)
265+
);
263266
rpcRegister(rpc, "project.getDrift", (p, id) =>
264267
projectHandlers.handleGetDrift(p, id)
265268
);

0 commit comments

Comments
 (0)