CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
migrator.cjs68 linesDownload Raw Back to drizzle-orm
1"use strict";2var __create = Object.create;3var __defProp = Object.defineProperty;4var __getOwnPropDesc = Object.getOwnPropertyDescriptor;5var __getOwnPropNames = Object.getOwnPropertyNames;6var __getProtoOf = Object.getPrototypeOf;7var __hasOwnProp = Object.prototype.hasOwnProperty;8var __export = (target, all) => {9  for (var name in all)10    __defProp(target, name, { get: all[name], enumerable: true });11};12var __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};20var __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 ESM22  // file that has been converted to a CommonJS file using a Babel-23  // compatible transform (i.e. "__esModule" has not been set), then set24  // "default" to the CommonJS "module.exports" for node compatibility.25  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,26  mod27));28var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);29var migrator_exports = {};30__export(migrator_exports, {31  readMigrationFiles: () => readMigrationFiles32});33module.exports = __toCommonJS(migrator_exports);34var import_node_crypto = __toESM(require("node:crypto"), 1);35var import_node_fs = __toESM(require("node:fs"), 1);36function 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:650 && (module.exports = {66  readMigrationFiles67});68//# sourceMappingURL=migrator.cjs.map