feat: time of models' of creation and update #22
@ -0,0 +1,5 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
|
||||||
|
ALTER TABLE "tasks" DROP COLUMN "created_at";
|
||||||
|
ALTER TABLE "tasks" DROP COLUMN "updated_at";
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
|
||||||
|
ALTER TABLE "tasks" ADD COLUMN "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
ALTER TABLE "tasks" ADD COLUMN "updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
SELECT diesel_manage_updated_at('tasks');
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
|
use chrono::NaiveDateTime;
|
||||||
use crate::models::category::Category;
|
use crate::models::category::Category;
|
||||||
use crate::schema::tasks;
|
use crate::schema::tasks;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
@ -16,6 +17,8 @@ pub struct Task {
|
|||||||
deadline: Option<chrono::NaiveDate>,
|
deadline: Option<chrono::NaiveDate>,
|
||||||
category: Category,
|
category: Category,
|
||||||
project_id: Option<i32>,
|
project_id: Option<i32>,
|
||||||
|
created_at: NaiveDateTime,
|
||||||
|
updated_at: NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
@ -38,6 +41,14 @@ impl Task {
|
|||||||
pub fn project_id(&self) -> Option<i32> {
|
pub fn project_id(&self) -> Option<i32> {
|
||||||
self.project_id
|
self.project_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn created_at(&self) -> NaiveDateTime {
|
||||||
|
self.created_at
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn updated_at(&self) -> NaiveDateTime {
|
||||||
|
self.updated_at
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
||||||
|
@ -16,6 +16,8 @@ diesel::table! {
|
|||||||
deadline -> Nullable<Date>,
|
deadline -> Nullable<Date>,
|
||||||
category -> Jsonb,
|
category -> Jsonb,
|
||||||
project_id -> Nullable<Int4>,
|
project_id -> Nullable<Int4>,
|
||||||
|
created_at -> Timestamp,
|
||||||
|
updated_at -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user