Phase 3: Add filmstrip column to DB and update runner

This commit is contained in:
2025-12-28 10:29:40 +11:00
parent 039e126d9a
commit 9cd5cac287
3 changed files with 39 additions and 4 deletions

View File

@@ -201,8 +201,8 @@ async function _executeTest(url, options) {
const userIp = options.userIp || '0.0.0.0'; const userIp = options.userIp || '0.0.0.0';
const insertQuery = ` const insertQuery = `
INSERT INTO test_results (id, url, timestamp, is_mobile, scores, metrics, user_uuid, user_ip) 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) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
`; `;
const values = [ const values = [
testId, testId,
@@ -212,7 +212,8 @@ async function _executeTest(url, options) {
summary.scores, summary.scores,
summary.metrics, summary.metrics,
userUuid, userUuid,
userIp userIp,
JSON.stringify(summary.filmstrip) // Ensure it's a JSON string
]; ];
try { try {
@@ -277,7 +278,8 @@ async function getHistory(userUuid, userIp) {
timestamp: row.timestamp, // JS Date timestamp: row.timestamp, // JS Date
isMobile: row.is_mobile, isMobile: row.is_mobile,
scores: row.scores, scores: row.scores,
metrics: row.metrics metrics: row.metrics,
filmstrip: row.filmstrip || [] // Return filmstrip if available
})); }));
} catch (err) { } catch (err) {
console.error('Error fetching history from DB:', err); console.error('Error fetching history from DB:', err);

View File

@@ -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';

27
migrations/migrate_002.js Normal file
View File

@@ -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();