Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Fix: implement missing onOk handler to download migration zip (#960)

Paulina Méndezf6867c32e249
diff --git a/src/components/EditorHeader/SideSheet/Migration.jsx b/src/components/EditorHeader/SideSheet/Migration.jsx
index b2244659..7f7d7ae1 100644
--- a/src/components/EditorHeader/SideSheet/Migration.jsx
+++ b/src/components/EditorHeader/SideSheet/Migration.jsx
@@ -9,6 +9,8 @@ import { deepDiff } from "../../../utils/diff";
import { DateTime } from "luxon";
import CodeEditor from "../../CodeEditor";
import { generateMigrationSQL } from "../../../utils/migrations/diffToSQL";
+import * as JSZip from "jszip";
+import { saveAs } from "file-saver";
export default function Migration({
gistId,
@@ -77,6 +79,22 @@ export default function Migration({
}
}, [gistId, selectedVersion, versionToCompareTo]);
+ const handleConfirm = () => {
+ if (!migrationSQL?.up) return;
+
+ const JSZipConstructor = JSZip.default || JSZip;
+ const zip = new JSZipConstructor();
+
+ zip.file(`${filename}.up.sql`, migrationSQL.up);
+ zip.file(`${filename}.down.sql`, migrationSQL.down);
+
+ zip.generateAsync({ type: "blob" }).then(function (content) {
+ saveAs(content, `${filename}.zip`);
+ });
+
+ setSelectedVersion(null);
+ };
+
useEffect(() => {
if (versionToCompareTo === "") {
setLoading(true);
@@ -99,6 +117,7 @@ export default function Migration({
}
visible={!!selectedVersion}
onCancel={() => setSelectedVersion(null)}
+ onOk={handleConfirm}
>
<Tabs lazyRender keepDOM={false} className="h-[26rem] -mt-3">
<TabPane tab={t("scripts")} itemKey="1">