Files
klz-cables.com/.pnpm-store/v10/files/4f/ff58d3d8c543da198cad76115ebde7fc30996178abff81057218c6611369dc78456dc1f399d9633f2431da23f87850c04e16d9a98de28a2270e969ab455b19
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

65 lines
1.8 KiB
Plaintext

import { useEffect, useReducer } from "react";
async function readMigrationFiles({ journal, migrations }) {
const migrationQueries = [];
for await (const journalEntry of journal.entries) {
const query = migrations[`m${journalEntry.idx.toString().padStart(4, "0")}`];
if (!query) {
throw new Error(`Missing migration: ${journalEntry.tag}`);
}
try {
const result = query.split("--> statement-breakpoint").map((it) => {
return it;
});
migrationQueries.push({
sql: result,
bps: journalEntry.breakpoints,
folderMillis: journalEntry.when,
hash: ""
});
} catch {
throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
}
}
return migrationQueries;
}
async function migrate(db, config) {
const migrations = await readMigrationFiles(config);
return db.dialect.migrate(migrations, db.session);
}
const useMigrations = (db, migrations) => {
const initialState = {
success: false,
error: void 0
};
const fetchReducer = (state2, action) => {
switch (action.type) {
case "migrating": {
return { ...initialState };
}
case "migrated": {
return { ...initialState, success: action.payload };
}
case "error": {
return { ...initialState, error: action.payload };
}
default: {
return state2;
}
}
};
const [state, dispatch] = useReducer(fetchReducer, initialState);
useEffect(() => {
dispatch({ type: "migrating" });
migrate(db, migrations).then(() => {
dispatch({ type: "migrated", payload: true });
}).catch((error) => {
dispatch({ type: "error", payload: error });
});
}, []);
return state;
};
export {
migrate,
useMigrations
};
//# sourceMappingURL=migrator.js.map