-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor Document Module and Cloud Storage to use project-based organization and add signed URL support #346
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
25816ae
Add project id in model and use project id for crud
avirajsingh7 d556fea
add support for signed url
avirajsingh7 ae1b873
Add storage path in project table
avirajsingh7 98610a9
fix collection endpoint
avirajsingh7 527c83d
pre commit
avirajsingh7 7af3a5c
Fix api routes test cases for document module
avirajsingh7 ed98c67
fix crud unit test for document module
avirajsingh7 c388423
fix unit test for collections
avirajsingh7 2009ed1
use project id instead of project model in document store utils
avirajsingh7 7409b1c
Merge branch 'main' into update/document_module
avirajsingh7 a27d551
Fix migration
avirajsingh7 6ac0c63
precommit
avirajsingh7 efd4d03
introduce get_cloud_storage method
avirajsingh7 016bbde
fix testcase
avirajsingh7 2f07600
fix message
avirajsingh7 8fbaf8f
implement abstract method in CloudStorage class
avirajsingh7 198b22c
use POSIX separators and Reject absolute file_path
avirajsingh7 46099b5
fix argument of put method in CloudStorage
avirajsingh7 1cee5b2
fix
avirajsingh7 eddbacf
fix unit test
avirajsingh7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...lembic/versions/40307ab77e9f_add_storage_path_to_project_and_project_to_document_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """add storage_path to project and project_id to document table | ||
|
|
||
| Revision ID: 40307ab77e9f | ||
| Revises: 8725df286943 | ||
| Create Date: 2025-08-28 10:54:30.712627 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "40307ab77e9f" | ||
| down_revision = "8725df286943" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
|
|
||
| op.add_column("project", sa.Column("storage_path", sa.Uuid(), nullable=True)) | ||
|
|
||
| conn = op.get_bind() | ||
| conn.execute(sa.text("UPDATE project SET storage_path = gen_random_uuid()")) | ||
|
|
||
| op.alter_column("project", "storage_path", nullable=False) | ||
| op.create_unique_constraint("uq_project_storage_path", "project", ["storage_path"]) | ||
|
|
||
| op.add_column("document", sa.Column("project_id", sa.Integer(), nullable=True)) | ||
| op.add_column("document", sa.Column("is_deleted", sa.Boolean(), nullable=True)) | ||
|
|
||
| conn.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE document | ||
| SET is_deleted = CASE | ||
| WHEN deleted_at IS NULL THEN false | ||
| ELSE true | ||
| END | ||
| """ | ||
| ) | ||
| ) | ||
| conn.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE document | ||
| SET project_id = ( | ||
| SELECT project_id FROM apikey | ||
| WHERE apikey.user_id = document.owner_id | ||
| LIMIT 1 | ||
| ) | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| op.alter_column("document", "is_deleted", nullable=False) | ||
| op.alter_column("document", "project_id", nullable=False) | ||
|
|
||
| op.drop_constraint("document_owner_id_fkey", "document", type_="foreignkey") | ||
| op.create_foreign_key( | ||
| None, "document", "project", ["project_id"], ["id"], ondelete="CASCADE" | ||
| ) | ||
| op.drop_column("document", "owner_id") | ||
|
|
||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_constraint("uq_project_storage_path", "project", type_="unique") | ||
| op.drop_column("project", "storage_path") | ||
|
|
||
| op.add_column( | ||
| "document", | ||
| sa.Column("owner_id", sa.Integer(), autoincrement=False, nullable=True), | ||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| conn = op.get_bind() | ||
| # Backfill owner_id from project_id using api_key mapping | ||
| conn.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE document d | ||
| SET owner_id = ( | ||
| SELECT user_id | ||
| FROM apikey a | ||
| WHERE a.project_id = d.project_id | ||
| LIMIT 1 | ||
| ) | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| op.alter_column("document", "owner_id", nullable=False) | ||
|
|
||
| op.drop_constraint("document_project_id_fkey", "document", type_="foreignkey") | ||
| op.create_foreign_key( | ||
| "document_owner_id_fkey", | ||
| "document", | ||
| "user", | ||
| ["owner_id"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
| op.drop_column("document", "is_deleted") | ||
| op.drop_column("document", "project_id") | ||
| # ### end Alembic commands ### | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ | |
| AmazonCloudStorageClient, | ||
| CloudStorage, | ||
| CloudStorageError, | ||
| get_cloud_storage, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.