Skip to content

Improved Vendor Table - #153

Merged
claudfuen merged 3 commits into
mainfrom
claudio/misc-fixes
Mar 19, 2025
Merged

claudfuen merged 3 commits into
mainfrom
claudio/misc-fixes

Conversation

@claudfuen

@claudfuen claudfuen commented Mar 19, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Expanded vendor management with enhanced risk assessment, categorization, and status tracking.
    • Improved task handling with additional details for assignments, comments, and file attachments.
  • Chores

    • Updated and optimized backend database structure for improved data consistency and performance.

- Created a new migration to add the Vendor table and associated columns, including foreign key constraints and unique indexes.
- Introduced new enums for task status and attachment types.
- Updated existing tables to include necessary columns and constraints, ensuring data integrity.
- Cleared existing assignments in VendorTaskAssignment to prevent unique constraint violations.
- Added new fields to the Vendor model, including category, status, inherentRisk, and residualRisk with default values.
- Introduced new enums for VendorCategory, VendorStatus, VendorInherentRisk, VendorResidualRisk, VendorTaskStatus, VendorAttachmentType, and updated related models.
- Updated relationships and added cascading delete behavior for improved data integrity.
- Enhanced VendorTaskAssignment model with unique constraints and additional indexing for better query performance.
@CLAassistant

CLAassistant commented Mar 19, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Mar 19, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 4:14pm
comp-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 4:14pm

@coderabbitai

coderabbitai Bot commented Mar 19, 2025 •

Copy link
Copy Markdown

Walkthrough

This pull request introduces changes to the vendor-related database schema. A migration script adds new enumerated types, columns, indexes, and redefines foreign key constraints with cascading delete options across vendor-associated tables. In addition, the Prisma schema is updated across multiple models—Employee, User, and Vendor—to include new fields, relation arrays, and extra enums for risk and task management. These modifications adjust the data structure and relationships for vendor management.

Changes

File(s) Change Summary
packages/db/prisma/migrations/.../migration.sql Updated DB migration: added enums (RiskLikelihood, RiskImpact, VendorTaskStatus, VendorAttachmentType), introduced new columns (e.g., ownerId, fileKey, fileUrl, etc.), created new indexes, and re-established foreign key constraints for vendor-related tables.
packages/db/prisma/schema/(employee, schema, vendor).prisma Modified Prisma schemas: added a VendorTaskAssignment relation to the Employee model; extended the User model with vendor-related arrays and enums; updated Vendor and its related models (VendorContact, VendorComment, VendorAttachment, VendorTask, VendorTaskAttachment, VendorTaskComment, VendorTaskAssignment) with new fields and cascading delete relationships.

Poem

I’m a rabbit hopping through lines of code so neat,
Migrating schemas with a rhythmic beat,
New enums and fields join the dance in view,
Cascading deletes and indexes all brand new,
With a twitch of my nose, the changes now shine through!
Hop on, dear coder, and keep that code true!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/prisma/schema/vendor.prisma (1)

12-14: Optional Owner Relationship in Vendor Model

The optional ownerId field, along with its relation to the User model, is a solid enhancement for attributing vendor ownership. Consider whether you need to enforce specific ON DELETE behavior on this relation to suit your data retention policies.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5af6590 and 42b2391.

📒 Files selected for processing (4)
  • packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql (1 hunks)
  • packages/db/prisma/schema/employee.prisma (1 hunks)
  • packages/db/prisma/schema/schema.prisma (2 hunks)
  • packages/db/prisma/schema/vendor.prisma (3 hunks)
🔇 Additional comments (20)
packages/db/prisma/schema/employee.prisma (1)

44-44: Added VendorTaskAssignment Field in Employee Model

The addition of the VendorTaskAssignment VendorTaskAssignment[] relation is well integrated. It expands the functionality to track vendor task assignments for employees. Ensure that the corresponding model is correctly defined and that related queries are updated accordingly.

packages/db/prisma/schema/schema.prisma (1)

71-76: New Vendor-Related Fields Added to User Model

The new fields (Vendor, VendorComment, VendorAttachment, VendorTask, VendorTaskAttachment, and VendorTaskComment) have been added as arrays in the User model. This expansion aligns the user schema with vendor management enhancements. Please ensure that any business logic or UI components using the User model are updated to reflect these changes.

packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql (10)

24-35: Enum Creation

The script creates enums for RiskLikelihood, RiskImpact, VendorTaskStatus, and VendorAttachmentType. These definitions match those in your Prisma schema. It’s important to confirm that the enum values remain consistent between your database and schema.


36-80: Dropping Existing Foreign Key Constraints

Foreign key constraints are dropped from several vendor-related tables to facilitate schema modifications. Verify that these drops won’t disrupt any real-time operations and that the application is prepared for a brief period without enforced relational integrity.


92-100: Updates to VendorComment and VendorContact Tables

Columns such as createdAt, ownerId, and updatedAt are added to VendorComment, and createdAt and updatedAt are added to VendorContact. Default values are provided for timestamp fields, which is good. However, be mindful of the NOT NULL constraints on fields like ownerId if existing rows lack this data.


