From b2d985790f1df65f50ee195ccab44b45315b3dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Ce=C5=A1pivo?= Date: Sat, 20 Dec 2025 21:17:46 +0100 Subject: [PATCH 1/2] Add optional time crate support for migrations Use OffsetDateTime for migration timestamps when the time feature is enabled, falling back to SystemTime otherwise. --- sea-orm-migration/Cargo.toml | 1 + sea-orm-migration/src/migrator.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 29eea62ab..9dcb6ef59 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", 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) From ee0d420564ffc7e18483987ea66c24e31abf770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Ce=C5=A1pivo?= Date: Sat, 20 Dec 2025 21:19:50 +0100 Subject: [PATCH 2/2] Add time to with-time feature --- sea-orm-migration/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 9dcb6ef59..bd863aa66 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -90,7 +90,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"] # This allows us to develop using an overridden version of sea-query