Skip to content

Commit

Permalink
switch chrono for time fixes rust-db#191
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Dec 6, 2021
1 parent 52a6d2e commit da4abba
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased - 2021-10-16
### Changed
- replace `chrono` with `time`, fixes [191](https://github.com/rust-db/refinery/issues/191)

## [0.7.0] - 2021-10-16
### Added
- Add `Target::Fake` and `Target::FakeVersion` to allow users to only update refinery's schema migration table without actually running the migration files
Expand Down
2 changes: 1 addition & 1 deletion refinery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ futures = "0.3"
assert_cmd = "2.0"
predicates = "2"
tempfile = "3"
chrono = "0.4"
time = "0.3.5"
tokio-util = { version = "0.6.7", features = ["compat"] }
tokio = { version = "1.9.0", features = ["full"] }
17 changes: 13 additions & 4 deletions refinery/tests/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use barrel::backend::MySql as Sql;
#[cfg(feature = "mysql")]
mod mysql {
use assert_cmd::prelude::*;
use chrono::Local;
use mysql::prelude::TextQuery;
use predicates::str::contains;
use refinery::embed_migrations;
Expand All @@ -14,6 +13,7 @@ mod mysql {
};
use refinery_core::mysql;
use std::process::Command;
use time::OffsetDateTime;

mod embedded {
use refinery::embed_migrations;
Expand Down Expand Up @@ -210,7 +210,10 @@ mod mysql {
let current = conn.get_last_applied_migration().unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
});
}

Expand All @@ -231,7 +234,10 @@ mod mysql {
let current = conn.get_last_applied_migration().unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
});
}

