Skip to content

Conversation

@jsbroks
Copy link
Member

@jsbroks jsbroks commented Mar 27, 2025

Summary by CodeRabbit

  • New Features
    • Introduced enhanced recurrence scheduling for better management of repeating events.
    • Expanded policy and event management capabilities through improved data structures.
    • Added new database tables for policies, their targets, releases, and associated variables, enhancing data organization.
    • New table added for managing resource-release relationships.
  • Dependencies
    • Added the rrule library for handling recurrence rules in date and time calculations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new dependency, "rrule" version ^2.8.1, has been added to both the API and DB packages to handle recurrence rules in date and time management. The DB schema has been expanded by exporting new modules and introducing new TypeScript files that define multiple database tables—policy, policyTarget, policyRuleDenyWindow, release, releaseVariable, releaseJob, and resourceRelease—using the Drizzle ORM with appropriate fields and constraints.

Changes

File(s) Change Summary
packages/api/package.json
packages/db/package.json
Added dependency "rrule": "^2.8.1" in the dependencies section to enable recurrence rule handling.
packages/db/src/schema/index.ts Added export statements export * from "./rule.js"; and export * from "./release.js"; to include new module exports.
packages/db/src/schema/rule.ts New file defining three tables (policy, policyTarget, and policyRuleDenyWindow) with fields, constraints, and cascading foreign key relationships via Drizzle ORM.
packages/db/src/schema/release.ts New file defining three tables (release, releaseVariable, and releaseJob) with fields, constraints, and relationships via Drizzle ORM.
packages/db/src/schema/resource.ts New table defined: resourceRelease with fields and foreign key constraints to capture relationships between resources and their desired releases.
packages/db/drizzle/0081_fresh_christian_walker.sql Introduced new SQL tables and constraints for resource_release, policy, policy_rule_deny_window, policy_target, release, release_job, and release_variable.
packages/db/drizzle/meta/_journal.json Added a new entry to the journal with index 81, version 7, and tag "0081_fresh_christian_walker".

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant DB
    participant RRULE
    Client->>API: Request recurrence event details
    API->>DB: Query policy and rule data
    DB->>RRULE: Process recurrence rule using rrule library
    RRULE-->>DB: Return computed recurrence dates
    DB-->>API: Provide rule and schedule data
    API-->>Client: Respond with rule-based event schedule
Loading

Possibly related PRs

  • init deny rule #421: The changes in the main PR and the retrieved PR are related through the addition of the rrule library, which is utilized in both PRs for handling recurrence rules in date and time management.

Poem

I'm a rabbit, hopping with delight,
New code sprouts bright in the moonlit night.
Dependencies added, tables all in line,
Recurrence rules now perfectly align.
I wiggle my ears, excited and spry—
Coding magic makes this bunny fly!
🐇✨


📜 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 ee20c99 and ad303f4.

📒 Files selected for processing (2)
  • packages/db/drizzle/0081_fresh_christian_walker.sql (1 hunks)
  • packages/db/drizzle/meta/_journal.json (1 hunks)

🪧 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: 0

🧹 Nitpick comments (2)
packages/db/src/schema/rule.ts (2)

33-40: Consider adding foreign key index for policy_target table

While the foreign key is properly defined, adding an index on the policyId column would improve query performance, especially for queries filtering or joining on this column.

export const policyTarget = pgTable("policy_target", {
  id: uuid("id").primaryKey().defaultRandom(),
  policyId: uuid("policy_id")
    .notNull()
+    .index()
    .references(() => policy.id, { onDelete: "cascade" }),
  deploymentSelector: jsonb("deployment_selector").default(sql`NULL`),
  environmentSelector: jsonb("environment_selector").default(sql`NULL`),
});

42-58: LGTM: Well-structured deny event table with proper rrule implementation

The ruleDeploymentDenyEvent table is well-defined with appropriate fields. The rrule field is correctly typed to match the Options interface from the rrule library, and the comment is helpful for understanding the implementation.

Consider adding an index on the policyId field for improved query performance, similar to the suggestion for the policyTarget table.

