-
Notifications
You must be signed in to change notification settings - Fork 11
init db #420
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 db #420
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughA new dependency, Changes
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
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🪧 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: 0
🧹 Nitpick comments (2)
packages/db/src/schema/rule.ts (2)
33-40: Consider adding foreign key index for policy_target tableWhile 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 implementationThe 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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.tspackages/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 handlingThe addition of the
rrulelibrary (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 exportThe 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 schemaThe addition of the
rrulelibrary (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 setupThe imports look good, including the Options type from rrule and the necessary components from drizzle-orm.
15-31: LGTM: Well-structured policy table definitionThe 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.
packages/db/src/schema/rule.ts
Outdated
| environmentSelector: jsonb("environment_selector").default(sql`NULL`), | ||
| }); | ||
|
|
||
| export const ruleDeploymentDenyEvent = pgTable("rule_deployment_deny_event", { |
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.
policy_rule_deny_window
j7m4
left a comment
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.
one change on table naming per conversation
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: 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis 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.
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: 0
🧹 Nitpick comments (1)
packages/db/src/schema/resource.ts (1)
91-120: Consider renaming the table to match the variable nameThe table name
resource_releasedoesn't match the variable nameresourceDesiredRelease. 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
📒 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.tspackages/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 referencesThe 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 handlingThe 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 relationshipsThe 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 addedThe imports for deployment, environment, and release are correctly added to support the foreign key relationships in the new table.
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: 0
🧹 Nitpick comments (1)
packages/db/src/schema/resource.ts (1)
91-120: The resourceRelease table structure looks goodThe new table has appropriate foreign key constraints with cascade delete actions for
resourceId,environmentId, anddeploymentId, and a "set null" delete action fordesiredReleaseId. The unique index on the combination ofresourceId,environmentId, anddeploymentIdensures proper data integrity.Consider the following suggestions for completeness:
- You might want to add relation definitions for
resourceReleaseas you've done for other tables (likeresourceRelations, etc.)- TypeScript type definitions and schemas for this new table would help with type safety and consistency
- The commented-out fields for
selfReportedReleaseIdindicate 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
📒 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 goodThese import statements are correctly added to provide references for the new
resourceReleasetable. The imports are necessary for the foreign key constraints defined in the new table.
Summary by CodeRabbit
rrulelibrary for handling recurrence rules in date and time calculations.