Skip to content

Replace bulk import with client-provided UUID document creation.#56

Merged
santhoshh-kumar merged 8 commits into
mainfrom
feat/local-doc-id
May 22, 2026
Merged

Replace bulk import with client-provided UUID document creation.#56
santhoshh-kumar merged 8 commits into
mainfrom
feat/local-doc-id

Conversation

@santhoshh-kumar
Copy link
Copy Markdown
Collaborator

@santhoshh-kumar santhoshh-kumar commented May 22, 2026

This refactors the document creation and migration logic to utilize client-generated UUIDs, replacing the bulk import functionality with a document promotion mechanism.

This also fixes a bug where the db is cleared on refresh if the current user is in guest session.

This simplifies a lot of things in the backend. To make it completely offline-first, we could also allow users to create new documents in offline mode and edit them offline.

Previously, the database schema included a source_local_id field
on the Document entity to support idempotent bulk imports of local
documents, backed by a Flyway schema migration.

Remove the source_local_id column, its index, and the associated
Spring Data repository queries. Delete the Flyway schema migration V3
since the backend no longer tracks local IDs.
…k import.

Previously, Document entity IDs were always auto-generated using
Hibernate's UUID strategy, and local documents had to be imported via
a dedicated bulk-import API endpoint that mapped local IDs.

Now, accept an optional client-provided UUID id in DocumentCreateRequest.
If a document with that ID already exists for the user, return 200 OK
with a message indicating it already exists. Remove the bulk import
endpoints, DTOs, and corresponding controller/service tests.
Previously, clearLocalUserData cleared the entire IndexedDB database during
logout or unauthenticated session clear, including guest/local documents.

Add a getUserId getter to indexedDBService to check if there is an
authenticated user. In clearLocalUserData, check if the current user
ID is null (i.e. guest session) and avoid clearing the database to
ensure guest/local documents persist across refreshes.
Previously, when offline loading failed or migration completed, the
useDocument hook did not automatically retry loading the document.

Add event listeners for cloud-documents-changed and local-documents-changed
within useDocument to clear the backoff and trigger a reload when these
migration/promotion events are fired.
…ent creation.

Previously, guest documents were promoted to the user's account using
bulkImportLocalDocuments, which relied on the deleted backend bulk-import API.

Replace bulkImportLocalDocuments with promoteGuestDocumentsToAccount.
For each guest document, call createCloudDocument with the document's
existing local UUID as the requested ID, then cache it.
Previously, migrating a local document to the cloud resulted in a
new cloud-generated document ID, requiring subsequent deletion of the
original local document and database redirection.

Now, migrateLocalDocumentToCloud and resolveRootDocumentId pass the
existing local document UUID to createCloudDocument, ensuring the
document ID remains identical in both local and cloud databases.
Previously, creating a new document offline or online did not use
a consistent pre-generated ID schema, relying on separate random
UUIDs for guest documents versus cloud documents.

Update handleCreateFile to always generate a document ID locally
using generateDocumentId, then save it local-first and, if
authenticated, propagate the same ID to createCloudDocument.
…promotion.

Previously, the AppShell component tracked local document sync using the
naming convention of "bulk import" in state variables and refs.

Refactor all references of "bulk import" to "promotion" in AppShell to
reflect the new client-driven promotion strategy. Update the corresponding
unit tests to verify guest document promotion.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the document creation and migration logic to utilize client-generated UUIDs, replacing the bulk import functionality with a document promotion mechanism. Key changes include updating the backend Document entity and DocumentCreateRequest to support manual ID assignment, removing the bulk import API, and refactoring the frontend to generate IDs locally. Feedback suggests improving the implementation by moving yjsState validation to the DTO level using standard annotations and parallelizing the document promotion process in the frontend service to reduce latency.

Comment thread api/src/main/java/com/nextdocs/api/document/service/DocumentService.java Outdated
Comment thread web/services/document.service.ts Outdated
@santhoshh-kumar santhoshh-kumar merged commit 1328552 into main May 22, 2026
6 checks passed
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