57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import { readFileSync } from "fs";
|
|
import Database from "better-sqlite3";
|
|
|
|
// Check database directly
|
|
const dbPath = "./data/database.sqlite";
|
|
const db = new Database(dbPath);
|
|
|
|
console.log("Checking audit logs table...\n");
|
|
|
|
// Check table schema
|
|
const schema = db
|
|
.prepare(
|
|
"SELECT sql FROM sqlite_master WHERE type='table' AND name='audit_logs'"
|
|
)
|
|
.get();
|
|
console.log("Table schema:");
|
|
console.log(schema?.sql || "Table not found");
|
|
|
|
console.log("\n" + "=".repeat(50) + "\n");
|
|
|
|
// Get some audit logs
|
|
const logs = db
|
|
.prepare("SELECT * FROM audit_logs ORDER BY timestamp DESC LIMIT 5")
|
|
.all();
|
|
console.log(`Found ${logs.length} audit log entries:`);
|
|
|
|
logs.forEach((log, index) => {
|
|
console.log(`\n${index + 1}. ID: ${log.id}`);
|
|
console.log(` Timestamp: ${log.timestamp}`);
|
|
console.log(` User ID: ${log.user_id || "NULL"}`);
|
|
console.log(` Action: ${log.action}`);
|
|
console.log(` Resource Type: ${log.resource_type}`);
|
|
console.log(` Resource ID: ${log.resource_id || "N/A"}`);
|
|
console.log(` IP Address: ${log.ip_address || "N/A"}`);
|
|
console.log(` User Agent: ${log.user_agent || "N/A"}`);
|
|
console.log(` Details: ${log.details || "NULL"}`);
|
|
console.log(` Details type: ${typeof log.details}`);
|
|
});
|
|
|
|
// Count null user_ids
|
|
const nullUserCount = db
|
|
.prepare("SELECT COUNT(*) as count FROM audit_logs WHERE user_id IS NULL")
|
|
.get();
|
|
const totalCount = db.prepare("SELECT COUNT(*) as count FROM audit_logs").get();
|
|
|
|
console.log(`\n${"=".repeat(50)}`);
|
|
console.log(`Total audit logs: ${totalCount.count}`);
|
|
console.log(`Logs with NULL user_id: ${nullUserCount.count}`);
|
|
console.log(
|
|
`Percentage with NULL user_id: ${(
|
|
(nullUserCount.count / totalCount.count) *
|
|
100
|
|
).toFixed(2)}%`
|
|
);
|
|
|
|
db.close();
|