diff --git a/src/database/migrate.js b/src/database/migrate.js new file mode 100644 index 0000000..387d517 --- /dev/null +++ b/src/database/migrate.js @@ -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(); \ No newline at end of file diff --git a/src/database/migrations/add_request_data.sql b/src/database/migrations/add_request_data.sql new file mode 100644 index 0000000..5542fc3 --- /dev/null +++ b/src/database/migrations/add_request_data.sql @@ -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'; \ No newline at end of file