|
@@ -1,132 +0,0 @@
|
|
-#![cfg(feature = "migrate")]
|
|
|
|
-
|
|
|
|
-use microrm::{
|
|
|
|
- prelude::*,
|
|
|
|
- schema::migrate::{Migration, Migrator},
|
|
|
|
- ConnectionPool,
|
|
|
|
-};
|
|
|
|
-use test_log::test;
|
|
|
|
-
|
|
|
|
-mod common;
|
|
|
|
-
|
|
|
|
-mod s1 {
|
|
|
|
- use microrm::prelude::*;
|
|
|
|
- #[derive(Entity)]
|
|
|
|
- pub struct E {
|
|
|
|
- pub val: String,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[derive(Default, Schema)]
|
|
|
|
- pub struct S {
|
|
|
|
- pub emap: microrm::IDMap<E>,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-use s1::{E as E1, S as S1};
|
|
|
|
-
|
|
|
|
-mod s2 {
|
|
|
|
- use microrm::prelude::*;
|
|
|
|
- #[derive(PartialEq, Entity)]
|
|
|
|
- pub struct E {
|
|
|
|
- pub val: String,
|
|
|
|
- pub other_val: String,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[derive(Default, Schema)]
|
|
|
|
- pub struct S {
|
|
|
|
- pub emap: microrm::IDMap<E>,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-use s2::{E as E2, S as S2};
|
|
|
|
-
|
|
|
|
-#[derive(Default)]
|
|
|
|
-struct S1S2;
|
|
|
|
-
|
|
|
|
-impl Migration for S1S2 {
|
|
|
|
- type OldSchema = S1;
|
|
|
|
- type NewSchema = S2;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[test]
|
|
|
|
-fn from_empty() {
|
|
|
|
- let cpool = common::open_test_pool!();
|
|
|
|
- let mut lease = cpool.acquire().unwrap();
|
|
|
|
-
|
|
|
|
- let mut migrator = Migrator::new::<S1>();
|
|
|
|
- migrator.add::<S1S2>();
|
|
|
|
-
|
|
|
|
- migrator.apply(&mut lease).unwrap();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[test]
|
|
|
|
-fn multistep_schema() {
|
|
|
|
- let cpool = common::open_test_pool!();
|
|
|
|
- let mut lease = cpool.acquire().unwrap();
|
|
|
|
-
|
|
|
|
- // first apply S1
|
|
|
|
- let mut migrator = Migrator::new::<S1>();
|
|
|
|
- migrator.apply(&mut lease).unwrap();
|
|
|
|
-
|
|
|
|
- // then apply S1S2
|
|
|
|
- migrator.add::<S1S2>();
|
|
|
|
- migrator.apply(&mut lease).unwrap();
|
|
|
|
-
|
|
|
|
- S2::default()
|
|
|
|
- .emap
|
|
|
|
- .insert(
|
|
|
|
- &mut lease,
|
|
|
|
- E2 {
|
|
|
|
- val: String::from("some_val"),
|
|
|
|
- other_val: String::from("some_other_val"),
|
|
|
|
- },
|
|
|
|
- )
|
|
|
|
- .unwrap();
|
|
|
|
-
|
|
|
|
- let all_entities = S2::default().emap.get(&mut lease).unwrap();
|
|
|
|
- assert_eq!(
|
|
|
|
- all_entities
|
|
|
|
- .into_iter()
|
|
|
|
- .map(|v| v.wrapped())
|
|
|
|
- .collect::<Vec<_>>(),
|
|
|
|
- vec![E2 {
|
|
|
|
- val: String::from("some_val"),
|
|
|
|
- other_val: String::from("some_other_val")
|
|
|
|
- },]
|
|
|
|
- );
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[test]
|
|
|
|
-fn migrated_data() {
|
|
|
|
- let cpool = common::open_test_pool!(); // ConnectionPool::new(":memory:").unwrap();
|
|
|
|
- let mut lease = cpool.acquire().unwrap();
|
|
|
|
-
|
|
|
|
- // first apply S1
|
|
|
|
- let mut migrator = Migrator::new::<S1>();
|
|
|
|
- migrator.apply(&mut lease).unwrap();
|
|
|
|
-
|
|
|
|
- // add some data
|
|
|
|
- S1::default()
|
|
|
|
- .emap
|
|
|
|
- .insert(
|
|
|
|
- &mut lease,
|
|
|
|
- E1 {
|
|
|
|
- val: String::from("some_val"),
|
|
|
|
- },
|
|
|
|
- )
|
|
|
|
- .unwrap();
|
|
|
|
-
|
|
|
|
- // then apply S1S2
|
|
|
|
- migrator.add::<S1S2>();
|
|
|
|
- migrator.apply(&mut lease).unwrap();
|
|
|
|
-
|
|
|
|
- let all_entities = S2::default().emap.get(&mut lease).unwrap();
|
|
|
|
- assert_eq!(
|
|
|
|
- all_entities
|
|
|
|
- .into_iter()
|
|
|
|
- .map(|v| v.wrapped())
|
|
|
|
- .collect::<Vec<_>>(),
|
|
|
|
- vec![E2 {
|
|
|
|
- val: String::from("some_val"),
|
|
|
|
- other_val: String::from("migrated_value")
|
|
|
|
- },]
|
|
|
|
- );
|
|
|
|
-}
|
|
|