Began working on backend php for Database setup and management.

This commit is contained in:
Tristan Ancelet 2023-05-09 19:50:37 -05:00
parent 77ac940c7a
commit 6a23079126
5 changed files with 55 additions and 11 deletions

View File

@ -0,0 +1,31 @@
CREATE TABLE IF NOT EXISTS log_levels (
log_level_id INTEGER PRIMARY KEY,
log_level_name VARCHAR(10) NOT NULL
);
INSERT INTO log_levels (log_level_id, log_level_name) VALUES
(0, 'INFO'),
(1, 'CRITICAL'),
(2, 'WARNING');
CREATE TABLE IF NOT EXISTS logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
log_level_id INTEGER NOT NULL DEFAULT 0,
log_source VARCHAR NOT NULL, -- This will be a unix path '/path/to/script'
log_message TEXT NOT NULl,
log_entry_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (log_level_id) REFERENCES log_levels(log_level_id)
);
CREATE VIEW IF NOT EXISTS log_statistics AS
SELECT levels.log_level_name, COUNT(logs.log_id) FROM logs
JOIN log_levels levels ON log_levels.log_level_id = logs.log_level_id
GROUP BY logs.log_level_id;
CREATE VIEW IF NOT EXISTS log_statistics_last_7_days AS
SELECT log_levels.log_level_name, COUNT(logs.log_id) FROM logs
JOIN log_levels ON log_levels.log_level_id = logs.log_level_id
WHERE logs.log_entry_timestamp > DATETIME(CURRENT_TIMESTAMP, '-7 day')
GROUP BY logs.log_level_id;

8
database_version.php Normal file
View File

@ -0,0 +1,8 @@
<?php
$ver = SQLite3::version();
$versionString=$ver['versionString'];
$versionNumber=$ver['versionNumber'];
echo "Database Type: SQLite3<br>";
echo "Version: $versionString <br>";
echo "Version Number: $versionNumber" ;
?>

View File

@ -6,6 +6,7 @@
<head> <head>
<!-- <script src="https://cdn.tailwindcss.com"></script> --> <!-- <script src="https://cdn.tailwindcss.com"></script> -->
<link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/main.css">
<script src="main.js"> </script>
<title>This is a test</title> <title>This is a test</title>
</head> </head>
<body> <body>
@ -20,19 +21,11 @@
<div class="menu_bar bordered_right cell"> <div class="menu_bar bordered_right cell">
<button class="menu_button"> Check Logs </button> <button class="menu_button"> Check Logs </button>
<button class="menu_button"> View Crontab Statistics</button> <button class="menu_button"> View Crontab Statistics</button>
<button class="menu_button" onclick="setInfoSection()"> View Database Version</button>
</div> </div>
<div class="content cell"> <div id="content" class="content cell">
test Test
<?php
echo "<br>";
echo "<ul>";
for ($x = 0; $x <= 10; $x++){
echo "<li> Hey there $x </li>";
}
echo "</ul>";
?>
</div> </div>
<div class="double_width_menu_bar bordered_left cell"> <div class="double_width_menu_bar bordered_left cell">

11
main.js Normal file
View File

@ -0,0 +1,11 @@
function request_sqlite_version () {
var request = new XMLHttpRequest();
request.open("GET", 'http://localhost:8000/database_version.php', false);
request.send(null);
return request.responseText;
}
function setInfoSection (string) {
var info_section = document.getElementById("content");
info_section.innerHTML = request_sqlite_version();
}

1
php.ini Normal file
View File

@ -0,0 +1 @@
extension=sqlite3