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