diff --git a/README.md b/README.md index fe4532fd5131309ffaf6a8125c1d07ed48552f6b..500cfc6591cc1b95588aefa26200c9cb23db0b41 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 0000000000000000000000000000000000000000..f2221873bda2b0dfd0a16bea737f2fa6f56900fd --- /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 1ddee971395bb1d11e03116258472014a92ba28d..83aa9c20473a96287fd942e83a4a5bf8b8d9e079 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 85eb3db231f0e9745919b99b7752c6b9ad2b26e1..5caa9485cfe264e3e3bcc7a06e7299c174cafec6 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();