export const ruleDeploymentDenyEvent = pgTable("rule_deployment_deny_event", {
  id: uuid("id").primaryKey().defaultRandom(),

  policyId: uuid("policy_id")
    .notNull()
+    .index()
    .references(() => policy.id, { onDelete: "cascade" }),

  name: text("name").notNull(),
  description: text("description"),

  // RRule fields stored as JSONB to match Options interface
  rrule: jsonb("rrule").notNull().default("{}").$type<Options>(),

  createdAt: timestamp("created_at", { withTimezone: true })
    .notNull()
    .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 d154355 and 99febc8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • packages/api/package.json (1 hunks)
  • packages/db/package.json (1 hunks)
  • packages/db/src/schema/index.ts (1 hunks)
  • packages/db/src/schema/rule.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.

  • packages/db/src/schema/index.ts
  • packages/db/src/schema/rule.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (5)
packages/api/package.json (1)

43-43: LGTM: Added dependency for recurrence rule handling

The addition of the rrule library (version ^2.8.1) is appropriate for handling recurrence rules in date/time management.

packages/db/src/schema/index.ts (1)

25-25: LGTM: New schema export

The export statement for the new rule schema has been properly integrated into the existing export list.

packages/db/package.json (1)

47-47: LGTM: Added dependency for rule schema

The addition of the rrule library (version ^2.8.1) is consistent with its usage in the rule schema for handling recurrence rules.

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

1-14: LGTM: Proper imports and setup

The imports look good, including the Options type from rrule and the necessary components from drizzle-orm.


15-31: LGTM: Well-structured policy table definition

The policy table is well-defined with appropriate fields and constraints. The foreign key relationship to the workspace table is properly set up with cascade deletion.

environmentSelector: jsonb("environment_selector").default(sql`NULL`),
});

