-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Filter is optional on release dependency #199
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
Conversation
WalkthroughThe pull request introduces several modifications across multiple files, primarily focusing on the handling of the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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
Documentation and Community
|
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
🧹 Outside diff range and nitpick comments (4)
packages/db/drizzle/0032_past_firestar.sql (1)
1-2: Consider adding a down migration for reversibility.While the changes are safe, it would be good practice to include a down migration that restores the NOT NULL constraint and removes the default value, in case rollback is needed.
Add these statements to your down migration:
ALTER TABLE "release_dependency" ALTER COLUMN "release_filter" DROP DEFAULT; ALTER TABLE "release_dependency" ALTER COLUMN "release_filter" SET NOT NULL;packages/job-dispatch/src/policies/release-dependency.ts (1)
86-86: Consider performance optimization for large dependency graphs.While the change is logically correct, consider adding a performance optimization by maintaining a Set of processed IDs instead of using array operations with
_.uniq.- const allIds = _.uniq([...sourceIds, ...targetIds, trigger.targetId]); + const allIds = Array.from(new Set([...sourceIds, ...targetIds, trigger.targetId]));apps/webservice/src/app/[workspaceSlug]/dependencies/DependencyDiagram.tsx (1)
172-172: Consider enhancing edge labels for better readability.While using
${d.deploymentId}-${d.releaseId}is technically correct and unique, it might be less user-friendly as it shows technical IDs. Consider adding more descriptive information to help users understand the relationship type.Example enhancement:
- label: `${d.deploymentId}-${d.releaseId}`, + label: `${d.deploymentId}-${d.releaseId}${d.releaseFilter?.type ? ` (${d.releaseFilter.type})` : ''}`,This would show the filter type when available while still maintaining compatibility with null filters.
apps/webservice/src/app/[workspaceSlug]/_components/CreateRelease.tsx (1)
292-292: Consider simplifying the icon rendering logicWhile the current implementation works correctly, the conditional icon rendering could be simplified using a ternary operator.
Consider this more concise version:
-{value == null && ( - <IconFilterExclamation className="h-4 w-4" /> -)} -{value != null && ( - <IconFilterFilled className="h-4 w-4" /> -)} +{value == null ? ( + <IconFilterExclamation className="h-4 w-4" /> +) : ( + <IconFilterFilled className="h-4 w-4" /> +)}Also applies to: 296-301
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
apps/webservice/src/app/[workspaceSlug]/_components/CreateRelease.tsx(4 hunks)apps/webservice/src/app/[workspaceSlug]/dependencies/DependencyDiagram.tsx(1 hunks)packages/db/drizzle/0032_past_firestar.sql(1 hunks)packages/db/drizzle/meta/_journal.json(1 hunks)packages/db/src/schema/release.ts(2 hunks)packages/job-dispatch/src/policies/release-dependency.ts(1 hunks)
🔇 Additional comments (11)
packages/db/drizzle/0032_past_firestar.sql (1)
1-2: LGTM! Verify existing data integrity.
The ALTER TABLE statements are correctly structured and safely modify the release_filter column. The order of operations (setting default before dropping NOT NULL) maintains data integrity.
Let's verify there are no NULL values in existing rows:
✅ Verification successful
LGTM! The migration is safe and consistent with the schema
The changes are safe because:
- The
release_filtercolumn was initially added asjsonb NOT NULLin migration 0022 - The schema definition shows it's typed as
ReleaseConditionand already has adefault(sql\NULL`)` configuration - No intermediate migrations between 0022 and 0032 modified this column's constraints
- The current migration properly sets the default first, then drops the NOT NULL constraint
The changes align with both the TypeScript schema definition and the database evolution history.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any existing NULL values in release_filter column
# Note: This is a safety check, should return no results as the column was NOT NULL
# Search for SQL files that might contain relevant INSERT statements
rg -l "INSERT.*release_dependency.*release_filter" --type sql
Length of output: 63
Script:
#!/bin/bash
# Let's try a different approach to analyze the schema and data patterns:
# 1. Find all SQL migration files
echo "=== SQL Migration Files ==="
fd -e sql . packages/db/drizzle/
# 2. Look for release_dependency table creation and modifications
echo -e "\n=== Table Creation and Modifications ==="
rg -A 5 "CREATE TABLE.*release_dependency|ALTER TABLE.*release_dependency" --type sql
# 3. Check for any TypeScript schema definitions
echo -e "\n=== Schema Definitions ==="
rg -l "release_dependency" --type ts
Length of output: 6379
Script:
#!/bin/bash
# Let's examine the evolution of the release_filter column and its usage
# 1. Check when release_filter was added and its initial state
echo "=== Release Filter Addition ==="
rg "release_filter" packages/db/drizzle/0022_clean_wrecking_crew.sql
# 2. Look at the schema definition to understand the type
echo -e "\n=== Schema Definition ==="
cat packages/db/src/schema/release.ts
# 3. Check for any migrations between 0022 and 0032 that modify release_filter
echo -e "\n=== Intermediate Migrations ==="
for i in {23..31}; do
num=$(printf "%04d" $i)
if [ -f "packages/db/drizzle/${num}"* ]; then
echo "Checking migration ${num}:"
rg "release_filter" "packages/db/drizzle/${num}"*
fi
done
Length of output: 10896
packages/db/drizzle/meta/_journal.json (1)
228-234: LGTM! Migration entry follows established patterns.
The new migration entry is properly structured and maintains consistency with existing entries in terms of sequential indexing, version numbering, and configuration.
Let's verify the migration has been properly applied and the schema changes are consistent:
✅ Verification successful
Migration changes are properly implemented and schema is consistent
The verification confirms:
- Migration file
0032_past_firestar.sqlcorrectly modifies therelease_filtercolumn to be nullable with appropriate SQL statements - Schema definition in
release.tsmaintains thereleaseFilterfield as a JSON column - Changes align with the migration journal entry and the goal of making the filter optional
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the migration changes and schema consistency
# Test 1: Check if the migration file exists and contains the ALTER TABLE statement
echo "Checking migration file content..."
fd -e sql "0032_past_firestar.sql" -x cat {}
# Test 2: Verify the schema definition in the TypeScript code
echo "Checking schema definition..."
rg "release_filter" "packages/db/src/schema/release.ts"
Length of output: 514
packages/job-dispatch/src/policies/release-dependency.ts (2)
Line range hint 9-143: Implementation is robust and well-structured.
The overall implementation of isPassingReleaseDependencyPolicy is well-structured with proper:
- Error handling
- Async/await usage
- SQL query optimization using WITH RECURSIVE
- Type safety
The change to include trigger.targetId in dependency resolution integrates well with the existing implementation.
86-86: Verify the impact of including trigger.targetId in dependency resolution.
The addition of trigger.targetId to allIds ensures that the current trigger's target is always considered in dependency checks, which aligns with making filters optional. However, we should verify that this doesn't create any unintended circular dependencies or performance issues.
Let's verify the potential impact:
✅ Verification successful
Including trigger.targetId in allIds array is safe and intentional
The verification shows that:
- The code uses a recursive CTE query that already handles cycle prevention through the
visitedarray and explicit checkNOT ... = ANY(rr.visited). - The
trigger.targetIdis used as the starting point in the recursive query and is explicitly excluded from further traversal withAND tr.target_id != ${trigger.targetId}. - Adding
trigger.targetIdtoallIdsis only used for subsequent dependency validation, not for relationship traversal.
This implementation ensures that:
- Circular dependencies are prevented during graph traversal
- The target being processed is properly considered in dependency validation
- The change aligns with the system's existing dependency resolution logic
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for potential circular dependencies and analyze the dependency resolution logic
# Test 1: Look for any existing circular dependency prevention mechanisms
echo "Checking for circular dependency prevention..."
rg -i "circular|cycle|loop" --type ts
# Test 2: Analyze the usage of targetId in dependency resolution
echo "Analyzing targetId usage in dependency checks..."
ast-grep --pattern 'targetId = ANY(visited)'
# Test 3: Check if there are any existing test cases handling circular dependencies
echo "Looking for relevant test cases..."
fd -e test.ts -e spec.ts | xargs rg -l "circular|cycle|loop"
Length of output: 2676
Script:
#!/bin/bash
# Let's analyze the dependency resolution logic more specifically
# Check how visited/dependency tracking is implemented
echo "Analyzing dependency tracking implementation..."
rg -A 10 "isPassingReleaseDependencyPolicy" --type ts
# Check how targetId is used in the context
echo "Checking targetId usage..."
rg -B 5 -A 5 "trigger\.targetId" --type ts
# Look for tests specific to release dependencies
echo "Checking release dependency tests..."
fd -e test.ts -e spec.ts | xargs rg -l "ReleaseDependencyPolicy|isPassingReleaseDependencyPolicy"
Length of output: 9232
apps/webservice/src/app/[workspaceSlug]/dependencies/DependencyDiagram.tsx (1)
172-172: LGTM: More resilient edge labeling.
The change from d.releaseFilter.type to ${d.deploymentId}-${d.releaseId} aligns with making release filters optional and prevents potential null reference errors when releaseFilter is null.
packages/db/src/schema/release.ts (3)
292-292: LGTM!
The parameter type update to ReleaseCondition | null is correct and consistent with making the filter optional.
Line range hint 293-296: LGTM!
The null check and empty object handling is correct. The loose equality operator (==) appropriately handles both null and undefined cases.
Line range hint 292-296: Verify function usage across the codebase.
Let's ensure all callers of releaseMatchesCondition handle the nullable parameter correctly.
✅ Verification successful
Based on the search results, I can now generate the final response as all callers have been identified and analyzed.
All callers handle the nullable parameter correctly
The verification shows that all usages of releaseMatchesCondition pass the filter parameter directly without any assumptions about non-nullability:
- In
packages/api/src/router/release.ts,input.filteris passed as-is - In
packages/api/src/router/job.ts,rd.releaseFilteris passed as-is - In
packages/api/src/router/deployment.ts,filteris passed as-is - In
packages/job-dispatch/src/environment-creation.ts, explicitly handles null withreleaseFilter ?? undefined - In
packages/job-dispatch/src/policies/release-dependency.ts,dep.releaseFilteris passed as-is - In
packages/job-dispatch/src/policies/release-string-check.ts,releaseFilteris passed as-is
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all usages of releaseMatchesCondition function
# Use ast-grep to find function calls with their arguments
ast-grep --pattern 'releaseMatchesCondition($$$)'
# Backup: Use ripgrep to find any string matches
rg -A 2 'releaseMatchesCondition'
Length of output: 3375
apps/webservice/src/app/[workspaceSlug]/_components/CreateRelease.tsx (3)
44-44: LGTM: Schema and import changes align with making release filters optional
The changes to make releaseFilter nullable and import defaultCondition are consistent with the PR objective of making filters optional on release dependencies.
Also applies to: 54-54
324-324: LGTM: Correct initialization of new release dependencies
The initialization of new dependencies with releaseFilter: null is consistent with the schema changes and maintains type safety.
114-120: LGTM: Form submission properly handles optional filters
The submission logic correctly transforms the release dependencies by:
- Preserving the original data structure
- Setting null for both empty and null filters
- Maintaining non-empty filters as-is
Let's verify the handling of empty conditions:
Also applies to: 123-123
✅ Verification successful
The search results show that isEmptyCondition is consistently implemented across different condition types (job, target, and release conditions) and is used uniformly throughout the codebase for handling empty filters. Let me verify the specific implementation for release conditions to ensure it aligns with our usage.
Let me adjust the search to find the type definitions using a different approach.
Verified: Release filter handling is correctly implemented
The implementation is consistent and correct because:
isEmptyConditionfor releases properly checks both the type (ReleaseFilterType.Comparison) and empty conditions array- The usage in CreateRelease.tsx correctly coalesces both
nulland empty conditions tonull - This pattern is consistently used across the codebase in other components handling release filters
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if isEmptyCondition is consistently used across the codebase
rg "isEmptyCondition" -A 2
Length of output: 5049
Script:
#!/bin/bash
# Check the implementation of ReleaseCondition and ReleaseFilterType
ast-grep --pattern 'type ReleaseFilterType = {
$$$
}'
# Also check ReleaseCondition type
ast-grep --pattern 'type ReleaseCondition = {
$$$
}'
Length of output: 114
Script:
#!/bin/bash
# Search for ReleaseFilterType and ReleaseCondition definitions
rg "export (type|enum|interface) Release(FilterType|Condition)" -A 5
# Also check the actual implementation of isEmptyCondition for releases
rg "export const isEmptyCondition.*ReleaseCondition.*=>" -A 3
Length of output: 2507
| releaseFilter: jsonb("release_filter") | ||
| .$type<ReleaseCondition>() | ||
| .default(sql`NULL`), |
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 type definition to match nullable default value and ensure database migration exists.
The migration for making release_filter nullable exists in packages/db/drizzle/0032_past_firestar.sql:
ALTER TABLE "release_dependency" ALTER COLUMN "release_filter" SET DEFAULT NULL;
ALTER TABLE "release_dependency" ALTER COLUMN "release_filter" DROP NOT NULL;Apply this diff to match the database schema:
releaseFilter: jsonb("release_filter")
- .$type<ReleaseCondition>()
+ .$type<ReleaseCondition | null>()
.default(sql`NULL`),🔗 Analysis chain
Update type definition to match nullable default value.
The releaseFilter field is now nullable with a default value of NULL, but the type definition only includes ReleaseCondition. Update the type to include null.
Apply this diff:
releaseFilter: jsonb("release_filter")
- .$type<ReleaseCondition>()
+ .$type<ReleaseCondition | null>()
.default(sql`NULL`),This schema change might require a database migration. Let's verify if a migration exists:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for migration files related to release_dependency table
fd -e sql -e ts 'migration|release_dependency' packages/db/migrations
Length of output: 181
Script:
#!/bin/bash
# Let's first check if the migrations directory exists elsewhere
fd -H migrations
# Then let's search for any SQL files in the repository
fd -e sql
# Also search for migration-related TypeScript files
fd -e ts migration
Length of output: 1627
Script:
#!/bin/bash
# Let's check the content of the most recent migration files for any changes related to release_filter or release_dependency
cat packages/db/drizzle/0031_absurd_young_avengers.sql packages/db/drizzle/0032_past_firestar.sql
# Also search for any mentions of release_filter or release_dependency in recent migrations
rg -i "release.*filter|release.*dependency" packages/db/drizzle/
Length of output: 54941
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Chores