Skip to main content

bitwarden_pm/
migrations.rs

1//! Manages repository migrations for the Bitwarden SDK.
2
3use bitwarden_core::client::persisted_state::OrganizationSharedKey;
4use bitwarden_organizations::ProfileOrganization;
5use bitwarden_policies::Policy;
6use bitwarden_send::Send;
7use bitwarden_state::{
8    SettingItem,
9    repository::{RepositoryItem, RepositoryMigrationStep, RepositoryMigrations},
10};
11use bitwarden_vault::{Cipher, Folder};
12
13/// Returns a list of all SDK-managed repository migrations.
14pub fn get_sdk_managed_migrations() -> RepositoryMigrations {
15    use RepositoryMigrationStep::*;
16    RepositoryMigrations::new(vec![
17        // Add any new migrations here. Note that order matters, and that removing a repository
18        // requires a separate migration step using `Remove(...)`.
19        Add(Cipher::data()),
20        Add(Folder::data()),
21        Add(SettingItem::data()),
22        Add(OrganizationSharedKey::data()),
23        Add(Send::data()),
24        Add(Policy::data()),
25        Add(ProfileOrganization::data()),
26    ])
27}
28
29/// Macro to create the client managed repositories for the SDK.
30/// To add a new repository, add it to the list in the macro invocation.
31/// This is meant to be used by the final application crates (e.g., bitwarden-uniffi,
32/// bitwarden-wasm-internal, bw).
33#[macro_export]
34macro_rules! create_client_managed_repositories {
35    ($container_name:ident, $macro:ident) => {
36        $macro! {
37            $container_name;
38            // List any SDK-managed repositories here. The format is:
39            // <fully qualified path to the item>, <item type idenfier>, <field name>, <name of the repository implementation>
40            ::bitwarden_vault::Cipher, Cipher, cipher, CipherRepository;
41            ::bitwarden_vault::Folder, Folder, folder, FolderRepository;
42            ::bitwarden_core::key_management::LocalUserDataKeyState, LocalUserDataKeyState, local_user_data_key_state, LocalUserDataKeyStateRepository;
43            ::bitwarden_core::client::persisted_state::OrganizationSharedKey, OrganizationSharedKey, organization_shared_key, OrganizationSharedKeyRepository;
44            ::bitwarden_send::Send, Send, send, SendRepository;
45            ::bitwarden_policies::Policy, Policy, policy, PolicyRepository;
46            ::bitwarden_organizations::ProfileOrganization, ProfileOrganization, organization, ProfileOrganizationRepository;
47        }
48    };
49}