112-116: VendorTaskAssignment Table Update

The migration adds assignedAt (with a default), and makes employeeId and taskId required. The subsequent unique constraint on (taskId, employeeId) will enforce data integrity. It’s important to verify that no existing data violates this uniqueness.


126-132: VendorTaskComment Table Update

The addition of columns (content, createdAt, ownerId, taskId, and updatedAt) to the VendorTaskComment table improves comment tracking. Make sure that data migration handles these new required fields on existing rows.


133-164: Index Creation for Optimizing Queries

Indexes are created on new columns across various tables, which should improve query performance. Verify that the selected index columns align with the most common query filters in your application.


166-240: Re-establishing Foreign Key Constraints

The script re-adds foreign key constraints across vendor-related tables. Note the different ON DELETE actions (e.g., CASCADE or SET NULL). Confirm that these behaviors are consistent with your application's data management and business logic.


81-91:

Details

❓ Verification inconclusive

Alter Table Modifications for Vendor and VendorAttachment

New columns are added to the Vendor table (ownerId) and to the VendorAttachment table (e.g. fileKey, fileUrl, name, ownerId, type, uploadedAt). Note that some new columns marked as NOT NULL (like fileUrl and name) lack a defined default value. Double-check these changes against existing data to prevent migration failures.


Action Required: Verify Migration Data Safety for Vendor and VendorAttachment Tables

The migration file at packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql (lines 81–91) introduces new columns to both tables:

  • Vendor Table: Adds the ownerId column.
  • VendorAttachment Table: Adds several columns including fileKey, fileUrl, name, ownerId, type, and uploadedAt.

Key Concern:
The fileUrl and name columns are defined as TEXT NOT NULL without a default value. This setup may cause migration failures if existing records lack these values.

Recommendation:
Double-check the migration against your current dataset. Ensure that either appropriate default values are provided or that existing records are handled to prevent issues during migration.


117-124:

Details

❓ Verification inconclusive

VendorTaskAttachment Table Alterations

New columns are introduced in the VendorTaskAttachment table such as fileKey, fileUrl, name, ownerId, taskId, type, and uploadedAt. As with similar changes, ensure that required columns like fileUrl, name, taskId, and type are populated correctly to avoid migration issues.


Action Required: Verify Data Integrity in VendorTaskAttachment Migration

The migration for the VendorTaskAttachment table adds several columns—fileKey, fileUrl, name, ownerId, taskId, type, and uploadedAt—without including any steps to handle existing rows. Note that while fileUrl, name, taskId, and type are defined as NOT NULL (with type having a default), no defaults or update steps are provided for the other required columns. Please ensure that:

  • For any existing records, proper default values or data migration steps are implemented so that the NOT NULL constraints are not violated.
  • The migration process is tested to confirm that these new columns are correctly populated, especially in environments with pre-existing data.

File: packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
Lines: 117-124


101-111:

Details

❓ Verification inconclusive

Alter Table Changes for VendorTask

A suite of new columns (e.g., completedAt, createdAt, description, dueDate, notifiedAt, ownerId, status, title, updatedAt) is added to the VendorTask table. The required fields (notably description, title, and updatedAt) lack a default value, so confirm that existing records can accommodate these changes or that data is pre-populated.



Action: Verify Handling of Required Fields in VendorTask Migration

The migration adds several new columns to the VendorTask table. Notably, columns such as description, title, and updatedAt are marked as NOT NULL without a default value. Please confirm that existing records can accommodate these changes—either through prior data pre-population or another migration step to update existing rows—so that no record violates the non-null constraint. Consider refactoring the migration if necessary to include defaults or additional data migration logic.


🏁 Script executed:

#!/bin/bash
# Verify that required non-nullable columns (description, title, updatedAt) in the migration
# do not include default values in the migration script.
# We use 'rg' to search for the respective patterns in the migration file.

rg 'ADD COLUMN\s+"description"\s+TEXT NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
rg 'ADD COLUMN\s+"title"\s+TEXT NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
rg 'ADD COLUMN\s+"updatedAt"\s+TIMESTAMP\(3\)\s+NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql

Length of output: 1459


Manual Verification Required: VendorTask Migration Non-Nullable Columns

The migration adds several new columns to the VendorTask table. Of particular note, the required fields (description, title, and updatedAt) do not include default values. Please verify that either:

  • Existing rows have been updated with appropriate values prior to this migration, or
  • A subsequent data-population step will prevent non-null constraint violations during deployment.

Ensure that handling for existing records is in place to avoid issues with these non-nullable columns during the migration.


🏁 Script executed:

#!/bin/bash
# Re-run verification for non-nullable columns using PCRE2 lookahead assertions.
rg --pcre2 'ADD COLUMN\s+"description"\s+TEXT NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
rg --pcre2 'ADD COLUMN\s+"title"\s+TEXT NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
rg --pcre2 'ADD COLUMN\s+"updatedAt"\s+TIMESTAMP\(3\)\s+NOT NULL(?!.*DEFAULT)' packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql

