-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
46 lines (38 loc) · 1.49 KB
/
setup.js
File metadata and controls
46 lines (38 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fs = require('fs');
const path = require('path');
const Database = require('better-sqlite3');
const DB_PATH = path.join(__dirname, 'data', 'status.db');
// Ensure data directory exists
if (!fs.existsSync(path.join(__dirname, 'data'))) {
fs.mkdirSync(path.join(__dirname, 'data'), { recursive: true });
}
const db = new Database(DB_PATH);
db.pragma('journal_mode = WAL');
db.exec(`
CREATE TABLE IF NOT EXISTS checks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
service_name TEXT NOT NULL,
service_url TEXT NOT NULL,
status TEXT NOT NULL CHECK(status IN ('up', 'down', 'degraded')),
response_time INTEGER,
status_code INTEGER,
error_message TEXT,
checked_at DATETIME DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_checks_service ON checks(service_name, checked_at);
CREATE INDEX IF NOT EXISTS idx_checks_date ON checks(checked_at);
CREATE TABLE IF NOT EXISTS incidents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
service_name TEXT NOT NULL,
title TEXT NOT NULL,
description TEXT,
status TEXT NOT NULL CHECK(status IN ('investigating', 'identified', 'monitoring', 'resolved')),
severity TEXT NOT NULL CHECK(severity IN ('minor', 'major', 'critical')),
created_at DATETIME DEFAULT (datetime('now')),
updated_at DATETIME DEFAULT (datetime('now')),
resolved_at DATETIME
);
CREATE INDEX IF NOT EXISTS idx_incidents_service ON incidents(service_name, created_at);
`);
console.log('Database setup complete at', DB_PATH);
db.close();