mz_catalog/durable/upgrade/
v78_to_v79.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
10#![allow(clippy::unwrap_used)]
11
12use crate::durable::traits::UpgradeFrom;
13use crate::durable::traits::UpgradeInto;
14use crate::durable::upgrade::MigrationAction;
15use crate::durable::upgrade::json_compatible::JsonCompatible;
16use crate::durable::upgrade::objects_v78 as v78;
17use crate::durable::upgrade::objects_v79 as v79;
18use crate::json_compatible;
19
20json_compatible!(v78::AclMode with v79::AclMode);
21json_compatible!(v78::ClusterScheduleRefreshOptions with v79::ClusterScheduleRefreshOptions);
22json_compatible!(v78::CommentValue with v79::CommentValue);
23json_compatible!(v78::DefaultPrivilegesValue with v79::DefaultPrivilegesValue);
24json_compatible!(v78::EpochMillis with v79::EpochMillis);
25json_compatible!(v78::OptimizerFeatureOverride with v79::OptimizerFeatureOverride);
26json_compatible!(v78::ReplicaConfig with v79::ReplicaConfig);
27json_compatible!(v78::ReplicaLogging with v79::ReplicaLogging);
28json_compatible!(v78::RoleAttributes with v79::RoleAttributes);
29json_compatible!(v78::RoleAuthValue with v79::RoleAuthValue);
30json_compatible!(v78::SourceReferencesValue with v79::SourceReferencesValue);
31json_compatible!(v78::StorageCollectionMetadataValue with v79::StorageCollectionMetadataValue);
32json_compatible!(v78::SystemPrivilegesValue with v79::SystemPrivilegesValue);
33json_compatible!(v78::Version with v79::Version);
34json_compatible!(v78::state_update_kind::IdAlloc with v79::IdAlloc);
35json_compatible!(v78::state_update_kind::ServerConfiguration with v79::ServerConfiguration);
36json_compatible!(v78::state_update_kind::TxnWalShard with v79::TxnWalShard);
37json_compatible!(v78::state_update_kind::UnfinalizedShard with v79::UnfinalizedShard);
38
39// These types MUST be JSON-compatible because they are de-serialized before we run the migration.
40// See `StateUpdateKindJson::is_always_deserializable`.
41json_compatible!(v78::state_update_kind::AuditLog with v79::AuditLog);
42json_compatible!(v78::state_update_kind::Config with v79::Config);
43json_compatible!(v78::state_update_kind::FenceToken with v79::FenceToken);
44json_compatible!(v78::state_update_kind::Setting with v79::Setting);
45
46pub fn upgrade(
47    snapshot: Vec<v78::StateUpdateKind>,
48) -> Vec<MigrationAction<v78::StateUpdateKind, v79::StateUpdateKind>> {
49    use v78::state_update_kind::Kind::*;
50    use v79::StateUpdateKind as Kind;
51
52    // For JSON-compatible kinds we don't need to perform a migration.
53    macro_rules! skip_json_compatible {
54        ($old_val:expr, $new_type:ty) => {{
55            let _: $new_type = JsonCompatible::convert(&$old_val);
56            return None;
57        }};
58    }
59
60    snapshot
61        .into_iter()
62        .filter_map(|old| {
63            let new = match old.kind.clone().unwrap() {
64                Cluster(x) => Kind::Cluster(x.upgrade_into()),
65                ClusterIntrospectionSourceIndex(x) => {
66                    Kind::ClusterIntrospectionSourceIndex(x.upgrade_into())
67                }
68                ClusterReplica(x) => Kind::ClusterReplica(x.upgrade_into()),
69                Comment(x) => Kind::Comment(x.upgrade_into()),
70                Database(x) => Kind::Database(x.upgrade_into()),
71                DefaultPrivileges(x) => Kind::DefaultPrivileges(x.upgrade_into()),
72                GidMapping(x) => Kind::GidMapping(x.upgrade_into()),
73                Item(x) => Kind::Item(x.upgrade_into()),
74                NetworkPolicy(x) => Kind::NetworkPolicy(x.upgrade_into()),
75                Role(x) => Kind::Role(x.upgrade_into()),
76                RoleAuth(x) => Kind::RoleAuth(x.upgrade_into()),
77                Schema(x) => Kind::Schema(x.upgrade_into()),
78                SourceReferences(x) => Kind::SourceReferences(x.upgrade_into()),
79                StorageCollectionMetadata(x) => Kind::StorageCollectionMetadata(x.upgrade_into()),
80                SystemPrivileges(x) => Kind::SystemPrivileges(x.upgrade_into()),
81
82                AuditLog(x) => skip_json_compatible!(x, v79::AuditLog),
83                Config(x) => skip_json_compatible!(x, v79::Config),
84                FenceToken(x) => skip_json_compatible!(x, v79::FenceToken),
85                IdAlloc(x) => skip_json_compatible!(x, v79::IdAlloc),
86                ServerConfiguration(x) => skip_json_compatible!(x, v79::ServerConfiguration),
87                Setting(x) => skip_json_compatible!(x, v79::Setting),
88                TxnWalShard(x) => skip_json_compatible!(x, v79::TxnWalShard),
89                UnfinalizedShard(x) => skip_json_compatible!(x, v79::UnfinalizedShard),
90            };
91            Some(MigrationAction::Update(old, new))
92        })
93        .collect()
94}
95
96impl UpgradeFrom<v78::state_update_kind::Cluster> for v79::Cluster {
97    fn upgrade_from(old: v78::state_update_kind::Cluster) -> Self {
98        Self {
99            key: old.key.unwrap().upgrade_into(),
100            value: old.value.unwrap().upgrade_into(),
101        }
102    }
103}
104
105impl UpgradeFrom<v78::ClusterKey> for v79::ClusterKey {
106    fn upgrade_from(old: v78::ClusterKey) -> Self {
107        Self {
108            id: old.id.unwrap().upgrade_into(),
109        }
110    }
111}
112
113impl UpgradeFrom<v78::ClusterValue> for v79::ClusterValue {
114    fn upgrade_from(old: v78::ClusterValue) -> Self {
115        Self {
116            name: old.name,
117            owner_id: old.owner_id.unwrap().upgrade_into(),
118            privileges: old
119                .privileges
120                .into_iter()
121                .map(UpgradeInto::upgrade_into)
122                .collect(),
123            config: old.config.unwrap().upgrade_into(),
124        }
125    }
126}
127
128impl UpgradeFrom<v78::ClusterId> for v79::ClusterId {
129    fn upgrade_from(old: v78::ClusterId) -> Self {
130        use v78::cluster_id::Value::*;
131        match old.value.unwrap() {
132            System(id) => Self::System(id),
133            User(id) => Self::User(id),
134        }
135    }
136}
137
138impl UpgradeFrom<v78::RoleId> for v79::RoleId {
139    fn upgrade_from(old: v78::RoleId) -> Self {
140        use v78::role_id::Value::*;
141        match old.value.unwrap() {
142            System(id) => Self::System(id),
143            User(id) => Self::User(id),
144            Public(_) => Self::Public,
145            Predefined(id) => Self::Predefined(id),
146        }
147    }
148}
149
150impl UpgradeFrom<v78::MzAclItem> for v79::MzAclItem {
151    fn upgrade_from(old: v78::MzAclItem) -> Self {
152        Self {
153            grantee: old.grantee.unwrap().upgrade_into(),
154            grantor: old.grantor.unwrap().upgrade_into(),
155            acl_mode: JsonCompatible::convert(&old.acl_mode.unwrap()),
156        }
157    }
158}
159
160impl UpgradeFrom<v78::ClusterConfig> for v79::ClusterConfig {
161    fn upgrade_from(old: v78::ClusterConfig) -> Self {
162        Self {
163            workload_class: old.workload_class,
164            variant: old.variant.unwrap().upgrade_into(),
165        }
166    }
167}
168
169impl UpgradeFrom<v78::cluster_config::Variant> for v79::ClusterVariant {
170    fn upgrade_from(old: v78::cluster_config::Variant) -> Self {
171        use v78::cluster_config::Variant::*;
172        match old {
173            Unmanaged(_) => Self::Unmanaged,
174            Managed(m) => Self::Managed(m.upgrade_into()),
175        }
176    }
177}
178
179impl UpgradeFrom<v78::cluster_config::ManagedCluster> for v79::ManagedCluster {
180    fn upgrade_from(old: v78::cluster_config::ManagedCluster) -> Self {
181        Self {
182            size: old.size,
183            replication_factor: old.replication_factor,
184            availability_zones: old.availability_zones,
185            logging: JsonCompatible::convert(&old.logging.unwrap()),
186            optimizer_feature_overrides: old
187                .optimizer_feature_overrides
188                .iter()
189                .map(JsonCompatible::convert)
190                .collect(),
191            schedule: old.schedule.unwrap().upgrade_into(),
192        }
193    }
194}
195
196impl UpgradeFrom<v78::ClusterSchedule> for v79::ClusterSchedule {
197    fn upgrade_from(old: v78::ClusterSchedule) -> Self {
198        use v78::cluster_schedule::Value::*;
199        match old.value.unwrap() {
200            Manual(_) => Self::Manual,
201            Refresh(r) => Self::Refresh(JsonCompatible::convert(&r)),
202        }
203    }
204}
205
206impl UpgradeFrom<v78::state_update_kind::ClusterReplica> for v79::ClusterReplica {
207    fn upgrade_from(old: v78::state_update_kind::ClusterReplica) -> Self {
208        Self {
209            key: old.key.unwrap().upgrade_into(),
210            value: old.value.unwrap().upgrade_into(),
211        }
212    }
213}
214
215impl UpgradeFrom<v78::ClusterReplicaKey> for v79::ClusterReplicaKey {
216    fn upgrade_from(old: v78::ClusterReplicaKey) -> Self {
217        Self {
218            id: old.id.unwrap().upgrade_into(),
219        }
220    }
221}
222
223impl UpgradeFrom<v78::ReplicaId> for v79::ReplicaId {
224    fn upgrade_from(old: v78::ReplicaId) -> Self {
225        use v78::replica_id::Value::*;
226        match old.value.unwrap() {
227            System(id) => Self::System(id),
228            User(id) => Self::User(id),
229        }
230    }
231}
232
233impl UpgradeFrom<v78::ClusterReplicaValue> for v79::ClusterReplicaValue {
234    fn upgrade_from(old: v78::ClusterReplicaValue) -> Self {
235        Self {
236            cluster_id: old.cluster_id.unwrap().upgrade_into(),
237            name: old.name,
238            config: JsonCompatible::convert(&old.config.unwrap()),
239            owner_id: old.owner_id.unwrap().upgrade_into(),
240        }
241    }
242}
243
244impl UpgradeFrom<v78::state_update_kind::Comment> for v79::Comment {
245    fn upgrade_from(old: v78::state_update_kind::Comment) -> Self {
246        Self {
247            key: old.key.unwrap().upgrade_into(),
248            value: JsonCompatible::convert(&old.value.unwrap()),
249        }
250    }
251}
252
253impl UpgradeFrom<v78::CommentKey> for v79::CommentKey {
254    fn upgrade_from(old: v78::CommentKey) -> Self {
255        Self {
256            object: old.object.unwrap().upgrade_into(),
257            sub_component: old.sub_component.map(UpgradeInto::upgrade_into),
258        }
259    }
260}
261
262impl UpgradeFrom<v78::comment_key::Object> for v79::CommentObject {
263    fn upgrade_from(old: v78::comment_key::Object) -> Self {
264        use v78::comment_key::Object::*;
265        match old {
266            Table(id) => Self::Table(id.upgrade_into()),
267            View(id) => Self::View(id.upgrade_into()),
268            MaterializedView(id) => Self::MaterializedView(id.upgrade_into()),
269            Source(id) => Self::Source(id.upgrade_into()),
270            Sink(id) => Self::Sink(id.upgrade_into()),
271            Index(id) => Self::Index(id.upgrade_into()),
272            Func(id) => Self::Func(id.upgrade_into()),
273            Connection(id) => Self::Connection(id.upgrade_into()),
274            Type(id) => Self::Type(id.upgrade_into()),
275            Secret(id) => Self::Secret(id.upgrade_into()),
276            ContinualTask(id) => Self::ContinualTask(id.upgrade_into()),
277            Role(id) => Self::Role(id.upgrade_into()),
278            Database(id) => Self::Database(id.upgrade_into()),
279            Schema(s) => Self::Schema(s.upgrade_into()),
280            Cluster(id) => Self::Cluster(id.upgrade_into()),
281            ClusterReplica(id) => Self::ClusterReplica(id.upgrade_into()),
282            NetworkPolicy(id) => Self::NetworkPolicy(id.upgrade_into()),
283        }
284    }
285}
286
287impl UpgradeFrom<v78::CatalogItemId> for v79::CatalogItemId {
288    fn upgrade_from(old: v78::CatalogItemId) -> Self {
289        use v78::catalog_item_id::Value::*;
290        match old.value.unwrap() {
291            System(id) => Self::System(id),
292            User(id) => Self::User(id),
293            Transient(id) => Self::Transient(id),
294            IntrospectionSourceIndex(id) => Self::IntrospectionSourceIndex(id),
295        }
296    }
297}
298
299impl UpgradeFrom<v78::DatabaseId> for v79::DatabaseId {
300    fn upgrade_from(old: v78::DatabaseId) -> Self {
301        use v78::database_id::Value::*;
302        match old.value.unwrap() {
303            System(id) => Self::System(id),
304            User(id) => Self::User(id),
305        }
306    }
307}
308
309impl UpgradeFrom<v78::ResolvedSchema> for v79::ResolvedSchema {
310    fn upgrade_from(old: v78::ResolvedSchema) -> Self {
311        Self {
312            database: old.database.unwrap().upgrade_into(),
313            schema: old.schema.unwrap().upgrade_into(),
314        }
315    }
316}
317
318impl UpgradeFrom<v78::ResolvedDatabaseSpecifier> for v79::ResolvedDatabaseSpecifier {
319    fn upgrade_from(old: v78::ResolvedDatabaseSpecifier) -> Self {
320        use v78::resolved_database_specifier::Spec::*;
321        match old.spec.unwrap() {
322            Ambient(_) => Self::Ambient,
323            Id(id) => Self::Id(id.upgrade_into()),
324        }
325    }
326}
327
328impl UpgradeFrom<v78::SchemaSpecifier> for v79::SchemaSpecifier {
329    fn upgrade_from(old: v78::SchemaSpecifier) -> Self {
330        use v78::schema_specifier::Spec::*;
331        match old.spec.unwrap() {
332            Temporary(_) => Self::Temporary,
333            Id(id) => Self::Id(id.upgrade_into()),
334        }
335    }
336}
337
338impl UpgradeFrom<v78::SchemaId> for v79::SchemaId {
339    fn upgrade_from(old: v78::SchemaId) -> Self {
340        use v78::schema_id::Value::*;
341        match old.value.unwrap() {
342            System(id) => Self::System(id),
343            User(id) => Self::User(id),
344        }
345    }
346}
347
348impl UpgradeFrom<v78::ClusterReplicaId> for v79::ClusterReplicaId {
349    fn upgrade_from(old: v78::ClusterReplicaId) -> Self {
350        Self {
351            cluster_id: old.cluster_id.unwrap().upgrade_into(),
352            replica_id: old.replica_id.unwrap().upgrade_into(),
353        }
354    }
355}
356
357impl UpgradeFrom<v78::NetworkPolicyId> for v79::NetworkPolicyId {
358    fn upgrade_from(old: v78::NetworkPolicyId) -> Self {
359        use v78::network_policy_id::Value::*;
360        match old.value.unwrap() {
361            System(id) => Self::System(id),
362            User(id) => Self::User(id),
363        }
364    }
365}
366
367impl UpgradeFrom<v78::comment_key::SubComponent> for v79::CommentSubComponent {
368    fn upgrade_from(old: v78::comment_key::SubComponent) -> Self {
369        use v78::comment_key::SubComponent::*;
370        match old {
371            ColumnPos(pos) => Self::ColumnPos(pos),
372        }
373    }
374}
375
376impl UpgradeFrom<v78::state_update_kind::Database> for v79::Database {
377    fn upgrade_from(old: v78::state_update_kind::Database) -> Self {
378        Self {
379            key: old.key.unwrap().upgrade_into(),
380            value: old.value.unwrap().upgrade_into(),
381        }
382    }
383}
384
385impl UpgradeFrom<v78::DatabaseKey> for v79::DatabaseKey {
386    fn upgrade_from(old: v78::DatabaseKey) -> Self {
387        Self {
388            id: old.id.unwrap().upgrade_into(),
389        }
390    }
391}
392
393impl UpgradeFrom<v78::DatabaseValue> for v79::DatabaseValue {
394    fn upgrade_from(old: v78::DatabaseValue) -> Self {
395        Self {
396            name: old.name,
397            owner_id: old.owner_id.unwrap().upgrade_into(),
398            privileges: old
399                .privileges
400                .into_iter()
401                .map(UpgradeInto::upgrade_into)
402                .collect(),
403            oid: old.oid,
404        }
405    }
406}
407
408impl UpgradeFrom<v78::state_update_kind::DefaultPrivileges> for v79::DefaultPrivileges {
409    fn upgrade_from(old: v78::state_update_kind::DefaultPrivileges) -> Self {
410        Self {
411            key: old.key.unwrap().upgrade_into(),
412            value: JsonCompatible::convert(&old.value.unwrap()),
413        }
414    }
415}
416
417impl UpgradeFrom<v78::DefaultPrivilegesKey> for v79::DefaultPrivilegesKey {
418    fn upgrade_from(old: v78::DefaultPrivilegesKey) -> Self {
419        Self {
420            role_id: old.role_id.unwrap().upgrade_into(),
421            database_id: old.database_id.map(UpgradeInto::upgrade_into),
422            schema_id: old.schema_id.map(UpgradeInto::upgrade_into),
423            object_type: old.object_type.upgrade_into(),
424            grantee: old.grantee.unwrap().upgrade_into(),
425        }
426    }
427}
428
429impl UpgradeFrom<i32> for v79::ObjectType {
430    fn upgrade_from(value: i32) -> Self {
431        match value {
432            0 => Self::Unknown,
433            1 => Self::Table,
434            2 => Self::View,
435            3 => Self::MaterializedView,
436            4 => Self::Source,
437            5 => Self::Sink,
438            6 => Self::Index,
439            7 => Self::Type,
440            8 => Self::Role,
441            9 => Self::Cluster,
442            10 => Self::ClusterReplica,
443            11 => Self::Secret,
444            12 => Self::Connection,
445            13 => Self::Database,
446            14 => Self::Schema,
447            15 => Self::Func,
448            16 => Self::ContinualTask,
449            17 => Self::NetworkPolicy,
450            x => panic!("invalid ObjectType: {x}"),
451        }
452    }
453}
454
455impl UpgradeFrom<v78::state_update_kind::ClusterIntrospectionSourceIndex>
456    for v79::ClusterIntrospectionSourceIndex
457{
458    fn upgrade_from(old: v78::state_update_kind::ClusterIntrospectionSourceIndex) -> Self {
459        Self {
460            key: old.key.unwrap().upgrade_into(),
461            value: old.value.unwrap().upgrade_into(),
462        }
463    }
464}
465
466impl UpgradeFrom<v78::ClusterIntrospectionSourceIndexKey>
467    for v79::ClusterIntrospectionSourceIndexKey
468{
469    fn upgrade_from(old: v78::ClusterIntrospectionSourceIndexKey) -> Self {
470        Self {
471            cluster_id: old.cluster_id.unwrap().upgrade_into(),
472            name: old.name,
473        }
474    }
475}
476
477impl UpgradeFrom<v78::ClusterIntrospectionSourceIndexValue>
478    for v79::ClusterIntrospectionSourceIndexValue
479{
480    fn upgrade_from(old: v78::ClusterIntrospectionSourceIndexValue) -> Self {
481        Self {
482            catalog_id: v79::IntrospectionSourceIndexCatalogItemId(old.index_id),
483            global_id: old.global_id.unwrap().upgrade_into(),
484            oid: old.oid,
485        }
486    }
487}
488
489impl UpgradeFrom<v78::IntrospectionSourceIndexGlobalId> for v79::IntrospectionSourceIndexGlobalId {
490    fn upgrade_from(old: v78::IntrospectionSourceIndexGlobalId) -> Self {
491        Self(old.value)
492    }
493}
494
495impl UpgradeFrom<v78::state_update_kind::Item> for v79::Item {
496    fn upgrade_from(old: v78::state_update_kind::Item) -> Self {
497        Self {
498            key: old.key.unwrap().upgrade_into(),
499            value: old.value.unwrap().upgrade_into(),
500        }
501    }
502}
503
504impl UpgradeFrom<v78::ItemKey> for v79::ItemKey {
505    fn upgrade_from(old: v78::ItemKey) -> Self {
506        Self {
507            gid: old.gid.unwrap().upgrade_into(),
508        }
509    }
510}
511
512impl UpgradeFrom<v78::ItemValue> for v79::ItemValue {
513    fn upgrade_from(old: v78::ItemValue) -> Self {
514        Self {
515            schema_id: old.schema_id.unwrap().upgrade_into(),
516            name: old.name,
517            definition: old.definition.unwrap().upgrade_into(),
518            owner_id: old.owner_id.unwrap().upgrade_into(),
519            privileges: old
520                .privileges
521                .into_iter()
522                .map(UpgradeInto::upgrade_into)
523                .collect(),
524            oid: old.oid,
525            global_id: old.global_id.unwrap().upgrade_into(),
526            extra_versions: old
527                .extra_versions
528                .into_iter()
529                .map(UpgradeInto::upgrade_into)
530                .collect(),
531        }
532    }
533}
534
535impl UpgradeFrom<v78::CatalogItem> for v79::CatalogItem {
536    fn upgrade_from(old: v78::CatalogItem) -> Self {
537        use v78::catalog_item::Value::*;
538        match old.value.unwrap() {
539            V1(v) => Self::V1(v79::CatalogItemV1 {
540                create_sql: v.create_sql,
541            }),
542        }
543    }
544}
545
546impl UpgradeFrom<v78::GlobalId> for v79::GlobalId {
547    fn upgrade_from(old: v78::GlobalId) -> Self {
548        use v78::global_id::Value::*;
549        match old.value.unwrap() {
550            System(id) => Self::System(id),
551            User(id) => Self::User(id),
552            Transient(id) => Self::Transient(id),
553            Explain(_) => Self::Explain,
554            IntrospectionSourceIndex(id) => Self::IntrospectionSourceIndex(id),
555        }
556    }
557}
558
559impl UpgradeFrom<v78::ItemVersion> for v79::ItemVersion {
560    fn upgrade_from(old: v78::ItemVersion) -> Self {
561        Self {
562            global_id: old.global_id.unwrap().upgrade_into(),
563            version: JsonCompatible::convert(&old.version.unwrap()),
564        }
565    }
566}
567
568impl UpgradeFrom<v78::state_update_kind::Role> for v79::Role {
569    fn upgrade_from(old: v78::state_update_kind::Role) -> Self {
570        Self {
571            key: old.key.unwrap().upgrade_into(),
572            value: old.value.unwrap().upgrade_into(),
573        }
574    }
575}
576
577impl UpgradeFrom<v78::RoleKey> for v79::RoleKey {
578    fn upgrade_from(old: v78::RoleKey) -> Self {
579        Self {
580            id: old.id.unwrap().upgrade_into(),
581        }
582    }
583}
584
585impl UpgradeFrom<v78::RoleValue> for v79::RoleValue {
586    fn upgrade_from(old: v78::RoleValue) -> Self {
587        Self {
588            name: old.name,
589            attributes: JsonCompatible::convert(&old.attributes.unwrap()),
590            membership: old.membership.unwrap().upgrade_into(),
591            vars: old.vars.unwrap().upgrade_into(),
592            oid: old.oid,
593        }
594    }
595}
596
597impl UpgradeFrom<v78::RoleMembership> for v79::RoleMembership {
598    fn upgrade_from(old: v78::RoleMembership) -> Self {
599        Self {
600            map: old.map.into_iter().map(UpgradeInto::upgrade_into).collect(),
601        }
602    }
603}
604
605impl UpgradeFrom<v78::role_membership::Entry> for v79::RoleMembershipEntry {
606    fn upgrade_from(old: v78::role_membership::Entry) -> Self {
607        Self {
608            key: old.key.unwrap().upgrade_into(),
609            value: old.value.unwrap().upgrade_into(),
610        }
611    }
612}
613
614impl UpgradeFrom<v78::RoleVars> for v79::RoleVars {
615    fn upgrade_from(old: v78::RoleVars) -> Self {
616        Self {
617            entries: old
618                .entries
619                .into_iter()
620                .map(UpgradeInto::upgrade_into)
621                .collect(),
622        }
623    }
624}
625
626impl UpgradeFrom<v78::role_vars::Entry> for v79::RoleVarsEntry {
627    fn upgrade_from(old: v78::role_vars::Entry) -> Self {
628        Self {
629            key: old.key,
630            val: old.val.unwrap().upgrade_into(),
631        }
632    }
633}
634
635impl UpgradeFrom<v78::role_vars::entry::Val> for v79::RoleVar {
636    fn upgrade_from(old: v78::role_vars::entry::Val) -> Self {
637        use v78::role_vars::entry::Val::*;
638        match old {
639            Flat(s) => Self::Flat(s),
640            SqlSet(s) => Self::SqlSet(s.entries),
641        }
642    }
643}
644
645impl UpgradeFrom<v78::state_update_kind::Schema> for v79::Schema {
646    fn upgrade_from(old: v78::state_update_kind::Schema) -> Self {
647        Self {
648            key: old.key.unwrap().upgrade_into(),
649            value: old.value.unwrap().upgrade_into(),
650        }
651    }
652}
653
654impl UpgradeFrom<v78::SchemaKey> for v79::SchemaKey {
655    fn upgrade_from(old: v78::SchemaKey) -> Self {
656        Self {
657            id: old.id.unwrap().upgrade_into(),
658        }
659    }
660}
661
662impl UpgradeFrom<v78::SchemaValue> for v79::SchemaValue {
663    fn upgrade_from(old: v78::SchemaValue) -> Self {
664        Self {
665            database_id: old.database_id.map(UpgradeInto::upgrade_into),
666            name: old.name,
667            owner_id: old.owner_id.unwrap().upgrade_into(),
668            privileges: old
669                .privileges
670                .into_iter()
671                .map(UpgradeInto::upgrade_into)
672                .collect(),
673            oid: old.oid,
674        }
675    }
676}
677
678impl UpgradeFrom<v78::state_update_kind::GidMapping> for v79::GidMapping {
679    fn upgrade_from(old: v78::state_update_kind::GidMapping) -> Self {
680        Self {
681            key: old.key.unwrap().upgrade_into(),
682            value: old.value.unwrap().upgrade_into(),
683        }
684    }
685}
686
687impl UpgradeFrom<v78::GidMappingKey> for v79::GidMappingKey {
688    fn upgrade_from(old: v78::GidMappingKey) -> Self {
689        Self {
690            schema_name: old.schema_name,
691            object_type: old.object_type.upgrade_into(),
692            object_name: old.object_name,
693        }
694    }
695}
696
697impl UpgradeFrom<i32> for v79::CatalogItemType {
698    fn upgrade_from(value: i32) -> Self {
699        match value {
700            0 => Self::Unknown,
701            1 => Self::Table,
702            2 => Self::Source,
703            3 => Self::Sink,
704            4 => Self::View,
705            5 => Self::MaterializedView,
706            6 => Self::Index,
707            7 => Self::Type,
708            8 => Self::Func,
709            9 => Self::Secret,
710            10 => Self::Connection,
711            11 => Self::ContinualTask,
712            x => panic!("invalid CatalogItemType: {x}"),
713        }
714    }
715}
716
717impl UpgradeFrom<v78::GidMappingValue> for v79::GidMappingValue {
718    fn upgrade_from(old: v78::GidMappingValue) -> Self {
719        Self {
720            catalog_id: v79::SystemCatalogItemId(old.id),
721            global_id: old.global_id.unwrap().upgrade_into(),
722            fingerprint: old.fingerprint,
723        }
724    }
725}
726
727impl UpgradeFrom<v78::SystemGlobalId> for v79::SystemGlobalId {
728    fn upgrade_from(old: v78::SystemGlobalId) -> Self {
729        Self(old.value)
730    }
731}
732
733impl UpgradeFrom<v78::state_update_kind::SystemPrivileges> for v79::SystemPrivileges {
734    fn upgrade_from(old: v78::state_update_kind::SystemPrivileges) -> Self {
735        Self {
736            key: old.key.unwrap().upgrade_into(),
737            value: JsonCompatible::convert(&old.value.unwrap()),
738        }
739    }
740}
741
742impl UpgradeFrom<v78::SystemPrivilegesKey> for v79::SystemPrivilegesKey {
743    fn upgrade_from(old: v78::SystemPrivilegesKey) -> Self {
744        Self {
745            grantee: old.grantee.unwrap().upgrade_into(),
746            grantor: old.grantor.unwrap().upgrade_into(),
747        }
748    }
749}
750
751impl UpgradeFrom<v78::state_update_kind::StorageCollectionMetadata>
752    for v79::StorageCollectionMetadata
753{
754    fn upgrade_from(old: v78::state_update_kind::StorageCollectionMetadata) -> Self {
755        Self {
756            key: old.key.unwrap().upgrade_into(),
757            value: JsonCompatible::convert(&old.value.unwrap()),
758        }
759    }
760}
761
762impl UpgradeFrom<v78::StorageCollectionMetadataKey> for v79::StorageCollectionMetadataKey {
763    fn upgrade_from(old: v78::StorageCollectionMetadataKey) -> Self {
764        Self {
765            id: old.id.unwrap().upgrade_into(),
766        }
767    }
768}
769
770impl UpgradeFrom<v78::state_update_kind::SourceReferences> for v79::SourceReferences {
771    fn upgrade_from(old: v78::state_update_kind::SourceReferences) -> Self {
772        Self {
773            key: old.key.unwrap().upgrade_into(),
774            value: JsonCompatible::convert(&old.value.unwrap()),
775        }
776    }
777}
778
779impl UpgradeFrom<v78::SourceReferencesKey> for v79::SourceReferencesKey {
780    fn upgrade_from(old: v78::SourceReferencesKey) -> Self {
781        Self {
782            source: old.source.unwrap().upgrade_into(),
783        }
784    }
785}
786
787impl UpgradeFrom<v78::state_update_kind::NetworkPolicy> for v79::NetworkPolicy {
788    fn upgrade_from(old: v78::state_update_kind::NetworkPolicy) -> Self {
789        Self {
790            key: old.key.unwrap().upgrade_into(),
791            value: old.value.unwrap().upgrade_into(),
792        }
793    }
794}
795
796impl UpgradeFrom<v78::NetworkPolicyKey> for v79::NetworkPolicyKey {
797    fn upgrade_from(old: v78::NetworkPolicyKey) -> Self {
798        Self {
799            id: old.id.unwrap().upgrade_into(),
800        }
801    }
802}
803
804impl UpgradeFrom<v78::NetworkPolicyValue> for v79::NetworkPolicyValue {
805    fn upgrade_from(old: v78::NetworkPolicyValue) -> Self {
806        Self {
807            name: old.name,
808            rules: old
809                .rules
810                .into_iter()
811                .map(UpgradeInto::upgrade_into)
812                .collect(),
813            owner_id: old.owner_id.unwrap().upgrade_into(),
814            privileges: old
815                .privileges
816                .into_iter()
817                .map(UpgradeInto::upgrade_into)
818                .collect(),
819            oid: old.oid,
820        }
821    }
822}
823
824impl UpgradeFrom<v78::NetworkPolicyRule> for v79::NetworkPolicyRule {
825    fn upgrade_from(old: v78::NetworkPolicyRule) -> Self {
826        Self {
827            name: old.name,
828            address: old.address,
829            action: old.action.unwrap().upgrade_into(),
830            direction: old.direction.unwrap().upgrade_into(),
831        }
832    }
833}
834
835impl UpgradeFrom<v78::network_policy_rule::Action> for v79::NetworkPolicyRuleAction {
836    fn upgrade_from(old: v78::network_policy_rule::Action) -> Self {
837        use v78::network_policy_rule::Action::*;
838        match old {
839            Allow(_) => Self::Allow,
840        }
841    }
842}
843
844impl UpgradeFrom<v78::network_policy_rule::Direction> for v79::NetworkPolicyRuleDirection {
845    fn upgrade_from(old: v78::network_policy_rule::Direction) -> Self {
846        use v78::network_policy_rule::Direction::*;
847        match old {
848            Ingress(_) => Self::Ingress,
849        }
850    }
851}
852
853impl UpgradeFrom<v78::state_update_kind::RoleAuth> for v79::RoleAuth {
854    fn upgrade_from(old: v78::state_update_kind::RoleAuth) -> Self {
855        Self {
856            key: old.key.unwrap().upgrade_into(),
857            value: JsonCompatible::convert(&old.value.unwrap()),
858        }
859    }
860}
861
862impl UpgradeFrom<v78::RoleAuthKey> for v79::RoleAuthKey {
863    fn upgrade_from(old: v78::RoleAuthKey) -> Self {
864        Self {
865            id: old.id.unwrap().upgrade_into(),
866        }
867    }
868}