Skip to content
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

init eph envs #179

Merged
merged 7 commits into from
Oct 28, 2024
Merged

init eph envs #179

merged 7 commits into from
Oct 28, 2024

Conversation

jsbroks
Copy link
Member

@jsbroks jsbroks commented Oct 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new releaseChannel table to manage release information.
    • Added rolloutDuration, ephemeralDuration, and createdAt fields to enhance environment policy tracking.
    • New tables for environment_policy_release_channel and environment_release_channel to support deployment channel relationships.
  • Bug Fixes

    • Removed deprecated releaseFilter field, streamlining the environment policy schema.

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 8bd395e and 067574c.

Walkthrough

The pull request introduces significant modifications to the database schema in the environment.ts and release.ts files. Key changes include the removal of the releaseFilter field from the environmentPolicy table, replaced by rolloutDuration and ephemeralDuration. A new createdAt timestamp field is added to the environment table. Additionally, new tables for environment_policy_release_channel and environment_release_channel are introduced. The release.ts file sees the addition of a releaseChannel table, which includes various fields related to release management.

Changes

File Path Change Summary
packages/db/src/schema/environment.ts - Removed releaseFilter from environmentPolicy table.
- Added rolloutDuration and ephemeralDuration fields to environmentPolicy table.
- Renamed duration to rolloutDuration.
- Added createdAt field to environment table.
- Introduced new tables: environment_policy_release_channel and environment_release_channel.
packages/db/src/schema/release.ts - Added new releaseChannel table with fields: id, name, description, deploymentId, and releaseFilter.

Possibly related PRs

  • fix: Remove semver and regex release filter #160: The changes in this PR involve the removal of the releaseFilter field from the environmentPolicy schema and its integration into a new schema definition, which aligns with the modifications made in the main PR regarding the restructuring of the environmentPolicy table and the handling of release conditions.

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?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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: 3

🧹 Outside diff range and nitpick comments (3)
packages/db/src/schema/release.ts (1)

51-51: Add documentation for the releaseChannel table.

Since this table is part of the ephemeral environments feature, consider adding a comment block above the table definition explaining:

  • The purpose of release channels
  • How they relate to ephemeral environments
  • The significance of the releaseFilter field
