diff --git a/lib/runner.js b/lib/runner.js index 43f3c1b..550dd93 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -201,8 +201,8 @@ async function _executeTest(url, options) { const userIp = options.userIp || '0.0.0.0'; const insertQuery = ` - INSERT INTO test_results (id, url, timestamp, is_mobile, scores, metrics, user_uuid, user_ip) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8) + INSERT INTO test_results (id, url, timestamp, is_mobile, scores, metrics, user_uuid, user_ip, filmstrip) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) `; const values = [ testId, @@ -212,7 +212,8 @@ async function _executeTest(url, options) { summary.scores, summary.metrics, userUuid, - userIp + userIp, + JSON.stringify(summary.filmstrip) // Ensure it's a JSON string ]; try { @@ -277,7 +278,8 @@ async function getHistory(userUuid, userIp) { timestamp: row.timestamp, // JS Date isMobile: row.is_mobile, scores: row.scores, - metrics: row.metrics + metrics: row.metrics, + filmstrip: row.filmstrip || [] // Return filmstrip if available })); } catch (err) { console.error('Error fetching history from DB:', err); diff --git a/migrations/002_add_filmstrip.sql b/migrations/002_add_filmstrip.sql new file mode 100644 index 0000000..0e5c678 --- /dev/null +++ b/migrations/002_add_filmstrip.sql @@ -0,0 +1,6 @@ +-- Add filmstrip column to test_results table +ALTER TABLE test_results +ADD COLUMN filmstrip JSONB DEFAULT '[]'::jsonb; + +-- Comment on column +COMMENT ON COLUMN test_results.filmstrip IS 'Array of filmstrip screenshots/thumbnails from Lighthouse'; diff --git a/migrations/migrate_002.js b/migrations/migrate_002.js new file mode 100644 index 0000000..c29e5d3 --- /dev/null +++ b/migrations/migrate_002.js @@ -0,0 +1,27 @@ +const db = require('../lib/db'); +const fs = require('fs'); +const path = require('path'); + +const migrationFile = path.join(__dirname, '002_add_filmstrip.sql'); + +async function runMigration() { + try { + console.log('Reading migration file:', migrationFile); + const sql = fs.readFileSync(migrationFile, 'utf8'); + + console.log('Applying migration...'); + await db.pool.query(sql); + + console.log('✅ Migration 002 applied successfully!'); + process.exit(0); + } catch (err) { + if (err.code === '42701') { // duplicate_column + console.log('⚠️ Column already exists. Skipping.'); + process.exit(0); + } + console.error('❌ Migration failed:', err); + process.exit(1); + } +} + +runMigration();