Implement PostgreSQL history with user isolation

This commit is contained in:
2025-12-28 00:13:43 +11:00
parent d83a93da7e
commit 5ae3b0d036
6 changed files with 130 additions and 21 deletions

33
lib/db.js Normal file
View File

@@ -0,0 +1,33 @@
const { Pool } = require('pg');
const dbConfig = require('./db-config');
const pool = new Pool(dbConfig);
async function initSchema() {
const client = await pool.connect();
try {
const query = `
CREATE TABLE IF NOT EXISTS test_results (
id UUID PRIMARY KEY,
url TEXT NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
is_mobile BOOLEAN NOT NULL,
scores JSONB NOT NULL,
metrics JSONB NOT NULL,
user_uuid TEXT NOT NULL,
user_ip TEXT NOT NULL
);
`;
await client.query(query);
console.log("Schema initialized: test_results table ready.");
} catch (err) {
console.error("Error initializing schema:", err);
} finally {
client.release();
}
}
module.exports = {
pool,
initSchema
};