Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Apr 8, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined internal processing for release data and its associated elements to enhance consistency.
  • Chore
    • Updated database relationships and query flows to bolster performance without affecting the user interface.
    • Transitioned to a version-based release schema, improving the organization of release-related data.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request updates the database queries and schema references to transition from using the release entity to the versionRelease entity. Changes include modifications in event worker queries, updates to join conditions in GitHub job dispatch, schema renaming and restructuring in the database, and corresponding updates in repository methods and type definitions within the rule engine.

Changes

File(s) Change Summary
apps/event-worker/src/workers/evaluate-release-target.ts
apps/event-worker/src/workers/job-dispatch/github.ts
Updated database queries and join operations: replaced references to release with versionRelease for fetching and joining release data.
packages/db/src/schema/release.ts Renamed tables and updated the schema: releaseversionRelease, releaseVariablevariableRelease; added variableReleaseValue table; updated relations and foreign key references to reflect the new data model.
packages/rule-engine/src/repositories/db-release-repository.ts
packages/rule-engine/src/repositories/get-releases.ts
packages/rule-engine/src/repositories/types.ts
Modified repository queries and type definitions to use the new schema: inserts and selects now target versionRelease and variableReleaseValue instead of the old release and releaseVariable entities.

Sequence Diagram(s)

sequenceDiagram
    participant Worker as EvaluateReleaseWorker
    participant DB as Database (tx.query.versionRelease)
    Worker->>DB: Invoke createJobForRelease(chosenReleaseId)
    DB-->>Worker: Return versionRelease record
Loading
sequenceDiagram
    participant Dispatch as GitHubDispatcher
    participant DB as Database (Join Query)
    Dispatch->>DB: Execute query joining releaseJob with versionRelease
    DB-->>Dispatch: Return joined release job data
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

I’m a happy rabbit coding in the glen,
Hopping through queries again and again.
Tables renamed and joins well aligned,
In a world of versionRelease, my joy is defined.
With every update, my heart skips a beat—
Here’s to a codebase that’s wonderfully neat!
🐰💻


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef2a967 and 57be196.

