From e114edd481e19acd2233ce75d3560cf58fd64e34 Mon Sep 17 00:00:00 2001 From: Volkor <me@volkor.me> Date: Tue, 24 Jan 2023 21:08:24 +1100 Subject: [PATCH] Make the user initialise the DB instead. --- README.md | 3 ++- schema.sql | 24 ++++++++++++++++++++++++ src/db.rs | 37 ------------------------------------- src/main.rs | 7 ------- 4 files changed, 26 insertions(+), 45 deletions(-) create mode 100644 schema.sql diff --git a/README.md b/README.md index fe4532f..500cfc6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ This project is a re-write of QuadFile, a project I found years ago, being a old That's a little more complicated. Eventually we'll have 2 different environments, development and production, each with different logging and such. -For now, just run `cargo run` (or `cargo watch -x run` if you're cool.) +1. Initialise the database with the following command `sqlite3 ephemeral.db < schema.sql` +2. Compile and run ephemeral with `LOG=debug cargo run` for the debug build. `LOG=info cargo run -r` will run the release build. ### Configuration Options diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..f222187 --- /dev/null +++ b/schema.sql @@ -0,0 +1,24 @@ +-- This drops the existing files table, and re-creates it. -- +DROP TABLE IF EXISTS 'files'; +CREATE TABLE IF NOT EXISTS 'files' ( + file TEXT NOT NULL, + filetype TEXT, + expiry INTEGER NOT NULL, + expiry_override INTEGER, + views INTEGER DEFAULT '0', + isDeleted INTEGER DEFAULT '0', + adminkey TEXT NOT NULL, + accessed INTEGER NOT NULL, + filesize INTEGER NOT NULL, + IP TEXT NOT NULL, + domain TEXT NOT NULL); + +-- This drops the existing qrscan table, and re-creates it. -- +DROP TABLE IF EXISTS 'qrscan'; +CREATE TABLE 'qrscan' ( + scanid INTEGER PRIMARY KEY, + time INTEGER NOT NULL, + IP TEXT NOT NULL, + useragent TEXT NOT NULL, + version INTEGER NOT NULL + ); \ No newline at end of file diff --git a/src/db.rs b/src/db.rs index 1ddee97..83aa9c2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,43 +2,6 @@ use std::time::SystemTime; use sqlx::{sqlite::SqliteQueryResult, Pool, Row, Sqlite}; -pub async fn create_filesdb(sqlconn: &Pool<Sqlite>) -> Result<SqliteQueryResult, sqlx::Error> { - tracing::info!("Creating files database!"); - sqlx::query( - "CREATE TABLE IF NOT EXISTS 'files' ( - file TEXT NOT NULL, - filetype TEXT, - expiry INTEGER NOT NULL, - expiry_override INTEGER, - views INTEGER DEFAULT '0', - isDeleted INTEGER DEFAULT '0', - adminkey TEXT NOT NULL, - accessed INTEGER NOT NULL, - filesize INTEGER NOT NULL, - IP TEXT NOT NULL, - domain TEXT NOT NULL);", - ) - .execute(sqlconn) - .await - // TODO: Check for row affected, and give a Result -} - -pub async fn create_qrscandb(sqlconn: &Pool<Sqlite>) -> Result<SqliteQueryResult, sqlx::Error> { - tracing::info!("Created Databases!"); - sqlx::query( - "CREATE TABLE 'qrscan' ( - scanid INTEGER PRIMARY KEY, - time INTEGER NOT NULL, - IP TEXT NOT NULL, - useragent TEXT NOT NULL, - version INTEGER NOT NULL - );", - ) - .execute(sqlconn) - .await - // TODO: Check for row affected, and give a Result -} - // Adding a file to the database // TODO: Fix panic on fileadd with same filename (even if isDeleted) (UNIQUE constraint) pub async fn add_file( diff --git a/src/main.rs b/src/main.rs index 85eb3db..5caa948 100644 --- a/src/main.rs +++ b/src/main.rs @@ -479,13 +479,6 @@ async fn main() { .expect("Cleaner interval was too long to fit in a i32.... wow"), ); - // Create the tables if they don't already exist - let (filesdb, qrscandb) = tokio::join!( - db::create_filesdb(SQLITE.get().unwrap()), - db::create_qrscandb(SQLITE.get().unwrap()) - ); - - tracing::debug!("main(filesdb: {:?}, qrscandb: {:?})", filesdb, qrscandb); // Attempt to create the files directory create_dir_all("files").unwrap(); -- GitLab