diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index dc79aaf33..b3d9b2c48 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -32,6 +32,7 @@ sea-schema = { version = "0.17.0-rc", default-features = false, features = [ "writer", "probe", ] } +time = { version = "0.3.36", default-features = false, optional = true } tracing = { version = "0.1", default-features = false, features = ["log"] } tracing-subscriber = { version = "0.3.17", default-features = false, features = [ "env-filter", @@ -90,7 +91,7 @@ with-chrono = ["sea-orm/with-chrono"] with-ipnetwork = ["sea-orm/with-ipnetwork"] with-json = ["sea-orm/with-json"] with-rust_decimal = ["sea-orm/with-rust_decimal"] -with-time = ["sea-orm/with-time"] +with-time = ["time", "sea-orm/with-time"] with-uuid = ["sea-orm/with-uuid"] [patch.crates-io] diff --git a/sea-orm-migration/src/migrator.rs b/sea-orm-migration/src/migrator.rs index 01879b55a..dd4ea1ad8 100644 --- a/sea-orm-migration/src/migrator.rs +++ b/sea-orm-migration/src/migrator.rs @@ -5,7 +5,10 @@ use std::collections::HashSet; use std::fmt::Display; use std::future::Future; use std::pin::Pin; +#[cfg(not(feature = "time"))] use std::time::SystemTime; +#[cfg(feature = "time")] +use time::OffsetDateTime; use tracing::info; use sea_orm::sea_query::{ @@ -468,12 +471,16 @@ async fn exec_up_with( info!("Applying migration '{}'", migration.name()); migration.up(manager).await?; info!("Migration '{}' has been applied", migration.name()); - let now = SystemTime::now() + #[cfg(not(feature = "time"))] + let applied_at = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) - .expect("SystemTime before UNIX EPOCH!"); + .expect("SystemTime before UNIX EPOCH!") + .as_secs() as i64; + #[cfg(feature = "time")] + let applied_at = OffsetDateTime::now_utc().unix_timestamp(); seaql_migrations::Entity::insert(seaql_migrations::ActiveModel { version: ActiveValue::Set(migration.name().to_owned()), - applied_at: ActiveValue::Set(now.as_secs() as i64), + applied_at: ActiveValue::Set(applied_at), }) .table_name(migration_table_name.clone()) .exec(db)