Fix table creation (#2)

- Add Caddyfile
- Add start of vanilla layout
This commit is contained in:
2024-04-04 20:49:25 -04:00
parent 9e027ca51e
commit 8db4216ea2
4 changed files with 44 additions and 5 deletions

View File

@@ -9,15 +9,17 @@ class Data {
* @return SQLite3 A new connection to the database
*/
private static function getConnection(): SQLite3 {
$db = new SQLite3("../data/{${DATABASE_NAME}}");
$db = new SQLite3('../data/' . DATABASE_NAME);
$db->exec('PRAGMA foreign_keys = ON;');
return $db;
}
public static function ensureDb(): void {
$db = self::getConnection();
$tables = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'")->fetchArray(SQLITE3_NUM);
if (!array_search('frc_user', $tables)) {
$tables = array();
$tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0];
if (!in_array('frc_user', $tables)) {
$query = <<<SQL
CREATE TABLE frc_user (
id INTEGER NOT NULL PRIMARY KEY,
@@ -28,7 +30,7 @@ class Data {
$db->exec($query);
$db->exec('CREATE INDEX idx_user_email ON frc_user (email)');
}
if (!array_search('feed', $tables)) {
if (!in_array('feed', $tables)) {
$query = <<<SQL
CREATE TABLE feed (
id INTEGER NOT NULL PRIMARY KEY,
@@ -39,7 +41,7 @@ class Data {
SQL;
$db->exec($query);
}
if (!array_search('item', $tables)) {
if (!in_array('item', $tables)) {
$query = <<<SQL
CREATE TABLE item (
id INTEGER NOT NULL PRIMARY KEY,