feat: adding request data table

This commit is contained in:
Carlos
2025-05-24 14:25:46 -04:00
parent 0e7222fba3
commit e2df2533f8
2 changed files with 45 additions and 0 deletions

39
src/database/migrate.js Normal file
View File

@ -0,0 +1,39 @@
const { Pool } = require('pg');
const fs = require('fs').promises;
const path = require('path');
require('dotenv').config();
const pool = new Pool({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
});
async function runMigration() {
const client = await pool.connect();
try {
console.log('🔄 Running database migration...');
// Read and execute the migration file
const migrationPath = path.join(__dirname, 'migrations', 'add_request_data.sql');
const migrationSQL = await fs.readFile(migrationPath, 'utf8');
await client.query('BEGIN');
await client.query(migrationSQL);
await client.query('COMMIT');
console.log('✅ Migration completed successfully');
} catch (error) {
await client.query('ROLLBACK');
console.error('❌ Migration failed:', error);
process.exit(1);
} finally {
client.release();
await pool.end();
}
}
// Run the migration
runMigration();

View File

@ -0,0 +1,6 @@
-- Add request_data column to prompts table
ALTER TABLE prompts
ADD COLUMN IF NOT EXISTS request_data JSONB;
-- Add comment to explain the column
COMMENT ON COLUMN prompts.request_data IS 'Stores complete request data including params, body, query, and headers';