export const ruleDeploymentDenyEvent = pgTable("rule_deployment_deny_event", {
Copy link
Collaborator

Choose a reason for hiding this comment

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

policy_rule_deny_window

Copy link
Collaborator

@j7m4 j7m4 left a comment

Choose a reason for hiding this comment

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

one change on table naming per conversation

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: 0

🧹 Nitpick comments (2)
packages/db/src/schema/rule.ts (2)

15-31: Well-structured policy table definition.

The policy table has a good structure with:

  • Properly defined primary key with auto-generated UUID
  • Appropriate fields for policy metadata
  • Clear foreign key relationship to workspace
  • Good default values and constraints

Consider adding indexes for the foreign key (workspaceId) if you anticipate querying policies by workspace frequently.


55-55: Consider validating timeZone values.

While storing timeZone as text is common, consider adding runtime validation to ensure only valid IANA timezone identifiers are stored (e.g., "America/New_York", "Europe/London").

You could implement this validation in your API layer or create a custom validation function in your schema.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99febc8 and 5e5e030.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • packages/db/src/schema/rule.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.

  • packages/db/src/schema/rule.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (6)
packages/db/src/schema/rule.ts (6)

1-14: Good choice of imports for the database schema.

The imports are appropriately selected for a Drizzle ORM setup with PostgreSQL, including the Options type from rrule that will be used for the recurrence rules.


33-40: Verify the NULL default syntax for JSONB fields.

The policy target table looks good overall with proper foreign key relationships. However, the default(sql\NULL`)` syntax for JSONB fields is worth double-checking.

While a previous reviewer confirmed this works with PostgreSQL, consider if an empty object {} might be more appropriate than NULL for these selector fields, depending on how your application code handles these values.


42-43: Table naming follows proper convention.

The table name "policy_rule_deny_window" follows the snake_case convention appropriate for PostgreSQL tables.


44-48: Foreign key relationship properly defined.

The relationship to the policy table is correctly established with cascade delete behavior, which will automatically remove related deny windows when a policy is deleted.


52-54: Good use of JSONB for flexible recurrence rules.

Storing the RRule as JSONB with proper type association to the Options interface is an excellent approach that provides both flexibility and type safety.


56-59: Timestamp definition looks good.

According to the previous review comment, this timestamp definition works fine with PostgreSQL. The with timezone option is important for consistent datetime handling across different regions.

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: 0

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

91-120: Consider renaming the table to match the variable name

The table name resource_release doesn't match the variable name resourceDesiredRelease. While this works functionally, it might create confusion when referencing the table in code or when examining the database directly.

Also, consider removing commented code (lines 110-116) until it's needed to maintain cleaner code.

-export const resourceDesiredRelease = pgTable(
-  "resource_release",
+export const resourceDesiredRelease = pgTable(
+  "resource_desired_release",
   {
     id: uuid("id").primaryKey().defaultRandom(),

     resourceId: uuid("resource_id")
       .references(() => resource.id, { onDelete: "cascade" })
       .notNull(),
     environmentId: uuid("environment_id")
       .references(() => environment.id, { onDelete: "cascade" })
       .notNull(),
     deploymentId: uuid("deployment_id")
       .references(() => deployment.id, { onDelete: "cascade" })
       .notNull(),

     desiredReleaseId: uuid("desired_release_id")
       .references(() => release.id, { onDelete: "set null" })
       .default(sql`NULL`),

-    // selfReportedReleaseId: uuid("self_reported_release_id")
-    //   .references(() => release.id, { onDelete: "set null" })
-    //   .default(sql`NULL`),
-    // lastReportedAt: timestamp("last_reported_at", {
-    //   withTimezone: true,
-    // }).default(sql`NULL`),
   },
   (t) => ({
     uniq: uniqueIndex().on(t.resourceId, t.environmentId, t.deploymentId),
   }),
 );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e5e030 and 47748d5.

📒 Files selected for processing (3)
  • packages/db/src/schema/index.ts (1 hunks)
  • packages/db/src/schema/release.ts (1 hunks)
  • packages/db/src/schema/resource.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/db/src/schema/index.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 (3)
packages/db/src/schema/environment.ts (1)
  • environment (49-74)
packages/db/src/schema/deployment.ts (1)
  • deployment (63-87)
packages/db/src/schema/release.ts (1)
  • release (17-36)
packages/db/src/schema/release.ts (4)
packages/db/src/schema/resource.ts (1)
  • resource (61-89)
packages/db/src/schema/deployment.ts (1)
  • deployment (63-87)
packages/db/src/schema/environment.ts (1)
  • environment (49-74)
packages/db/src/schema/job.ts (1)
  • job (74-106)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (4)
packages/db/src/schema/release.ts (3)

17-36: LGTM - Well-structured release table with proper references

The release table definition follows good database design practices with appropriate primary key, foreign keys to related tables, and cascading delete behavior which will help maintain referential integrity.


38-50: LGTM - Proper variable storage with sensitivity handling

The releaseVariable table is well-designed with:

  • Appropriate cascading delete behavior on the parent release
  • Unique constraint on releaseId+key combination
  • Boolean flag for sensitive information which will be useful for security purposes

52-63: LGTM - Good job tracking release-job relationships

The releaseJob table correctly establishes the many-to-many relationship between releases and jobs with proper cascading delete behaviors and timestamps.

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

53-57: LGTM - Necessary imports added

The imports for deployment, environment, and release are correctly added to support the foreign key relationships in the new table.

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: 0

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

91-120: The resourceRelease table structure looks good

The new table has appropriate foreign key constraints with cascade delete actions for resourceId, environmentId, and deploymentId, and a "set null" delete action for desiredReleaseId. The unique index on the combination of resourceId, environmentId, and deploymentId ensures proper data integrity.

Consider the following suggestions for completeness:

  1. You might want to add relation definitions for resourceRelease as you've done for other tables (like resourceRelations, etc.)
  2. TypeScript type definitions and schemas for this new table would help with type safety and consistency
  3. The commented-out fields for selfReportedReleaseId indicate future functionality. Consider documenting the plan for these fields or adding a TODO comment.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 47748d5 and ee20c99.

📒 Files selected for processing (1)
  • packages/db/src/schema/resource.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.

  • packages/db/src/schema/resource.ts
🧬 Code Definitions (1)
packages/db/src/schema/resource.ts (3)
packages/db/src/schema/environment.ts (1)
  • environment (49-74)
packages/db/src/schema/deployment.ts (1)
  • deployment (63-87)
packages/db/src/schema/release.ts (1)
  • release (17-36)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Lint
  • GitHub Check: Typecheck
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (1)
packages/db/src/schema/resource.ts (1)

53-57: Import additions look good

These import statements are correctly added to provide references for the new resourceRelease table. The imports are necessary for the foreign key constraints defined in the new table.

@jsbroks jsbroks merged commit 8d87773 into main Mar 28, 2025
8 of 10 checks passed
@jsbroks jsbroks deleted the policy-db-init branch March 28, 2025 05:42
@coderabbitai coderabbitai bot mentioned this pull request Mar 30, 2025
@coderabbitai coderabbitai bot mentioned this pull request Apr 6, 2025
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