+/**
+ * Release channels manage the flow of releases to environments,
+ * particularly for ephemeral environment management.
+ * 
+ * The releaseFilter determines which releases can flow through
+ * this channel based on conditions like metadata, version, or
+ * creation date.
+ */
 export const releaseChannel = pgTable("release_channel", {
packages/db/src/schema/environment.ts (2)

96-100: Consider including units in the field name for clarity

While the comment specifies that rolloutDuration is in milliseconds, explicitly indicating the unit in the field name (e.g., rolloutDurationMs) can enhance clarity and prevent potential confusion.


102-105: Include units in ephemeralDuration field name for consistency

Similar to rolloutDuration, consider renaming ephemeralDuration to ephemeralDurationMs to make the unit of measurement explicit and maintain consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 07dce71 and 8bd395e.

📒 Files selected for processing (2)
  • packages/db/src/schema/environment.ts (5 hunks)
  • packages/db/src/schema/release.ts (1 hunks)
🔇 Additional comments (4)
packages/db/src/schema/release.ts (1)

58-60: Verify releaseFilter compatibility with existing condition builders.

The releaseFilter field uses the same ReleaseCondition type that's used by the buildCondition function. Ensure that the releaseMatchesCondition function (lines 257-262) properly handles the new use case from the release channel.

✅ Verification successful

Release filter implementation is compatible with existing usage

Based on the verification results:

  • The releaseMatchesCondition function is used consistently across the codebase in multiple components (job-dispatch, API routes) with the same ReleaseCondition type
  • The ReleaseCondition type is well-defined and shared across the codebase
  • The new releaseFilter field in the release channel table follows the same pattern as existing implementations in other components
  • Existing code already handles null cases for release filters

The implementation is consistent with current usage patterns and type definitions, ensuring compatibility with the condition building functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any existing usage of releaseMatchesCondition with release channels
# to ensure compatibility

# Look for any connections between release channels and condition matching
rg -l "releaseMatchesCondition.*releaseChannel|releaseChannel.*releaseMatchesCondition"

# Check for any potential type mismatches or incompatible usage
ast-grep --pattern 'releaseMatchesCondition($_, $release_filter)'

Length of output: 157


Script:

#!/bin/bash
# Let's first check the implementation of releaseMatchesCondition and its usage
rg -A 5 "releaseMatchesCondition" 

# Check the ReleaseCondition type definition
rg -A 5 "type ReleaseCondition"

# Look for any existing usage of releaseFilter
rg "releaseFilter"

# Check for any release channel related functions
rg -A 5 "releaseChannel"

Length of output: 11384

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

21-22: Imports correctly added for new dependencies

The new imports for deployment, release, and releaseChannel are necessary for the entities used later in the schema definitions.


41-43: Good practice adding createdAt timestamp

Including the createdAt field with a default of the current time ensures that the creation time of each environment is recorded, which is beneficial for tracking and auditing purposes.


114-116: Ensure validation for new duration fields in createEnvironmentPolicy

With the addition of rolloutDuration and ephemeralDuration, please ensure that createEnvironmentPolicy includes appropriate validation for these fields. This could involve setting minimum and maximum acceptable values to prevent invalid or unintended data inputs.

Comment on lines +51 to +61
export const releaseChannel = pgTable("release_channel", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
description: text("description").default(""),
deploymentId: uuid("deployment_id")
.notNull()
.references(() => deployment.id, { onDelete: "cascade" }),
releaseFilter: jsonb("release_filter")
.$type<ReleaseCondition | null>()
.default(sql`NULL`),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding constraints and audit fields to the releaseChannel table.

While the basic structure is sound, consider the following improvements:

  1. Add a unique constraint to prevent duplicate channel names within a deployment:
 export const releaseChannel = pgTable("release_channel", {
   id: uuid("id").primaryKey().defaultRandom(),
   name: text("name").notNull(),
   description: text("description").default(""),
   deploymentId: uuid("deployment_id")
     .notNull()
     .references(() => deployment.id, { onDelete: "cascade" }),
   releaseFilter: jsonb("release_filter")
     .$type<ReleaseCondition | null>()
     .default(sql`NULL`),
+ }, (t) => ({
+   unq: uniqueIndex().on(t.name, t.deploymentId)
 });
  1. Add timestamp fields for better auditing:
   releaseFilter: jsonb("release_filter")
     .$type<ReleaseCondition | null>()
     .default(sql`NULL`),
+  createdAt: timestamp("created_at").notNull().defaultNow(),
+  updatedAt: timestamp("updated_at").notNull().defaultNow(),
  1. Consider using NULL instead of empty string for description:
-  description: text("description").default(""),
+  description: text("description").default(sql`NULL`),

Committable suggestion was skipped due to low confidence.

Comment on lines 222 to 240
export const environmentReleaseChannel = pgTable(
"environment_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
environmentId: uuid("environment_id")
.notNull()
.references(() => environment.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.environmentId, t.channelId),
deploymentUniq: uniqueIndex().on(
t.environmentId,
sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
),
}),
);
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 issue with unique index using a subquery

Similar to the previous comment, the deploymentUniq unique index in the environmentReleaseChannel table uses a subquery, which may not be valid in index definitions and could cause database errors.

Consider modifying the schema to avoid subqueries in the unique index. Adding a deploymentId field and adjusting the unique index accordingly can resolve this issue:

 export const environmentReleaseChannel = pgTable(
   "environment_release_channel",
   {
     id: uuid("id").primaryKey().defaultRandom(),
     environmentId: uuid("environment_id")
       .notNull()
       .references(() => environment.id, { onDelete: "cascade" }),
     channelId: uuid("channel_id")
       .notNull()
       .references(() => releaseChannel.id, { onDelete: "cascade" }),
+    deploymentId: uuid("deployment_id")
+      .notNull()
+      .references(() => deployment.id, { onDelete: "cascade" }),
   },
   (t) => ({
     uniq: uniqueIndex().on(t.environmentId, t.channelId),
-    deploymentUniq: uniqueIndex().on(
-      t.environmentId,
-      sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
-    ),
+    deploymentUniq: uniqueIndex().on(t.environmentId, t.deploymentId),
   }),
 );

This adjustment aligns the unique index definition with standard practices and ensures compatibility with the database.

📝 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
export const environmentReleaseChannel = pgTable(
"environment_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
environmentId: uuid("environment_id")
.notNull()
.references(() => environment.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.environmentId, t.channelId),
deploymentUniq: uniqueIndex().on(
t.environmentId,
sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
),
}),
);
export const environmentReleaseChannel = pgTable(
"environment_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
environmentId: uuid("environment_id")
.notNull()
.references(() => environment.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
deploymentId: uuid("deployment_id")
.notNull()
.references(() => deployment.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.environmentId, t.channelId),
deploymentUniq: uniqueIndex().on(t.environmentId, t.deploymentId),
}),
);

