AK-21/Graphite-Industrial-Intelligence
0
1import crypto from "node:crypto";2import fs from "node:fs";3function readMigrationFiles(config) {4 const migrationFolderTo = config.migrationsFolder;5 const migrationQueries = [];6 const journalPath = `${migrationFolderTo}/meta/_journal.json`;7 if (!fs.existsSync(journalPath)) {8 throw new Error(`Can't find meta/_journal.json file`);9 }10 const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();11 const journal = JSON.parse(journalAsString);12 for (const journalEntry of journal.entries) {13 const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;14 try {15 const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();16 const result = query.split("--> statement-breakpoint").map((it) => {17 return it;18 });19 migrationQueries.push({20 sql: result,21 bps: journalEntry.breakpoints,22 folderMillis: journalEntry.when,23 hash: crypto.createHash("sha256").update(query).digest("hex")24 });25 } catch {26 throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);27 }28 }29 return migrationQueries;30}31export {32 readMigrationFiles33};34//# sourceMappingURL=migrator.js.map