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
65
66
67
68
69
70
71
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use crateStep;
/// The migrations of a plugin's `plugin_config` and `columns_config`, whose
/// [`Step::at`] versions are the Perspective release that wrote a token rather
/// than releases of the plugin itself.
///
/// # Example
///
/// ```
/// use perspective_migrate::{Kind, Migrator, PluginMigration, Step, StepCx, Version};
/// use serde_json::{Map, Value, json};
///
/// struct Sparkline;
///
/// fn rename_width(
/// token: &mut Map<String, Value>,
/// _cx: &mut StepCx,
/// ) -> Result<(), perspective_migrate::MigrateError> {
/// if let Some(Value::Object(config)) = token.get_mut("plugin_config")
/// && let Some(width) = config.remove("width")
/// {
/// config.insert("line_width".to_owned(), width);
/// }
///
/// Ok(())
/// }
///
/// impl PluginMigration for Sparkline {
/// fn plugins(&self) -> &[&'static str] {
/// &["Sparkline"]
/// }
///
/// fn steps(&self) -> Vec<Step> {
/// vec![Step {
/// at: Version::new(3, 0, 0),
/// id: "sparkline.line_width",
/// apply: rename_width,
/// }]
/// }
/// }
///
/// let migrated = Migrator::new()
/// .with_plugin(Sparkline)
/// .migrate(Kind::Viewer, None, json!({
/// "version": "2.10.0",
/// "plugin": "Sparkline",
/// "plugin_config": {"width": 2}
/// }))
/// .unwrap();
///
/// assert_eq!(migrated.value["plugin_config"], json!({"line_width": 2}));
/// ```