UNPKG

exclaim-recovery-database

Version:

Shared database schemas for Exclaim Recovery platform

76 lines 2.96 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); require("dotenv/config"); const node_postgres_1 = require("drizzle-orm/node-postgres"); const migrator_1 = require("drizzle-orm/node-postgres/migrator"); const pg_1 = require("pg"); const drizzle_orm_1 = require("drizzle-orm"); const path_1 = require("path"); const schema = __importStar(require("./schema.js")); async function main() { // Get connection string from environment const connectionString = process.env.VERCEL_POSTGRES_URL; if (!connectionString) { console.error('No VERCEL_POSTGRES_URL found in environment'); process.exit(1); } console.log('Connecting to database...'); const pool = new pg_1.Pool({ connectionString, }); const db = (0, node_postgres_1.drizzle)(pool, { schema }); try { // First, ensure the pgvector extension is installed console.log('Installing pgvector extension...'); await db.execute((0, drizzle_orm_1.sql) `CREATE EXTENSION IF NOT EXISTS vector`); // Then run migrations console.log('Running migrations...'); // Define the migrations folder path const migrationsFolder = (0, path_1.resolve)(__dirname, './migrations'); // Run migrations await (0, migrator_1.migrate)(db, { migrationsFolder }); console.log('Migrations completed successfully'); } catch (error) { console.error('Migration failed:', error); process.exit(1); } finally { await pool.end(); } } main(); //# sourceMappingURL=migrate.js.map