feat: adding request data table
This commit is contained in:
39
src/database/migrate.js
Normal file
39
src/database/migrate.js
Normal 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();
|
6
src/database/migrations/add_request_data.sql
Normal file
6
src/database/migrations/add_request_data.sql
Normal 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';
|
Reference in New Issue
Block a user