AK-21/Graphite-Industrial-Intelligence
0
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, 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 numeric34 )35 `;36 await db.session.run(migrationTableCreate);37 const dbMigrations = await db.values(38 import_sql.sql`SELECT id, hash, created_at FROM ${import_sql.sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`39 );40 const lastDbMigration = dbMigrations[0] ?? void 0;41 const statementToBatch = [];42 for (const migration of migrations) {43 if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {44 for (const stmt of migration.sql) {45 statementToBatch.push(db.run(import_sql.sql.raw(stmt)));46 }47 statementToBatch.push(48 db.run(49 import_sql.sql`INSERT INTO ${import_sql.sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${import_sql.sql.raw(`'${migration.hash}'`)}, ${import_sql.sql.raw(`${migration.folderMillis}`)})`50 )51 );52 }53 }54 if (statementToBatch.length > 0) {55 await db.session.batch(statementToBatch);56 }57}58// Annotate the CommonJS export names for ESM import in node:590 && (module.exports = {60 migrate61});62//# sourceMappingURL=migrator.cjs.map