mz_catalog/durable/upgrade/
v76_to_v77.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use crate::durable::traits::UpgradeFrom;
11use crate::durable::upgrade::MigrationAction;
12use crate::durable::upgrade::objects_v76 as v76;
13
14/// This upgrade doesn't change any protos, simply retroactively marks mz_system as login
15pub fn upgrade(
16    snapshot: Vec<v76::StateUpdateKind>,
17) -> Vec<MigrationAction<v76::StateUpdateKind, v76::StateUpdateKind>> {
18    let mut migrations = Vec::new();
19    for update in snapshot {
20        match update.kind {
21            Some(v76::state_update_kind::Kind::Role(old_role)) => {
22                let new_role = v76::state_update_kind::Role::upgrade_from(old_role.clone());
23                let old_role = v76::StateUpdateKind {
24                    kind: Some(v76::state_update_kind::Kind::Role(old_role)),
25                };
26                let new_role = v76::StateUpdateKind {
27                    kind: Some(v76::state_update_kind::Kind::Role(new_role)),
28                };
29                let migration = MigrationAction::Update(old_role, new_role);
30                migrations.push(migration);
31            }
32            _ => {}
33        }
34    }
35    migrations
36}
37
38impl UpgradeFrom<v76::state_update_kind::Role> for v76::state_update_kind::Role {
39    fn upgrade_from(value: v76::state_update_kind::Role) -> Self {
40        let new_key = value.key;
41
42        let is_mz_system = value
43            .value
44            .as_ref()
45            .map_or(false, |v| v.name == "mz_system");
46
47        let mut new_value = value.value.map(|value| v76::RoleValue {
48            name: value.name,
49            oid: value.oid,
50            attributes: value.attributes,
51            membership: value.membership,
52            vars: value.vars,
53        });
54
55        if is_mz_system {
56            if let Some(ref mut value) = new_value {
57                if let Some(ref mut attrs) = value.attributes {
58                    attrs.login = Some(true);
59                }
60            }
61        }
62
63        v76::state_update_kind::Role {
64            key: new_key,
65            value: new_value,
66        }
67    }
68}