Skip to content

feature: support import user data with multiple workspaces #7822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

appflowy
Copy link
Contributor

@appflowy appflowy commented Apr 24, 2025

Feature Preview


PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

Summary by Sourcery

Add support for importing user data across multiple workspaces, including preview and import functionality for AppFlowy user data

New Features:

  • Implement preview functionality for user data import
  • Add support for importing user data with multiple workspaces
  • Create new event handlers for previewing and importing user data

Enhancements:

  • Refactor migration methods to support multi-workspace import
  • Extend user data import infrastructure to handle complex import scenarios

Chores:

  • Update event mapping to include new import-related events
  • Add new data structures to support user data import process

Copy link
Contributor

sourcery-ai bot commented Apr 24, 2025

Reviewer's Guide by Sourcery

This pull request introduces the functionality to import user data with multiple workspaces. It includes new protobuf definitions for handling user data, modifications to user data migrations, new event handlers, and a new module for managing the import process. The changes also involve updating functions to use user ID and workspace ID directly, instead of a session object.

Sequence diagram for previewing user data folder

sequenceDiagram
    participant FE as Frontend
    participant BE as Backend
    participant UM as UserManager

    FE->>BE: PreviewAppFlowyUserData(UserDataPathPB)
    BE->>UM: preview_user_data_folder_handler(UserDataPathPB)
    UM->>UM: user_data_preview(path)
    UM-->>BE: UserDataPreviewPB
    BE-->>FE: UserDataPreviewPB
Loading

Sequence diagram for importing user data folder

sequenceDiagram
    participant FE as Frontend
    participant BE as Backend
    participant UM as UserManager

    FE->>BE: ImportAppFlowyUserData(ImportUserDataPB)
    BE->>UM: import_user_data_folder_handler(ImportUserDataPB, UserManager)
    UM->>UM: get_import_user_data(ImportUserDataPB, version)
    UM->>UM: import_user_data(ImportedUserData)
    UM-->>BE: Result<(), FlowyError>
    BE-->>FE: Result<(), FlowyError>
Loading

Updated class diagram for Import Data Entities

classDiagram
    class ImportAppFlowyDataPB {
        path: String
        parent_view_id: Option<String>
    }

    class UserDataPathPB {
        path: String
    }

    class ImportUserDataPB {
        path: String
        parent_view_id: Option<String>
        workspaces: Vec<WorkspaceDataPreviewPB>
    }

    class WorkspaceDataPreviewPB {
        name: String
        created_at: i64
        workspace_id: String
        workspace_database_id: String
    }

    class UserDataPreviewPB {
        user_name: String
        workspaces: Vec<WorkspaceDataPreviewPB>
    }

    ImportUserDataPB -- WorkspaceDataPreviewPB : contains
    UserDataPreviewPB -- WorkspaceDataPreviewPB : contains
Loading

File-Level Changes

Change Details Files
Introduces new protobuf structures for handling user data import, including definitions for user data paths, import configurations, workspace data previews, and user data previews.
  • Adds UserDataPathPB for specifying the path to user data.
  • Adds ImportUserDataPB for configuring user data import, including path, parent view ID, and workspace data.
  • Adds WorkspaceDataPreviewPB for previewing workspace data with name, creation timestamp, workspace ID, and workspace database ID.
  • Adds UserDataPreviewPB for previewing user data, including user name and workspace data.
frontend/rust-lib/flowy-user/src/entities/import_data.rs
Modifies user data migrations to accept user ID and workspace ID as separate parameters, instead of a session object.
  • Updates the run method signature in FavoriteV1AndWorkspaceArrayMigration to accept uid and workspace_id.
  • Updates the run method signature in WorkspaceTrashMapToSectionMigration to accept uid and workspace_id.
  • Updates the run method signature in HistoricalEmptyDocumentMigration to accept uid and workspace_id.
frontend/rust-lib/flowy-user/src/migrations/workspace_and_favorite_v1.rs
frontend/rust-lib/flowy-user/src/migrations/workspace_trash_v1.rs
frontend/rust-lib/flowy-user/src/migrations/document_empty_content.rs
Adds functions to select user ID and user name from the database.
  • Adds select_user_id to retrieve the user ID from the user_table.
  • Adds select_user_name to retrieve the user name from the user_table based on the user ID.
frontend/rust-lib/flowy-user-pub/src/sql/user_sql.rs
Implements new event handlers for previewing and importing user data folders.
  • Adds preview_user_data_folder_handler to handle previewing user data from a folder.
  • Adds import_user_data_folder_handler to handle importing user data from a folder.
frontend/rust-lib/flowy-user/src/event_handler.rs
Updates the UserLocalDataMigration struct and its methods to use user ID and workspace ID directly, instead of a session object.
  • Modifies the UserLocalDataMigration struct to include uid and workspace_id fields.
  • Updates the new method to accept uid and workspace_id.
  • Updates the run method to pass uid and workspace_id to the migration's run method.
frontend/rust-lib/flowy-user/src/migrations/migration.rs
Updates run_data_migration to accept user ID and workspace ID directly.
  • Modifies the run_data_migration function to accept uid and workspace_id parameters.
  • Updates the call to UserLocalDataMigration::new with the new parameters.
frontend/rust-lib/flowy-user/src/user_manager/manager.rs
Adds new events to the event map for previewing and importing user data.
  • Adds PreviewAppFlowyUserData event with input UserDataPathPB.
  • Adds ImportAppFlowyUserData event with input ImportUserDataPB.
frontend/rust-lib/flowy-user/src/event_map.rs
Introduces new module user_data_import.rs to handle the import of user data, including previewing and importing workspaces.
  • Adds functions for previewing user data, importing user workspaces, and retrieving imported user data.
  • Adds structs for representing imported user data and workspace results.
frontend/rust-lib/flowy-user/src/services/data_import/user_data_import.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant