Skip to content

Commit f7604fe

Browse files
authored
Add a datetime-default-now helper function (#3159)
I found I was writing this a lot in my migrations. So why not just put it in the library?
1 parent 90f4da0 commit f7604fe

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

sea-orm-migration/src/schema.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ pub fn date_time_uniq<T: IntoIden>(col: T) -> ColumnDef {
293293
date_time(col).unique_key().take()
294294
}
295295

296+
/// A date time column with a server-side default of 'now'.
297+
pub fn date_time_default_now<T: IntoIden>(col: T) -> ColumnDef {
298+
date_time(col).default(Expr::current_timestamp()).take()
299+
}
300+
296301
pub fn interval<T: IntoIden>(
297302
col: T,
298303
fields: Option<PgInterval>,

0 commit comments

Comments
 (0)