📒 Files selected for processing (1)
  • packages/db/src/schema/release.ts (4 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
packages/db/src/schema/release.ts (1)

57-63: variableRelease introduction is valid, though consider a creation timestamp default.
Currently, createdAt is optional. Using a .defaultNow() might enhance consistency with other tables.

 createdAt: timestamp("created_at", { withTimezone: true })
- 
+   .defaultNow(),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb82448 and ef2a967.

📒 Files selected for processing (6)
  • apps/event-worker/src/workers/evaluate-release-target.ts (1 hunks)
  • apps/event-worker/src/workers/job-dispatch/github.ts (1 hunks)
  • packages/db/src/schema/release.ts (4 hunks)
  • packages/rule-engine/src/repositories/db-release-repository.ts (1 hunks)
  • packages/rule-engine/src/repositories/get-releases.ts (3 hunks)
  • packages/rule-engine/src/repositories/types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • apps/event-worker/src/workers/evaluate-release-target.ts
  • packages/rule-engine/src/repositories/db-release-repository.ts
  • packages/rule-engine/src/repositories/types.ts
  • apps/event-worker/src/workers/job-dispatch/github.ts
  • packages/rule-engine/src/repositories/get-releases.ts
  • packages/db/src/schema/release.ts
🧬 Code Definitions (3)
apps/event-worker/src/workers/evaluate-release-target.ts (1)
packages/db/src/schema/release.ts (1)
  • release (79-93)
packages/rule-engine/src/repositories/get-releases.ts (3)
packages/db/src/schema/job.ts (1)
  • JobStatus (136-136)
packages/db/src/schema/release.ts (1)
  • releaseTarget (18-40)
packages/db/src/schema/policy.ts (1)
  • policy (23-39)
packages/db/src/schema/release.ts (2)
packages/db/src/schema/deployment-version.ts (1)
  • deploymentVersion (109-134)
packages/db/src/schema/job.ts (1)
  • job (74-106)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (25)
packages/rule-engine/src/repositories/types.ts (1)

9-9: Type definition updated to use the new schema entity.

The Release type definition has been updated to infer its structure from schema.versionRelease instead of schema.release, aligning with the broader schema restructuring across the codebase.

apps/event-worker/src/workers/evaluate-release-target.ts (1)

22-24: Query updated to use versionRelease entity.

The database query has been correctly updated to reference the new versionRelease entity instead of the previous release entity, maintaining consistency with the schema changes.

packages/rule-engine/src/repositories/db-release-repository.ts (2)

136-140: Insert operation updated to use versionRelease entity.

The database insert operation has been correctly updated to target the new schema.versionRelease entity instead of the previous schema.release entity, aligning with the schema changes.


141-149: Variable storage entity updated to variableReleaseValue.

The database insert operation for variables has been correctly updated to use the new schema.variableReleaseValue entity instead of the previous schema.releaseVariable entity, maintaining consistency with the schema restructuring.

apps/event-worker/src/workers/job-dispatch/github.ts (2)

77-80: Join operation updated to use versionRelease entity.

The inner join in the database query has been correctly updated to join with the SCHEMA.versionRelease table instead of the previous SCHEMA.release table, aligning with the schema changes.


81-84: Join condition updated to reference versionRelease.

The join condition between the releaseTarget table and the release entity has been correctly updated to reference SCHEMA.versionRelease.releaseTargetId instead of the previous SCHEMA.release.releaseTargetId, maintaining schema consistency.

packages/rule-engine/src/repositories/get-releases.ts (11)

55-56: No immediate concerns with new references to the release table.
The updated .from(schema.release) and .innerJoin(schema.job, eq(schema.release.jobId, schema.job.id)) appear consistent with the newly introduced jobId foreign key in the release table.


65-65: Ordering by versionRelease.createdAt looks correct.
Ensures newer records appear first.


87-87: Switched to querying versionRelease is accurate.
Matches the updated schema for release tracking.


89-89: Filtering by releaseTargetId is valid.
Properly constrains the query to the correct release target relationship.


95-95: Ensuring only releases after the deployed release is logical.
gte(schema.versionRelease.createdAt, latestDeployedRelease.createdAt) correctly narrows the time window.


98-101: Bounded check against the desired release creation time is coherent.
Helps enforce an upper limit on retrieved releases.


108-108: Descending ordering by versionRelease.createdAt remains consistent.
No further issues here.


128-130: Returning the latest version release if no policy is specified looks good.
The usage of .findFirst with descending order ensures you get the most recent entry.


136-136: Querying versionRelease again is aligned with the updated schema.
No problems identified.


138-138: Filtering by releaseTargetId is again consistent.
Matches the same schema logic above.


145-145: Final descending sort step for .findFirst is coherent.
Keeps the latest release at the top of the result.

packages/db/src/schema/release.ts (8)

42-55: versionRelease table definition appears consistent.
The releaseTargetId and versionId references match the new schema design, and including createdAt is standard practice.


65-77: variableReleaseValue with unique (variableReleaseId, key) looks correct.
Ensures that each variable can only appear once per variable release.


79-93: New release table references versionRelease and variableRelease appropriately.
The relationships to job and timestamps are well-structured.


116-118: Extended relations on releaseTarget referencing versionReleases and variableReleases are coherent.
Keeps the design consistent with the new table split.


121-134: versionReleaseRelations accurately captures links to deploymentVersion, releaseTarget, and the associated release.
No issues found.


136-145: variableReleaseRelations linking to releaseTarget and release is correct.
Ensures user can trace from a variableRelease to all dependent relationships.


148-156: variableReleaseValue relations are straightforward and properly reference variableRelease.
No concerns.


158-171: releaseRelations connecting to versionRelease, variableRelease, and job completes the schema remodeling.
This neatly consolidates the final link in the new structure.

.where(
and(
sql`${schema.releaseJob.releaseId} = "releaseTarget_releases"."id"`,
sql`${schema.release.releaseId} = "releaseTarget_releases"."id"`,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential mismatch referencing a non-existent releaseId column.
The new release table does not declare a releaseId field. Consider comparing id or versionReleaseId instead to avoid runtime errors.

- sql`${schema.release.releaseId} = "releaseTarget_releases"."id"`,
+ sql`${schema.release.id} = "releaseTarget_releases"."id"`,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sql`${schema.release.releaseId} = "releaseTarget_releases"."id"`,
sql`${schema.release.id} = "releaseTarget_releases"."id"`,

releaseTargetId: uuid("release_target_id")
.notNull()
.references(() => releaseTarget.id, { onDelete: "cascade" }),
createdAt: timestamp("created_at", { withTimezone: true }),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
createdAt: timestamp("created_at", { withTimezone: true }),
createdAt: timestamp("created_at", { withTimezone: true }).nonNull(),

@jsbroks jsbroks deleted the init-release-schema-refactor branch April 8, 2025 04:38
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.

3 participants