Length of output: 854


VendorTask Migration: Verify Non-Null Handling

The migration adds several new columns to the VendorTask table. Notably, the required fields description, title, and updatedAt do not include default values. Please manually verify that either existing records will be updated with valid values or that a subsequent migration/data-population step will ensure no record violates these non-null constraints.

  • File: packages/db/prisma/migrations/20250319160739_added_vendor_table/migration.sql
  • Concern: The columns description, title, and updatedAt are defined as NOT NULL without defaults.
  • Action: Confirm that a data migration or pre-population process is in place to handle existing records.
packages/db/prisma/schema/vendor.prisma (8)

5-8: New Vendor Fields

The new fields category, status, inherentRisk, and residualRisk are added with sensible default values. They enhance the vendor model by enabling more granular categorization and risk assessment. Verify that these defaults are in line with business requirements.


38-41: VendorContact Timestamps

The addition of createdAt and updatedAt fields in the VendorContact model ensures automatic tracking of record changes. The default and @updatedAt settings follow best practices.


51-57: Enhancements to VendorComment Model

The new ownerId field and timestamp columns (createdAt, updatedAt) in the VendorComment model improve traceability. These changes align with your overall strategy for enhanced record-keeping.


65-76: VendorAttachment Enhancements

The VendorAttachment model has been significantly expanded to include file metadata such as name, fileUrl, fileKey, type, and uploadedAt, as well as an optional ownerId. Confirm the migration strategy to ensure that existing attachments receive valid values for these newly required fields.


83-106: Updated VendorTask Model

The VendorTask model now includes fields for title, description, status, dueDate, notifiedAt, completedAt, and an optional ownerId. These additions create a more comprehensive task representation. Make sure that all business processes interacting with vendor tasks are updated to accommodate the new mandatory fields.


108-128: Enhanced VendorTaskAttachment Model

The modifications to VendorTaskAttachment—including new columns for file details and an optional owner reference—improve file management within tasks. It is crucial to confirm that these enhancements are supported by the file upload and retrieval logic in the application.


130-148: Updated VendorTaskComment Model

Improvements to the VendorTaskComment model, such as the addition of ownerId and timestamp management, bolster comment tracking on vendor tasks. The changes appear consistent with similar models.


150-167: VendorTaskAssignment Model Improvements

The inclusion of an assignedAt timestamp and the new required fields (employeeId, taskId) along with the unique constraint on (taskId, employeeId) ensure strong data integrity for task assignments. Verify that the existing data will not conflict with this new constraint.

Comment on lines +1 to +23
/*
Warnings:

- A unique constraint covering the columns `[taskId,employeeId]` on the table `VendorTaskAssignment` will be added. If there are existing duplicate values, this will fail.
- Added the required column `fileUrl` to the `VendorAttachment` table without a default value. This is not possible if the table is not empty.
- Added the required column `name` to the `VendorAttachment` table without a default value. This is not possible if the table is not empty.
- Added the required column `ownerId` to the `VendorComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `VendorComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `VendorContact` table without a default value. This is not possible if the table is not empty.
- Added the required column `description` to the `VendorTask` table without a default value. This is not possible if the table is not empty.
- Added the required column `title` to the `VendorTask` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `VendorTask` table without a default value. This is not possible if the table is not empty.
- Added the required column `employeeId` to the `VendorTaskAssignment` table without a default value. This is not possible if the table is not empty.
- Added the required column `taskId` to the `VendorTaskAssignment` table without a default value. This is not possible if the table is not empty.
- Added the required column `fileUrl` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty.
- Added the required column `name` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty.
- Added the required column `taskId` to the `VendorTaskAttachment` table without a default value. This is not possible if the table is not empty.
- Added the required column `content` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `ownerId` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `taskId` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `VendorTaskComment` table without a default value. This is not possible if the table is not empty.

*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Critical: Migration Warnings & NOT NULL Columns Without Defaults

The initial comment block lists several warnings about adding required (NOT NULL) columns without default values. This may lead to migration failures on non-empty tables. Ensure you either migrate on an empty table, supply default values, or adopt a two-step migration (first add nullable columns, populate data, then alter to NOT NULL) to avoid runtime issues in production.


Action Required: Resolve Migration Warnings for Non-Empty Tables

The migration script currently adds several NOT NULL columns without providing default values and introduces a unique constraint on [taskId, employeeId] for the VendorTaskAssignment table. If any of these tables already contain data, these changes may lead to migration failures. Please ensure that you either:

  • Migrate on an empty table, or
  • Supply default values for the new NOT NULL columns, or
  • Adopt a two-step migration strategy where the columns are first added as nullable, data is populated, and then the columns are altered to NOT NULL.

Additionally, verify that there are no existing duplicate values in VendorTaskAssignment that could violate the unique constraint.

This branch was successfully deployed

2 active deployments
Preview – app — 42b23917 Deployed Mar 19, 2025 by vercel[bot]
Preview – comp-portal — 42b23917 Deployed Mar 19, 2025 by vercel[bot]
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