Comment on lines 202 to 220
export const environmentPolicyReleaseChannel = pgTable(
"environment_policy_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
policyId: uuid("policy_id")
.notNull()
.references(() => environmentPolicy.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.policyId, t.channelId),
deploymentUniq: uniqueIndex().on(
t.policyId,
sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
),
}),
);
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 issue with unique index using a subquery

Defining deploymentUniq with a subquery in the uniqueIndex() may not be supported by the database and could lead to migration or runtime errors. Unique indexes typically operate directly on columns of the table.

Consider adjusting the schema to avoid using a subquery in the unique index. One approach is to add a deploymentId field to the table and use it in the unique index. Here's how you might modify the code:

 export const environmentPolicyReleaseChannel = pgTable(
   "environment_policy_release_channel",
   {
     id: uuid("id").primaryKey().defaultRandom(),
     policyId: uuid("policy_id")
       .notNull()
       .references(() => environmentPolicy.id, { onDelete: "cascade" }),
     channelId: uuid("channel_id")
       .notNull()
       .references(() => releaseChannel.id, { onDelete: "cascade" }),
+    deploymentId: uuid("deployment_id")
+      .notNull()
+      .references(() => deployment.id, { onDelete: "cascade" }),
   },
   (t) => ({
     uniq: uniqueIndex().on(t.policyId, t.channelId),
-    deploymentUniq: uniqueIndex().on(
-      t.policyId,
-      sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
-    ),
+    deploymentUniq: uniqueIndex().on(t.policyId, t.deploymentId),
   }),
 );

This change adds a deploymentId field to the table schema and modifies the unique index to use this field directly.

📝 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
export const environmentPolicyReleaseChannel = pgTable(
"environment_policy_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
policyId: uuid("policy_id")
.notNull()
.references(() => environmentPolicy.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.policyId, t.channelId),
deploymentUniq: uniqueIndex().on(
t.policyId,
sql`(SELECT ${deployment.id} FROM ${releaseChannel} WHERE id = ${t.channelId})`,
),
}),
);
export const environmentPolicyReleaseChannel = pgTable(
"environment_policy_release_channel",
{
id: uuid("id").primaryKey().defaultRandom(),
policyId: uuid("policy_id")
.notNull()
.references(() => environmentPolicy.id, { onDelete: "cascade" }),
channelId: uuid("channel_id")
.notNull()
.references(() => releaseChannel.id, { onDelete: "cascade" }),
deploymentId: uuid("deployment_id")
.notNull()
.references(() => deployment.id, { onDelete: "cascade" }),
},
(t) => ({
uniq: uniqueIndex().on(t.policyId, t.channelId),
deploymentUniq: uniqueIndex().on(t.policyId, t.deploymentId),
}),
);

@@ -90,11 +93,16 @@ export const environmentPolicy = pgTable("environment_policy", {
concurrencyType: concurrencyType("concurrency_type").notNull().default("all"),
concurrencyLimit: integer("concurrency_limit").notNull().default(1),

duration: bigint("duration", { mode: "number" }).notNull().default(0),
// Duration in milliseconds over which to gradually roll out releases to this
Copy link
Contributor

Choose a reason for hiding this comment

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

wait are we doing seconds or milliseconds

Copy link
Member Author

Choose a reason for hiding this comment

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

we can do seconds after we migrate this, low p

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