migrator.cjs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var migrator_exports = {};
  30. __export(migrator_exports, {
  31. readMigrationFiles: () => readMigrationFiles
  32. });
  33. module.exports = __toCommonJS(migrator_exports);
  34. var import_node_crypto = __toESM(require("node:crypto"), 1);
  35. var import_node_fs = __toESM(require("node:fs"), 1);
  36. function readMigrationFiles(config) {
  37. const migrationFolderTo = config.migrationsFolder;
  38. const migrationQueries = [];
  39. const journalPath = `${migrationFolderTo}/meta/_journal.json`;
  40. if (!import_node_fs.default.existsSync(journalPath)) {
  41. throw new Error(`Can't find meta/_journal.json file`);
  42. }
  43. const journalAsString = import_node_fs.default.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
  44. const journal = JSON.parse(journalAsString);
  45. for (const journalEntry of journal.entries) {
  46. const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
  47. try {
  48. const query = import_node_fs.default.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
  49. const result = query.split("--> statement-breakpoint").map((it) => {
  50. return it;
  51. });
  52. migrationQueries.push({
  53. sql: result,
  54. bps: journalEntry.breakpoints,
  55. folderMillis: journalEntry.when,
  56. hash: import_node_crypto.default.createHash("sha256").update(query).digest("hex")
  57. });
  58. } catch {
  59. throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
  60. }
  61. }
  62. return migrationQueries;
  63. }
  64. // Annotate the CommonJS export names for ESM import in node:
  65. 0 && (module.exports = {
  66. readMigrationFiles
  67. });
  68. //# sourceMappingURL=migrator.cjs.map