database_migration/
test_dsl.rs1use crate::config::MIGRATION_KEY_FORMAT_STR;
2use crate::migration::{ApplicableMigration, Execution, Migration, ScriptContent};
3use chrono::{DateTime, NaiveDateTime, Utc};
4use indexmap::IndexMap;
5
6pub fn key(value: &str) -> NaiveDateTime {
7 NaiveDateTime::parse_from_str(value, MIGRATION_KEY_FORMAT_STR).expect("invalid migration key")
8}
9
10pub fn datetime(value: &str) -> DateTime<Utc> {
11 DateTime::parse_from_rfc3339(value)
12 .expect("invalid RFC 3339 datetime")
13 .to_utc()
14}
15
16pub fn defined_migrations(
17 values: impl IntoIterator<Item = Migration>,
18) -> IndexMap<NaiveDateTime, Migration> {
19 values
20 .into_iter()
21 .map(|m| (m.key, m))
22 .collect::<IndexMap<_, _>>()
23}
24
25pub fn script_contents(
26 values: impl IntoIterator<Item = ScriptContent>,
27) -> IndexMap<NaiveDateTime, ScriptContent> {
28 values
29 .into_iter()
30 .map(|m| (m.key, m))
31 .collect::<IndexMap<_, _>>()
32}
33
34pub fn executed_migrations(
35 values: impl IntoIterator<Item = Execution>,
36) -> IndexMap<NaiveDateTime, Execution> {
37 values
38 .into_iter()
39 .map(|m| (m.key, m))
40 .collect::<IndexMap<_, _>>()
41}
42
43pub fn applicable_migrations(
44 values: impl IntoIterator<Item = ApplicableMigration>,
45) -> IndexMap<NaiveDateTime, ApplicableMigration> {
46 values
47 .into_iter()
48 .map(|m| (m.key, m))
49 .collect::<IndexMap<_, _>>()
50}