mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
Implement PostgreSQL history with user isolation
This commit is contained in:
33
lib/db.js
Normal file
33
lib/db.js
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user