Skip to main content

bitwarden_pm/
migrations.rs

1//! Manages repository migrations for the Bitwarden SDK.
2
3use bitwarden_core::{
4    client::persisted_state::OrganizationSharedKey, key_management::UserKeyState,
5};
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(UserKeyState::data()),
21        Add(SettingItem::data()),
22        Add(OrganizationSharedKey::data()),
23    ])
24}
25
26/// Macro to create the client managed repositories for the SDK.
27/// To add a new repository, add it to the list in the macro invocation.
28/// This is meant to be used by the final application crates (e.g., bitwarden-uniffi,
29/// bitwarden-wasm-internal, bw).
30#[macro_export]
31macro_rules! create_client_managed_repositories {
32    ($container_name:ident, $macro:ident) => {
33        $macro! {
34            $container_name;
35            // List any SDK-managed repositories here. The format is:
36            // <fully qualified path to the item>, <item type idenfier>, <field name>, <name of the repository implementation>
37            ::bitwarden_vault::Cipher, Cipher, cipher, CipherRepository;
38            ::bitwarden_vault::Folder, Folder, folder, FolderRepository;
39            ::bitwarden_core::key_management::UserKeyState, UserKeyState, user_key_state, UserKeyStateRepository;
40            ::bitwarden_core::key_management::LocalUserDataKeyState, LocalUserDataKeyState, local_user_data_key_state, LocalUserDataKeyStateRepository;
41            ::bitwarden_core::key_management::EphemeralPinEnvelopeState, EphemeralPinEnvelopeState, ephemeral_pin_envelope_state, EphemeralPinEnvelopeStateRepository;
42            ::bitwarden_core::client::persisted_state::OrganizationSharedKey, OrganizationSharedKey, organization_shared_key, OrganizationSharedKeyRepository;
43        }
44    };
45}