-
Notifications
You must be signed in to change notification settings - Fork 11
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
account edge for question optional #351
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
📝 WalkthroughWalkthroughThe pull request introduces comprehensive changes to handle optional account IDs and authors across multiple files in the project. The modifications primarily focus on making the Changes
Sequence DiagramsequenceDiagram
participant Client
participant QuestionCreate
participant Database
Client->>QuestionCreate: Create Question
alt Optional Account
QuestionCreate->>QuestionCreate: SetNillableAccountID
QuestionCreate->>Database: Save with Optional Account
else No Account
QuestionCreate->>Database: Save without Account
end
Possibly related PRs
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
,!**/*.sum
📒 Files selected for processing (10)
app/resources/question/question.go
(2 hunks)app/resources/question/repo.go
(3 hunks)app/services/semdex/asker/cached.go
(2 hunks)app/transports/http/bindings/openapi_rbac/mapping.go
(1 hunks)internal/ent/migrate/schema.go
(2 hunks)internal/ent/mutation.go
(4 hunks)internal/ent/question/where.go
(1 hunks)internal/ent/question_create.go
(5 hunks)internal/ent/question_update.go
(2 hunks)internal/ent/schema/question.go
(2 hunks)
🔇 Additional comments (18)
internal/ent/schema/question.go (1)
26-26
: Verify cascade behavior for optional author relationshipThe changes correctly make the account relationship optional. However, we should ensure proper handling of orphaned questions when an account is deleted.
Run this script to check the cascade behavior in the schema:
Also applies to: 35-35
app/resources/question/question.go (1)
17-17
: LGTM! Well-structured optional handlingThe implementation correctly uses opt.Optional for the Author field with proper error handling in the mapping function.
Also applies to: 21-34, 44-44
app/services/semdex/asker/cached.go (1)
100-102
: LGTM! Clean session handlingThe changes correctly retrieve the optional account ID from the session and properly handle it in the Store call.
Also applies to: 110-110
app/transports/http/bindings/openapi_rbac/mapping.go (1)
430-430
: Verify the security implications of making DatagraphAsk public.The endpoint is being made publicly accessible by removing the permission requirement. Please confirm if this aligns with the security requirements and if there are any potential risks in allowing unauthenticated access.
Run the following script to check for any security-sensitive operations in the DatagraphAsk implementation:
✅ Verification successful
Making DatagraphAsk public is safe and follows security best practices
The endpoint is safe to make public as it:
- Is a read-only operation (GET method)
- Has proper error handling (401, 404, 500)
- Contains no sensitive operations in its implementation
- Can still be protected by authentication middleware if needed
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check the implementation of DatagraphAsk for security-sensitive operations. # Search for the DatagraphAsk implementation ast-grep --pattern $'func $_(ctx context.Context) $$ { $$$ }'Length of output: 64
Script:
#!/bin/bash # First, find files containing DatagraphAsk rg -l "DatagraphAsk" # Then look for the actual implementation with context rg -A 10 "DatagraphAsk" # Check for any security-related configurations rg -l "(?i)security|auth|permission|rbac" app/transports/http/bindings/openapi_rbac/Length of output: 33456
Script:
#!/bin/bash # Check for any middleware handling DatagraphAsk rg -A 5 "middleware.*DatagraphAsk" # Look for any authentication middleware configurations rg -l "(?i)auth.*middleware" # Check the actual implementation in middleware ast-grep --pattern 'middleware $_ { $$$ DatagraphAsk $$$ }'Length of output: 539
internal/ent/question_update.go (4)
122-126
: LGTM! New methods enhance flexibility for optional fields.The added methods
ClearAccountID
andSetNillableAuthorID
inQuestionUpdate
provide proper handling of optional account IDs and authors, aligning with the PR objectives.Also applies to: 134-140
Line range hint
404-408
: LGTM! Consistent handling in upsert operations.The
ClearAccountID
method inQuestionUpsert
maintains consistency with the update operations by allowing account IDs to be cleared during upserts.
Line range hint
559-564
: LGTM! Single-entity upsert support.The
ClearAccountID
method inQuestionUpsertOne
properly handles the clearing of account IDs for single-entity upsert operations.
Line range hint
882-887
: LGTM! Bulk upsert support.The
ClearAccountID
method inQuestionUpsertBulk
correctly implements the clearing of account IDs for bulk upsert operations.internal/ent/question/where.go (1)
442-450
: LGTM! Enhanced query predicates for optional fields.The new predicates
AccountIDIsNil
andAccountIDNotNil
provide the necessary filtering capabilities for handling optional account IDs in queries.internal/ent/question_create.go (2)
86-92
: LGTM! Flexible creation with optional fields.The new methods
SetNillableAccountID
andSetNillableAuthorID
inQuestionCreate
provide proper handling of optional fields during entity creation.Also applies to: 114-120
404-408
: LGTM! Consistent upsert behavior.The
ClearAccountID
methods in the upsert builders maintain consistency with the create operations by allowing account IDs to be cleared during upserts.Also applies to: 559-564, 882-887
internal/ent/migrate/schema.go (2)
703-703
: LGTM! Making account_id nullable aligns with the optional account requirement.The change to make
account_id
nullable is well-implemented and consistent with the schema design patterns used elsewhere in the codebase.
715-715
: LGTM! Appropriate foreign key behavior for optional relationships.Setting
OnDelete: schema.SetNull
is the correct choice here as it:
- Preserves questions when accounts are deleted
- Maintains referential integrity
- Aligns with the nullable nature of the relationship
internal/ent/mutation.go (5)
20771-20786
: Implementation follows ent patterns correctly!The new methods
ClearAccountID
andAccountIDCleared
are implemented correctly, following ent's mutation patterns for optional fields. The update toResetAccountID
properly maintains the cleared state.
20802-20802
: Logical enhancement to AuthorCleared!The method now correctly considers both ways an author can be cleared: either through the account_id field or the author edge directly.
21024-21026
: Consistent implementation of cleared fields tracking!The addition of
account_id
to the cleared fields list follows the established pattern and maintains consistency with ent's field clearing mechanism.
21047-21049
: Field clearing API properly extended!The addition of
account_id
to theClearField
method completes the field clearing API, maintaining consistency with ent's patterns.
Line range hint
20771-21049
: Verify consistency with related schema and operation changes.Let's ensure these mutation changes are properly supported by corresponding changes in related files.
✅ Verification successful
Mutation changes are properly supported across the codebase
The implementation is consistent with:
- Nullable account_id field in schema
- Proper author edge definition with unique constraint
- Complete mutation support in create/update operations
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify related changes for optional account_id support # Check schema changes echo "Checking schema definition..." rg -A 5 "account_id.*null" internal/ent/migrate/schema.go # Check create/update operations echo "Checking create operations..." rg "SetNillableAccountID" internal/ent/question_create.go echo "Checking update operations..." rg "ClearAccountID" internal/ent/question_update.go # Check predicates and filters echo "Checking predicates..." rg "HasAccountID|WithoutAccountID" internal/ent/questionLength of output: 963
Script:
#!/bin/bash # Check schema and edge definitions more broadly echo "Checking schema definition..." rg "account_id" internal/ent/migrate/schema.go echo "\nChecking edge definitions..." ast-grep --pattern 'func (Question) Edges() []ent.Edge { $$$ }' echo "\nChecking author edge constraints..." rg "author.*Edge" internal/ent/schema/question.goLength of output: 1875
@@ -21,7 +22,7 @@ func New(db *ent.Client) *Repository { | |||
return &Repository{db: db} | |||
} | |||
|
|||
func (r *Repository) Store(ctx context.Context, accountID account.AccountID, query string, result datagraph.Content) (*Question, error) { | |||
func (r *Repository) Store(ctx context.Context, query string, result datagraph.Content, accountID opt.Optional[account.AccountID]) (*Question, error) { |
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.
💡 Codebase verification
Update required: Incompatible Store method call found
The Store method call in app/services/semdex/asker/cached.go
needs to be updated to match the new signature with optional accountID:
- Current:
questions.Store(ctx, q, acc, accountID)
- Required:
questions.Store(ctx, query, result, opt.Optional[account.AccountID](accountID))
🔗 Analysis chain
Verify all callers of Store method
The Store method signature change and optional handling look good. However, we should verify all callers are updated to the new signature.
Also applies to: 34-37
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Find all calls to Store method
ast-grep --pattern 'Store($ctx, $$$)'
Length of output: 39
Script:
#!/bin/bash
# Search for Store method calls using ripgrep
rg -l "\.Store\("
# Show the actual calls with context
rg "\.Store\(" -A 2 -B 2
Length of output: 1112
Script:
#!/bin/bash
# Check the type definition and imports in cached.go
rg -B 5 "questions\s+\*?" app/services/semdex/asker/cached.go
# Show imports to verify the repository type
rg "^import \(" -A 10 app/services/semdex/asker/cached.go
Length of output: 581
No description provided.