From 1805ac94d42799c620895983b161c1e7c42aa5e7 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Wed, 12 Oct 2022 16:22:13 +0200 Subject: [PATCH] Add datetime to log --- Cargo.toml | 1 + .../2022-10-11-151321_create_history/up.sql | 15 ++++++++------- src/db.rs | 2 ++ src/models.rs | 2 ++ src/routes.rs | 4 ++++ src/schema.rs | 1 + 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a8f4c6b..31040a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ license-file = "LICENSE" [dependencies] cached = "0.39.0" +chrono = "0.4.22" diesel = { version = "2.0.2", features = [ "r2d2", "sqlite", diff --git a/migrations/2022-10-11-151321_create_history/up.sql b/migrations/2022-10-11-151321_create_history/up.sql index 3ac0996..0e910a0 100644 --- a/migrations/2022-10-11-151321_create_history/up.sql +++ b/migrations/2022-10-11-151321_create_history/up.sql @@ -1,9 +1,10 @@ CREATE TABLE hooklog ( - id INTEGER NOT NULL PRIMARY KEY, - repo_url TEXT NOT NULL, - command_with_args TEXT NOT NULL, - current_dir TEXT NOT NULL, - stdout TEXT NOT NULL, - stderr TEXT NOT NULL, - status_code INTEGER CHECK (status_code >= 0) + id INTEGER NOT NULL PRIMARY KEY, + datetime TEXT NOT NULL, + repo_url TEXT NOT NULL, + command_with_args TEXT NOT NULL, + current_dir TEXT NOT NULL, + stdout TEXT NOT NULL, + stderr TEXT NOT NULL, + status_code INTEGER CHECK (status_code >= 0) ); diff --git a/src/db.rs b/src/db.rs index b8d4522..e150973 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,3 +1,4 @@ +use chrono::Local; use diesel::prelude::*; use diesel::r2d2::{ConnectionManager, Pool}; use std::env; @@ -25,6 +26,7 @@ pub fn add_hook_log(pool: &DBPool, hook: &Hook, output: &Output) -> i32 { let command_with_args = hook.command.to_owned() + " " + &hook.args.join(" "); let new_hook_log = NewHookLog { + datetime: &Local::now().format("%d.%m.%Y %T").to_string(), repo_url: &hook.repo_url, command_with_args: &command_with_args, current_dir: &hook.current_dir, diff --git a/src/models.rs b/src/models.rs index 9aecdac..37fb694 100644 --- a/src/models.rs +++ b/src/models.rs @@ -5,6 +5,7 @@ use crate::schema::hooklog; #[derive(Queryable)] pub struct HookLog { pub id: i32, + pub datetime: String, pub repo_url: String, pub command_with_args: String, pub current_dir: String, @@ -16,6 +17,7 @@ pub struct HookLog { #[derive(Insertable)] #[diesel(table_name = hooklog)] pub struct NewHookLog<'a> { + pub datetime: &'a str, pub repo_url: &'a str, pub command_with_args: &'a str, pub current_dir: &'a str, diff --git a/src/routes.rs b/src/routes.rs index 4e5aae2..e9624fb 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -12,6 +12,9 @@ pub fn index(db_state: &State, id: i32) -> String { "Hook log id: {} +Datetime: +{} + Repository url: {} @@ -31,6 +34,7 @@ Status code: {} ", hook_log.id, + hook_log.datetime, hook_log.repo_url, hook_log.command_with_args, hook_log.current_dir, diff --git a/src/schema.rs b/src/schema.rs index c94a62f..30f5043 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -3,6 +3,7 @@ diesel::table! { hooklog (id) { id -> Integer, + datetime -> Text, repo_url -> Text, command_with_args -> Text, current_dir -> Text,