Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update created_at & updated_at timestamp columns on update #827

Closed
billy1624 opened this issue Jun 28, 2022 · 2 comments · May be fixed by #854
Closed

Automatically update created_at & updated_at timestamp columns on update #827

billy1624 opened this issue Jun 28, 2022 · 2 comments · May be fixed by #854
Milestone

Comments

@billy1624
Copy link
Member

Motivation

This is a common feature for an ORM. Which "touch" these timestamp columns to record the last update timestamp and create at timestamp of a row.

Proposed Solutions

User can enable this feature by placing attribute on the corresponding field in the entity model.

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: String,
    #[sea_orm(updated_at)]
    pub updated_at: Option<DateTimeWithTimeZone>,
    #[sea_orm(created_at)]
    pub created_at: Option<DateTimeWithTimeZone>,
}

For insert, the value of both updated_at and created_at will be set to CURRENT_TIMESTAMP.

For update, the value of updated_at will be set to CURRENT_TIMESTAMP.

User can override this behaviour by setting the value of it explicitly, i.e. Set(xxx).

Additional Information

Related Discussions:

@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Jun 28, 2022
@billy1624 billy1624 moved this from Triage to Next Up in SeaQL Dev Tracker Jun 28, 2022
@billy1624 billy1624 added this to the 0.9.x milestone Jun 28, 2022
@tyt2y3 tyt2y3 removed this from the 0.9.x milestone Jun 30, 2022
@baoyachi
Copy link
Contributor

this feature is so useful. 👍 . I look forward to using it soon

@billy1624 billy1624 moved this from Next Up to Changes / Comments Requested in SeaQL Dev Tracker Aug 10, 2022
@billy1624 billy1624 moved this from Changes / Comments Requested to Open for Contributions in SeaQL Dev Tracker Aug 10, 2022
@billy1624 billy1624 moved this from Open for Contributions to Review in SeaQL Dev Tracker Aug 10, 2022
@billy1624 billy1624 added this to the 0.10.x milestone Aug 24, 2022
@billy1624 billy1624 moved this from Review to In Progress in SeaQL Dev Tracker Sep 22, 2022
@billy1624 billy1624 moved this from In Progress to Triage in SeaQL Dev Tracker Jan 13, 2023
@tyt2y3
Copy link
Member

tyt2y3 commented Jan 31, 2023

created_at should be an alias to on_insert = "current_timestamp". Merge into #1431

@tyt2y3 tyt2y3 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants