From add9dd012f5bc704c32ad3708656ba576f665651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 6 Sep 2020 12:32:17 +0200 Subject: [PATCH] update models, fix build, add chrono --- Cargo.lock | 3 +++ Cargo.toml | 6 ++++-- migrations/upend/00_initial_structure/up.sql | 2 +- src/dataops.rs | 2 ++ src/models.rs | 3 +++ src/schema.rs | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc529f1..9c72870 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,6 +481,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -567,6 +568,7 @@ version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_derives 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "libsqlite3-sys 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1720,6 +1722,7 @@ dependencies = [ "actix_derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "anyhow 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 72f025a..a036d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,10 @@ env_logger = "0.7.1" anyhow = "1.0" -diesel = { version = "1.4.4", features=["sqlite", "r2d2"] } -diesel_migrations = "1.4.0" +diesel = { version = "1.4", features=["sqlite", "r2d2", "chrono"] } +diesel_migrations = "1.4" + +chrono = { version = "0.4", features = ["serde"] } actix = "0.9.0" actix-web = "2.0" diff --git a/migrations/upend/00_initial_structure/up.sql b/migrations/upend/00_initial_structure/up.sql index 359e8ff..c3bf5ac 100644 --- a/migrations/upend/00_initial_structure/up.sql +++ b/migrations/upend/00_initial_structure/up.sql @@ -3,7 +3,7 @@ CREATE TABLE files ( hash VARCHAR NOT NULL, path VARCHAR NOT NULL, size BIGINT NOT NULL, - ts DATETIME NOT NULL, + created DATETIME NOT NULL, valid BOOLEAN NOT NULL DEFAULT TRUE ); diff --git a/src/dataops.rs b/src/dataops.rs index 4963cd9..1aa317f 100644 --- a/src/dataops.rs +++ b/src/dataops.rs @@ -9,6 +9,7 @@ use tiny_keccak::{Hasher, KangarooTwelve}; use walkdir::WalkDir; use actix::prelude::*; +use chrono::prelude::*; // use rayon::prelude::*; // pub struct VaultUpdater( @@ -68,6 +69,7 @@ pub async fn update_directory>( .to_string(), hash: digest.unwrap().unwrap(), size, + created: NaiveDateTime::from_timestamp(Utc::now().timestamp(), 0), }; let _insert_result = db_executor diff --git a/src/models.rs b/src/models.rs index de9f4c4..28dce4d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,5 @@ use super::schema::files; +use chrono::NaiveDateTime; use serde::Serialize; #[derive(Queryable, Serialize)] @@ -7,6 +8,7 @@ pub struct File { pub hash: String, pub path: String, pub size: i64, + pub created: NaiveDateTime, pub valid: bool, } @@ -16,4 +18,5 @@ pub struct NewFile { pub hash: String, pub path: String, pub size: i64, + pub created: NaiveDateTime, } diff --git a/src/schema.rs b/src/schema.rs index d1d9a14..8637e4d 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -13,7 +13,7 @@ table! { hash -> Text, path -> Text, size -> BigInt, - ts -> Timestamp, + created -> Timestamp, valid -> Bool, } }