Skip to content

Conversation

@jsbroks
Copy link
Member

@jsbroks jsbroks commented Apr 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced release management system that streamlines the relationships among releases, deployments, and resources.
    • Added a new releaseTarget table to manage release targets effectively.
    • Created a new policy_deployment_version_selector table for improved policy management.
  • Refactor

    • Removed legacy deployment dependency handling.
    • Replaced the previous resource release mechanism with the new, unified release management design.
    • Updated various database queries and relationships to align with the new schema.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update modifies the database schema across multiple modules. The deploymentDependency constant was removed from the deployment schema, eliminating unused dependency logic. The release schema introduces a new releaseTarget table, along with modifications to the release table and its relations to support the new design. The resource schema no longer includes the resourceRelease table; its relationships have been updated to refer to the new releaseTarget structure, streamlining the resource management flow.

Changes

File(s) Change Summary
packages/db/src/schema/deployment.ts, packages/db/src/schema/resource.ts Removed obsolete table definitions: dropped deploymentDependency from deployment and removed resourceRelease table plus its relations. Updated resourceRelations to reference releaseTargets instead of resourceReleases.
packages/db/src/schema/release.ts Added a new releaseTarget table with specific fields and constraints; modified the release table to include a releaseTargetId foreign key; introduced releaseTargetRelations to define the new associations.
apps/event-worker/src/releases/variable-change/index.ts Updated functions to replace references from resourceRelease to releaseTarget in database queries.
packages/release-manager/src/repositories/release-repository.ts Modified getLatest method to query releaseTarget; added getReleaseTarget method; updated createForVersion and setDesired methods to reflect new schema.
packages/release-manager/src/types.ts Added releaseTargetId property to the Release type.
packages/rule-engine/src/db/create-ctx.ts Updated database query logic to reference releaseTarget instead of resourceRelease.
packages/rule-engine/src/utils/get-releases.ts Changed queries from resourceRelease to releaseTarget and updated variable names accordingly.
packages/db/drizzle/0083_needy_tony_stark.sql Created a new policy_deployment_version_selector table; renamed resource_release table to release_target; modified existing tables and added foreign key constraints.
packages/db/drizzle/meta/_journal.json Added a new entry for the schema changes in the journal.

Possibly related PRs

  • clean up releases db #439: The changes in the main PR and the retrieved PR are related as both involve the removal of the resourceRelease table and its references, replacing them with the releaseTarget table in the database schema.

Suggested reviewers

  • adityachoudhari26

Poem

I hopped through lines of SQL code,
Leaving old tables in a lighter mode.
New release targets now dance on the screen,
With clean relations so crisp and keen.
A bunny hops with joy—schema reborn and serene!
🐇💨


📜 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 bbceb30 and c83af3c.

