mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
Phase 3: Add filmstrip column to DB and update runner
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
6
migrations/002_add_filmstrip.sql
Normal file
6
migrations/002_add_filmstrip.sql
Normal 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
27
migrations/migrate_002.js
Normal 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();
|
||||||
Reference in New Issue
Block a user