Expand All @@ -253,7 +259,10 @@ mod mysql {
let migrations = get_migrations();
let applied_migrations = err.report().unwrap().applied_migrations();

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
assert_eq!(2, current.version());
assert_eq!(2, applied_migrations.len());

Expand Down
17 changes: 13 additions & 4 deletions refinery/tests/mysql_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use barrel::backend::MySql as Sql;

#[cfg(feature = "mysql_async")]
mod mysql_async {
use chrono::Local;
use futures::FutureExt;
use refinery::{
config::{Config, ConfigDbType},
Expand All @@ -13,6 +12,7 @@ mod mysql_async {
use refinery_core::mysql_async;
use refinery_core::mysql_async::prelude::Queryable;
use std::panic::AssertUnwindSafe;
use time::OffsetDateTime;

fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");
Expand Down Expand Up @@ -237,7 +237,10 @@ mod mysql_async {
let current = pool.get_last_applied_migration().await.unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand All @@ -257,7 +260,10 @@ mod mysql_async {
let current = pool.get_last_applied_migration().await.unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand All @@ -276,7 +282,10 @@ mod mysql_async {
let migrations = get_migrations();
let applied_migrations = err.report().unwrap().applied_migrations();

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
assert_eq!(2, current.version());
assert_eq!(2, applied_migrations.len());

Expand Down
17 changes: 13 additions & 4 deletions refinery/tests/rusqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use barrel::backend::Sqlite as Sql;
#[cfg(feature = "rusqlite")]
mod rusqlite {
use assert_cmd::prelude::*;
use chrono::Local;
use predicates::str::contains;
use refinery::{
config::{Config, ConfigDbType},
Expand All @@ -15,6 +14,7 @@ mod rusqlite {
use refinery_core::rusqlite::{Connection, OptionalExtension};
use std::fs::{self, File};
use std::process::Command;
use time::OffsetDateTime;

mod embedded {
use refinery::embed_migrations;
Expand Down Expand Up @@ -188,7 +188,10 @@ mod rusqlite {

assert_eq!(4, current.version());

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
}

#[test]
Expand All @@ -204,7 +207,10 @@ mod rusqlite {

assert_eq!(4, current.version());

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
}

#[test]
Expand All @@ -220,7 +226,10 @@ mod rusqlite {
let migrations = get_migrations();
let applied_migrations = err.report().unwrap().applied_migrations();

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
assert_eq!(2, current.version());
assert_eq!(2, applied_migrations.len());

Expand Down
17 changes: 13 additions & 4 deletions refinery/tests/tiberius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use barrel::backend::MsSql as Sql;
#[cfg(all(feature = "tiberius-config"))]
mod tiberius {
use assert_cmd::prelude::*;
use chrono::Local;
use futures::FutureExt;
use predicates::str::contains;
use refinery::{
Expand All @@ -14,6 +13,7 @@ mod tiberius {
use std::panic::AssertUnwindSafe;
use std::process::Command;
use std::str::FromStr;
use time::OffsetDateTime;
use tokio_util::compat::TokioAsyncWriteCompatExt;

const CONFIG: &'static str = "mssql://SA:Passw0rd@localhost:1433/refinery_test?trust_cert=true";
Expand Down Expand Up @@ -512,7 +512,10 @@ mod tiberius {

let current = client.get_last_applied_migration().await.unwrap().unwrap();
assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand Down Expand Up @@ -543,7 +546,10 @@ mod tiberius {

let current = client.get_last_applied_migration().await.unwrap().unwrap();
assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand Down Expand Up @@ -574,7 +580,10 @@ mod tiberius {
let migrations = get_migrations();
let applied_migrations = err.report().unwrap().applied_migrations();

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
assert_eq!(2, current.version());
assert_eq!(2, applied_migrations.len());

Expand Down
17 changes: 13 additions & 4 deletions refinery/tests/tokio_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use barrel::backend::Pg as Sql;

#[cfg(feature = "tokio-postgres")]
mod tokio_postgres {
use chrono::Local;
use futures::FutureExt;
use refinery::{
config::{Config, ConfigDbType},
Expand All @@ -13,6 +12,7 @@ mod tokio_postgres {
use refinery_core::tokio_postgres;
use refinery_core::tokio_postgres::NoTls;
use std::panic::AssertUnwindSafe;
use time::OffsetDateTime;

fn get_migrations() -> Vec<Migration> {
embed_migrations!("./tests/migrations");
Expand Down Expand Up @@ -294,7 +294,10 @@ mod tokio_postgres {
let current = client.get_last_applied_migration().await.unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand All @@ -320,7 +323,10 @@ mod tokio_postgres {
let current = client.get_last_applied_migration().await.unwrap().unwrap();

assert_eq!(4, current.version());
assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
})
.await
}
Expand All @@ -346,7 +352,10 @@ mod tokio_postgres {
let migrations = get_migrations();
let applied_migrations = err.report().unwrap().applied_migrations();

assert_eq!(Local::today(), current.applied_on().unwrap().date());
assert_eq!(
OffsetDateTime::now_utc().date(),
current.applied_on().unwrap().date()
);
assert_eq!(2, current.version());
assert_eq!(2, applied_migrations.len());

Expand Down
2 changes: 1 addition & 1 deletion refinery_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mysql_async = ["mysql-async-driver", "tokio"]
[dependencies]
async-trait = "0.1"
cfg-if = "1.0"
chrono = "0.4"
lazy_static = "1"
log = "0.4"
regex = "1"
Expand All @@ -39,6 +38,7 @@ tokio = { version = "1.0", features = ["full"], optional = true }
tiberius-driver = { package = "tiberius", version = "0.6", optional = true }
futures = { version = "0.3.16", optional = true }
tokio-util = { version = "0.6.7", features = ["compat"], optional = true }
time = { version = "0.3.5", features = ["parsing", "formatting"] }

[dev-dependencies]
barrel = { git = "https://github.com/jxs/barrel", features = ["sqlite3", "pg", "mysql", "mssql"] }
Expand Down
8 changes: 4 additions & 4 deletions refinery_core/src/drivers/mysql.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::traits::sync::{Migrate, Query, Transaction};
use crate::Migration;
use chrono::{DateTime, Local};
use mysql::{
error::Error as MError, prelude::Queryable, Conn, IsolationLevel, PooledConn,
Transaction as MTransaction, TxOpts,
};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;

fn get_tx_opts() -> TxOpts {
TxOpts::default()
Expand All @@ -23,9 +24,8 @@ fn query_applied_migrations(
let row = row?;
let version = row.get(0).unwrap();
let applied_on: String = row.get(2).unwrap();
let applied_on = DateTime::parse_from_rfc3339(&applied_on)
.unwrap()
.with_timezone(&Local);
// Safe to call unwrap, as we stored it in RFC3339 format on the database
let applied_on = OffsetDateTime::parse(&applied_on, &Rfc3339).unwrap();
let checksum: String = row.get(3).unwrap();

applied.push(Migration::applied(
Expand Down
8 changes: 4 additions & 4 deletions refinery_core/src/drivers/mysql_async.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::traits::r#async::{AsyncMigrate, AsyncQuery, AsyncTransaction};
use crate::Migration;
use async_trait::async_trait;
use chrono::{DateTime, Local};
use mysql_async_driver::{
prelude::Queryable, Error as MError, IsolationLevel, Pool, Transaction as MTransaction, TxOpts,
};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;

async fn query_applied_migrations<'a>(
mut transaction: MTransaction<'a>,
Expand All @@ -18,9 +19,8 @@ async fn query_applied_migrations<'a>(
let (version, name, applied_on, checksum): (i32, String, String, String) =
mysql_async_driver::from_row(row);

let applied_on = DateTime::parse_from_rfc3339(&applied_on)
.unwrap()
.with_timezone(&Local);
// Safe to call unwrap, as we stored it in RFC3339 format on the database
let applied_on = OffsetDateTime::parse(&applied_on, &Rfc3339).unwrap();
Migration::applied(
version,
name,
Expand Down
9 changes: 5 additions & 4 deletions refinery_core/src/drivers/postgres.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::traits::sync::{Migrate, Query, Transaction};
use crate::Migration;
use chrono::{DateTime, Local};
use postgres::{Client as PgClient, Error as PgError, Transaction as PgTransaction};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;

fn query_applied_migrations(
transaction: &mut PgTransaction,
Expand All @@ -12,9 +13,9 @@ fn query_applied_migrations(
for row in rows.into_iter() {
let version = row.get(0);
let applied_on: String = row.get(2);
let applied_on = DateTime::parse_from_rfc3339(&applied_on)
.unwrap()
.with_timezone(&Local);
// Safe to call unwrap, as we stored it in RFC3339 format on the database
let applied_on = OffsetDateTime::parse(&applied_on, &Rfc3339).unwrap();

let checksum: String = row.get(3);

applied.push(Migration::applied(
Expand Down
8 changes: 4 additions & 4 deletions refinery_core/src/drivers/rusqlite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::traits::sync::{Migrate, Query, Transaction};
use crate::Migration;
use chrono::{DateTime, Local};
use rusqlite::{Connection as RqlConnection, Error as RqlError};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;

fn query_applied_migrations(
transaction: &RqlConnection,
Expand All @@ -13,9 +14,8 @@ fn query_applied_migrations(
while let Some(row) = rows.next()? {
let version = row.get(0)?;
let applied_on: String = row.get(2)?;
let applied_on = DateTime::parse_from_rfc3339(&applied_on)
.unwrap()
.with_timezone(&Local);
// Safe to call unwrap, as we stored it in RFC3339 format on the database
let applied_on = OffsetDateTime::parse(&applied_on, &Rfc3339).unwrap();

let checksum: String = row.get(3)?;
applied.push(Migration::applied(
Expand Down

0 comments on commit da4abba

Please sign in to comment.