📒 Files selected for processing (4)
  • packages/db/drizzle/0083_needy_tony_stark.sql (1 hunks)
  • packages/db/drizzle/meta/_journal.json (1 hunks)
  • packages/db/src/schema/release.ts (4 hunks)
  • packages/rule-engine/src/utils/get-releases.ts (1 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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 085d584 and e9a9145.

📒 Files selected for processing (3)
  • packages/db/src/schema/deployment.ts (0 hunks)
  • packages/db/src/schema/release.ts (4 hunks)
  • packages/db/src/schema/resource.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/db/src/schema/deployment.ts
🧰 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.

  • packages/db/src/schema/resource.ts
  • packages/db/src/schema/release.ts
🧬 Code Definitions (2)
packages/db/src/schema/resource.ts (1)
packages/db/src/schema/release.ts (1)
  • releaseTarget (18-40)
packages/db/src/schema/release.ts (3)
packages/db/src/schema/resource.ts (1)
  • resource (59-87)
packages/db/src/schema/environment.ts (1)
  • environment (57-82)
packages/db/src/schema/deployment.ts (1)
  • deployment (66-90)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (linux/amd64)
  • GitHub Check: Lint
🔇 Additional comments (6)
packages/db/src/schema/release.ts (4)

1-1: No issues with the new import.

This addition aligns with the rest of the import statements, and the usage of relations and sql is appropriate.


18-40: Verify forward reference and type usage for desiredReleaseId.

The table definition appears consistent with your schema approach, but please ensure there's no runtime or type issue from referencing release in line 34 via (): any => release.id.


45-47: Confirm application logic for releaseTargetId references.

Declaring releaseTargetId as NOT NULL is fine, but make sure that upstream creation properly includes a valid releaseTargetId to avoid foreign key constraint errors.


89-91: Good relationship mapping.

This direct relationship from release to releaseTarget looks correct. It should help streamline queries involving releases and their respective targets.

packages/db/src/schema/resource.ts (2)

55-55: Import for new releaseTarget reference.

The import statement is correct and ensures that the release.ts definitions are accessible for the updated resource relations.


102-102: releaseTargets relation properly replaces the legacy concept.

Transitioning to releaseTargets aligns with the restructured schema. This provides a clear, direct relationship to the new release_target table without any apparent issues.

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 (3)
packages/db/src/schema/release.ts (2)

18-40: Consider eliminating the : any cast for desiredReleaseId.
The statement references((): any => release.id, ...) indicates a forward reference workaround. If feasible, reordering definitions or extracting shared types might avoid casting to any.


118-140: Specify references for the releases relationship for clarity.
While Drizzle can infer the linking columns, explicitly defining them (e.g., fields: [release.releaseTargetId], references: [releaseTarget.id]) may increase readability.

packages/release-manager/src/repositories/release-repository.ts (1)

30-54: Optimize retrieval of the most recent release.
The query currently fetches all associated releases, only to return .at(0). Consider limiting the sub-query to mitigate unnecessary data retrieval, for example:

  with: {
    releases: {
+     limit: 1,
      with: {
        version: true,
        variables: true,
      },
    },
  },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9a9145 and bbceb30.

📒 Files selected for processing (6)
  • apps/event-worker/src/releases/variable-change/index.ts (3 hunks)
  • packages/db/src/schema/release.ts (4 hunks)
  • packages/release-manager/src/repositories/release-repository.ts (5 hunks)
  • packages/release-manager/src/types.ts (1 hunks)
  • packages/rule-engine/src/db/create-ctx.ts (2 hunks)
  • packages/rule-engine/src/utils/get-releases.ts (2 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/releases/variable-change/index.ts
  • packages/rule-engine/src/db/create-ctx.ts
  • packages/release-manager/src/types.ts
  • packages/rule-engine/src/utils/get-releases.ts
  • packages/db/src/schema/release.ts
  • packages/release-manager/src/repositories/release-repository.ts
🧬 Code Definitions (4)
packages/rule-engine/src/db/create-ctx.ts (1)
packages/db/src/schema/release.ts (1)
  • releaseTarget (18-40)
packages/rule-engine/src/utils/get-releases.ts (1)
packages/db/src/schema/release.ts (1)
  • releaseTarget (18-40)
packages/db/src/schema/release.ts (3)
packages/db/src/schema/resource.ts (1)
  • resource (59-87)
packages/db/src/schema/environment.ts (1)
  • environment (57-82)
packages/db/src/schema/deployment.ts (1)
  • deployment (66-90)
packages/release-manager/src/repositories/release-repository.ts (2)
packages/release-manager/src/types.ts (2)
  • ReleaseIdentifier (3-7)
  • Release (9-13)
packages/db/src/schema/release.ts (2)
  • releaseTarget (18-40)
  • release (42-55)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (15)
packages/release-manager/src/types.ts (1)

9-13: LGTM: Addition of releaseTargetId to Release type.

This change adds a new required field releaseTargetId to the Release type, which aligns with the database schema updates that introduce the new releaseTarget table.

packages/rule-engine/src/db/create-ctx.ts (1)

4-4: Import statement updated to use releaseTarget instead of resourceRelease.

This update correctly reflects the schema changes where resourceRelease has been removed in favor of releaseTarget.

apps/event-worker/src/releases/variable-change/index.ts (3)

19-30: Query and result mapping updated from resourceRelease to releaseTarget.

The function has been properly updated to query from the new releaseTarget table and join it with the resource table. The result mapping has also been updated to extract data from release_target instead of resource_release.


41-43: LGTM: Updated deploymentId reference

The code now correctly references releaseTarget.deploymentId in the where clause.


57-60: LGTM: Updated resourceId reference

The code now correctly references releaseTarget.resourceId in the where clause.

packages/rule-engine/src/utils/get-releases.ts (4)

54-61: LGTM: Query updated from resourceRelease to releaseTarget.

The database query has been correctly updated to use the new releaseTarget table, with proper where clauses and relation loading.


63-66: LGTM: Variable reference updated for date bounds check.

References to resourceRelease have been properly updated to releaseTarget in the date bounds validation.


68-73: LGTM: Log message updated to reference releaseTarget.

The warning log message has been updated to correctly reference releaseTarget instead of resourceRelease.


88-93: LGTM: Condition updated to use releaseTarget.

The condition for filtering releases by creation date now correctly references releaseTarget instead of resourceRelease.

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

1-1: No remarks needed.


45-47: Foreign key reference is aligned with the new table.
The releaseTargetId field provides a clear one-to-one link to releaseTarget.


89-91: One-to-one relationship is properly defined.
This matches the newly introduced releaseTargetId column on the release table.

packages/release-manager/src/repositories/release-repository.ts (3)

73-84: Clean helper method to fetch the release target.
No issues found.


94-98: Proper null check for the target.
Ensuring releaseTarget exists before creating a release prevents orphan releases.


143-156: Upsert logic appears correct.
Conflict resolution is appropriately handled via the unique index on (environmentId, deploymentId, resourceId).

Comment on lines +18 to 23
return tx.query.releaseTarget.findFirst({
where: and(
eq(resourceRelease.id, repo.resourceId),
eq(resourceRelease.environmentId, repo.environmentId),
eq(resourceRelease.deploymentId, repo.deploymentId),
eq(releaseTarget.id, repo.resourceId),
eq(releaseTarget.environmentId, repo.environmentId),
eq(releaseTarget.deploymentId, repo.deploymentId),
),
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

Database query incorrectly mapping resourceId to releaseTarget.id

The query is comparing releaseTarget.id with repo.resourceId, but based on the releaseTarget schema from the relevant code snippets, it should be comparing releaseTarget.resourceId with repo.resourceId.

  return tx.query.releaseTarget.findFirst({
    where: and(
-      eq(releaseTarget.id, repo.resourceId),
+      eq(releaseTarget.resourceId, repo.resourceId),
      eq(releaseTarget.environmentId, repo.environmentId),
      eq(releaseTarget.deploymentId, repo.deploymentId),
    ),
📝 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
return tx.query.releaseTarget.findFirst({
where: and(
eq(resourceRelease.id, repo.resourceId),
eq(resourceRelease.environmentId, repo.environmentId),
eq(resourceRelease.deploymentId, repo.deploymentId),
eq(releaseTarget.id, repo.resourceId),
eq(releaseTarget.environmentId, repo.environmentId),
eq(releaseTarget.deploymentId, repo.deploymentId),
),
return tx.query.releaseTarget.findFirst({
where: and(
eq(releaseTarget.resourceId, repo.resourceId),
eq(releaseTarget.environmentId, repo.environmentId),
eq(releaseTarget.deploymentId, repo.deploymentId),
),

@jsbroks jsbroks merged commit c1f464a into main Apr 2, 2025
2 of 9 checks passed
@jsbroks jsbroks deleted the clean-up-db-releases branch April 2, 2025 06:58
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.

2 participants