-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: tables/migration for permission syncing attempts #5397
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
15d2ac3
to
2a61ed7
Compare
2a61ed7
to
3f1712a
Compare
3f1712a
to
c2188a5
Compare
c2188a5
to
4db3185
Compare
4db3185
to
838f1eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR introduces database infrastructure for tracking permission synchronization attempts by adding two new tables and supporting code changes. The changes implement:
New Database Tables:
doc_permission_sync_attempt
- Tracks document-level permission syncing with fields for total docs synced and permission errorsexternal_group_permission_sync_attempt
- Tracks group membership syncing with fields for users processed, groups processed, and memberships synced
Supporting Code Changes:
- Adds
PermissionSyncStatus
enum inbackend/onyx/db/enums.py
with states: NOT_STARTED, IN_PROGRESS, SUCCESS, CANCELED, FAILED, COMPLETED_WITH_ERRORS - Defines corresponding SQLAlchemy models in
backend/onyx/db/models.py
with proper foreign key relationships toconnector_credential_pair
- Creates Alembic migration script
03d710ccf29c_add_permission_sync_attempt_tables.py
for schema changes
Both tables follow the established pattern of the existing IndexAttempt
model, including comprehensive indexing for efficient queries by status, time, and connector credential pair. The external_group_permission_sync_attempt
table allows nullable connector_credential_pair_id
to support global group syncs, while doc_permission_sync_attempt
requires a specific connector pair since document permissions are always tied to a source.
This infrastructure enables the system to track sync attempt history and provide visibility to users about permission synchronization operations, supporting the broader permission auto-sync framework referenced in Linear ticket DAN-2494.
Confidence score: 4/5
- This PR is generally safe to merge but contains a few issues that should be addressed
- Score reflects well-structured database design with proper patterns but inconsistencies in migration constraints and hardcoded enum values
- Pay close attention to the migration file for constraint inconsistencies and enum synchronization
3 files reviewed, 2 comments
backend/alembic/versions/03d710ccf29c_add_permission_sync_attempt_tables.py
Show resolved
Hide resolved
backend/alembic/versions/03d710ccf29c_add_permission_sync_attempt_tables.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 3 files
838f1eb
to
79c6f7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments
backend/alembic/versions/03d710ccf29c_add_permission_sync_attempt_tables.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR introduces a permission sync tracking system by adding two new database tables and supporting infrastructure. The changes include:
-
New Database Models: Two tables are added to track different types of permission sync attempts:
DocPermissionSyncAttempt
: Tracks document-level permission syncing attempts, always tied to a specific connector-credential pair (NOT NULL constraint)ExternalGroupPermissionSyncAttempt
: Tracks external group membership syncing attempts, which can be global operations (nullable connector-credential pair ID)
-
Status Management: A new
PermissionSyncStatus
enum is added tobackend/onyx/db/enums.py
with six states (NOT_STARTED, IN_PROGRESS, SUCCESS, CANCELED, FAILED, COMPLETED_WITH_ERRORS) and helper methodsis_terminal()
andis_successful()
that mirror the existingIndexingStatus
pattern. -
Database Schema: The migration creates comprehensive indexing strategies for efficient querying by status, time, and connector-credential pair combinations. Both tables include progress tracking fields (e.g.,
total_docs_synced
,docs_with_permission_errors
for document sync;total_users_processed
,total_groups_processed
for group sync). -
SQLAlchemy Models: Corresponding model classes are added to
backend/onyx/db/models.py
with proper foreign key relationships and helper methods.
This foundation supports the broader permission syncing workflow mentioned in the PR stack, where users will be able to view sync history and errors through future API endpoints. The design follows established patterns in the codebase similar to IndexAttempt
tracking.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it only adds new database infrastructure without modifying existing functionality
- Score reflects well-structured database design following established patterns, but minor concerns about enum duplication and design consistency
- Pay close attention to the migration file for potential enum duplication issues and verify the nullable constraint design is intentional
3 files reviewed, no comments
79c6f7c
to
b7b43e6
Compare
Description
Partial completion of: https://linear.app/danswer/issue/DAN-2494/sync-permissions-database-and-backend-updates
Adding two two tables related to auto sync permissions:
These will be used to track history of sync attempts and display them to the user.
PR Stack:
How Has This Been Tested?
Ran a successful upgrade/downgrade via:
And we see the tables created on upgrade:
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.