1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use semver::Version;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

use super::migration::Migration;
use crate::version;
use crate::SettingsFile;

use super::structs::*;

#[derive(Deserialize, Serialize, Debug)]
pub struct Versioning<T: Default + Debug> {
    pub version: Version,
    #[serde(default, flatten)]
    pub data: T,
}

impl<T: Default + Debug> Versioning<T> {
    pub fn new(data: T) -> Self {
        Self {
            version: version::PACKAGE_VERSION.to_owned().parse().unwrap(),
            data,
        }
    }
}

impl<T: Default + Debug> Default for Versioning<T> {
    fn default() -> Self {
        Self {
            version: version::PACKAGE_VERSION.to_owned().parse().unwrap(),
            data: T::default(),
        }
    }
}

pub(crate) const JSON_MIGRATIONS: &[Migration<SConfig>] = &[
    Migration {
        from: || Version::parse("3.0.0-alpha.4").unwrap(),
        to: || Version::parse("3.0.0-alpha.5").unwrap(),
        up: |_, _| Ok(()),
        down: |_, _| Ok(()),
    },
    Migration {
        from: || Version::parse("3.0.0-alpha.5").unwrap(),
        to: || Version::parse("3.0.0").unwrap(),
        up: |_, _| Ok(()),
        down: |_, _| Ok(()),
    },
];

pub(crate) const SETTINGS_MIGRATIONS: &[Migration<SettingsFile>] = &[
    Migration {
        from: || Version::parse("3.0.0-alpha.4").unwrap(),
        to: || Version::parse("3.0.0-alpha.5").unwrap(),
        up: |_, _| Ok(()),
        down: |_, _| Ok(()),
    },
    Migration {
        from: || Version::parse("3.0.0-alpha.5").unwrap(),
        to: || Version::parse("3.0.0").unwrap(),
        up: |_, _| Ok(()),
        down: |_, _| Ok(()),
    },
];