mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
34 lines
782 B
JavaScript
34 lines
782 B
JavaScript
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
|
|
};
|