CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
migrator.cjs60 linesDownload Raw Back to singlestore-proxy
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7  for (var name in all)8    __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11  if (from && typeof from === "object" || typeof from === "function") {12    for (let key of __getOwnPropNames(from))13      if (!__hasOwnProp.call(to, key) && key !== except)14        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15  }16  return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var migrator_exports = {};20__export(migrator_exports, {21  migrate: () => migrate22});23module.exports = __toCommonJS(migrator_exports);24var import_migrator = require("../migrator.cjs");25var import_sql = require("../sql/sql.cjs");26async function migrate(db, callback, config) {27  const migrations = (0, import_migrator.readMigrationFiles)(config);28  const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";29  const migrationTableCreate = import_sql.sql`30		create table if not exists ${import_sql.sql.identifier(migrationsTable)} (31			id serial primary key,32			hash text not null,33			created_at bigint34		)35	`;36  await db.execute(migrationTableCreate);37  const dbMigrations = await db.select({38    id: import_sql.sql.raw("id"),39    hash: import_sql.sql.raw("hash"),40    created_at: import_sql.sql.raw("created_at")41  }).from(import_sql.sql.identifier(migrationsTable).getSQL()).orderBy(42    import_sql.sql.raw("created_at desc")43  ).limit(1);44  const lastDbMigration = dbMigrations[0];45  const queriesToRun = [];46  for (const migration of migrations) {47    if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {48      queriesToRun.push(49        ...migration.sql,50        `insert into ${import_sql.sql.identifier(migrationsTable).value} (\`hash\`, \`created_at\`) values('${migration.hash}', '${migration.folderMillis}')`51      );52    }53  }54  await callback(queriesToRun);55}56// Annotate the CommonJS export names for ESM import in node:570 && (module.exports = {58  migrate59});60//# sourceMappingURL=migrator.cjs.map