Adds TestGroup property to TestItem for categorization and filtering#1162
Adds TestGroup property to TestItem for categorization and filtering#1162jSylvestre wants to merge 5 commits into
Conversation
This introduces a new TestGroup field in the TestItem domain object and database column. It allows test items to be associated with predefined groups (e.g., AnLab, SIF) and facilitates filtering available tests for clients. issue #1161
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds a new TestGroup string property and a NotMapped TestGroups array with pipe-delimited mapping to the TestItem domain model, introduces a TestGroups constants class, persists TestGroup as NVARCHAR(64) NOT NULL in dbo.TestItems, applies DDL formatting/constraint updates across several tables and a view, and updates tests to expect the new fields. ChangesTestItem Group Addition
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
Anlab.Sql/dbo/Tables/TestItems.sql (1)
13-13: ⚡ Quick winConstrain
TestGroupvalues to the supported set.Filtering logic depends on known groups, but the column currently accepts any string. Add a
CHECKconstraint to prevent drift and invalid data.Suggested constraint
- [TestGroup] NVARCHAR(64) NOT NULL, + [TestGroup] NVARCHAR(64) NOT NULL, + CONSTRAINT [CK_TestItems_TestGroup] CHECK ([TestGroup] IN ('AnLab', 'SIF', 'ICPMS', 'CDFA')),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Anlab.Sql/dbo/Tables/TestItems.sql` at line 13, The TestItems table's [TestGroup] NVARCHAR(64) currently accepts any string; add a CHECK constraint (e.g., name it CK_TestItems_TestGroup) on the [TestGroup] column to only allow the supported set of group values used by filtering logic (replace the placeholder list with the actual allowed values), and deploy the constraint alongside the table definition so invalid values are rejected at insert/update time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Anlab.Core/Domain/TestItem.cs`:
- Around line 34-35: The TestItem domain model's TestGroup property lacks the
[Required] attribute while the database marks that column as non-nullable, so
add the [Required] attribute to the TestGroup property in the TestItem class
(public string TestGroup { get; set; } = string.Empty;) to enforce validation
earlier; also ensure the System.ComponentModel.DataAnnotations namespace is
imported if not already.
- Around line 37-41: The TestGroups computed property is missing the [NotMapped]
attribute and EF Core will try to map it; add the [NotMapped] attribute above
the TestGroups property (the string[] TestGroups getter/setter that wraps
TestGroup and uses Split/Join) to match the Categories pattern so EF Core
ignores this computed array property during model building.
In `@Anlab.Sql/dbo/Tables/TestItems.sql`:
- Line 13: The new NOT NULL constraint on the TestItems.TestGroup column will
fail on populated DBs; add a safe rollout migration that (1) alters TestItems to
add TestGroup as NULL or with a temporary DEFAULT, (2) backfills existing rows
with a valid value (e.g. empty string or a sentinel) via an UPDATE, and then (3)
alter the column to NOT NULL and remove any temporary default; reference the
TestItems table and TestGroup column when implementing the migration and ensure
the backfill value matches application expectations.
---
Nitpick comments:
In `@Anlab.Sql/dbo/Tables/TestItems.sql`:
- Line 13: The TestItems table's [TestGroup] NVARCHAR(64) currently accepts any
string; add a CHECK constraint (e.g., name it CK_TestItems_TestGroup) on the
[TestGroup] column to only allow the supported set of group values used by
filtering logic (replace the placeholder list with the actual allowed values),
and deploy the constraint alongside the table definition so invalid values are
rejected at insert/update time.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 424bbda7-ac19-4eb9-8ba1-085ff4664fae
📒 Files selected for processing (2)
Anlab.Core/Domain/TestItem.csAnlab.Sql/dbo/Tables/TestItems.sql
| [StringLength(64)] | ||
| public string TestGroup { get; set; } = string.Empty; |
There was a problem hiding this comment.
Align domain validation with DB requiredness for TestGroup.
TestGroup is required in SQL, but the model doesn’t declare [Required]. Add it to fail early in validation instead of at persistence time.
Proposed fix
+ [Required]
[StringLength(64)]
public string TestGroup { get; set; } = string.Empty;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@Anlab.Core/Domain/TestItem.cs` around lines 34 - 35, The TestItem domain
model's TestGroup property lacks the [Required] attribute while the database
marks that column as non-nullable, so add the [Required] attribute to the
TestGroup property in the TestItem class (public string TestGroup { get; set; }
= string.Empty;) to enforce validation earlier; also ensure the
System.ComponentModel.DataAnnotations namespace is imported if not already.
There was a problem hiding this comment.
It defaults to an empty string, so isn't needed
There was a problem hiding this comment.
@jSylvestre, that's a fair point — and actually a stronger reason than just nullability. Since [Required] rejects empty strings by default in .NET validation, adding it would break the intended behavior where an empty TestGroup is a valid state (matching the DB's DEFAULT('')). Acknowledging the flag was mistaken here.
✏️ Learnings added
Learnt from: jSylvestre
Repo: ucdavis/Anlab PR: 1162
File: Anlab.Core/Domain/TestItem.cs:34-35
Timestamp: 2026-05-07T17:20:34.929Z
Learning: In `Anlab.Core/Domain/TestItem.cs`, the `TestGroup` property on `TestItem` intentionally defaults to `string.Empty` and an empty string is a valid/allowed value (the SQL column is `NVARCHAR(64) NOT NULL DEFAULT('')`). Do not suggest adding `[Required]` to this property, as `[Required]` rejects empty strings by default in .NET and would break the intended behavior.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
This column facilitates categorization and filtering of test items, allowing them to be grouped (e.g., AnLab, SIF). This supports client-facing filtering of available tests. issue #1161
The `TestGroups` property is a derived property from `TestGroup` and should not be persisted to the database. Marking it with `[NotMapped]` prevents Entity Framework Core from attempting to create a corresponding database column for this computed property. Tests are updated to validate this attribute and the overall configuration for both `TestGroup` and `TestGroups`.
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
Anlab.Sql/dbo/Tables/MailMessages.sql (1)
6-15:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
MailMessages.OrderIdlacks foreign key constraint.
OrderId(Line 6) is a nullable INT column with a dedicated NONCLUSTERED index (Lines 26-27), yet has no foreign key constraint todbo.Orders(Id). This permits dangling references and violates referential integrity.Proposed fix
CONSTRAINT [PK_MailMessages] PRIMARY KEY CLUSTERED ([Id] ASC), - CONSTRAINT [FK_MailMessages_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]) + CONSTRAINT [FK_MailMessages_AspNetUsers_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[AspNetUsers] ([Id]), + CONSTRAINT [FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([Id])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Anlab.Sql/dbo/Tables/MailMessages.sql` around lines 6 - 15, MailMessages.OrderId is missing a foreign-key constraint; add a FK from MailMessages.OrderId to dbo.Orders(Id) by adding a constraint such as CONSTRAINT [FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([Id]) (optionally with an ON DELETE/UPDATE action you want) to the CREATE TABLE for MailMessages (near CONSTRAINT [PK_MailMessages] and the existing FK to AspNetUsers) or implement as an ALTER TABLE ... ADD CONSTRAINT if changing the existing table.Anlab.Sql/dbo/Tables/History.sql (1)
3-12:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRestore the
History.OrderIdforeign key constraint.Line 3 defines
OrderId INT NOT NULL, but line 11 only defines the primary key constraint; there is no foreign key todbo.Orders(Id). This allows orphaned history records and weakens data integrity.Proposed fix
CREATE TABLE [dbo].[History] ( [Id] INT IDENTITY (1, 1) NOT NULL, [OrderId] INT NOT NULL, @@ - CONSTRAINT [PK_History] PRIMARY KEY CLUSTERED ([Id] ASC) + CONSTRAINT [PK_History] PRIMARY KEY CLUSTERED ([Id] ASC), + CONSTRAINT [FK_History_Orders] FOREIGN KEY ([OrderId]) REFERENCES [dbo].[Orders] ([Id]) );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Anlab.Sql/dbo/Tables/History.sql` around lines 3 - 12, The table definition for History is missing a foreign key from History.OrderId to dbo.Orders(Id), allowing orphaned rows; add a FOREIGN KEY constraint (e.g., CONSTRAINT FK_History_OrderId FOREIGN KEY ([OrderId]) REFERENCES dbo.Orders([Id]) ) to the History table definition (alongside or after CONSTRAINT [PK_History]) so History.OrderId enforces referential integrity and choose the appropriate ON DELETE/ON UPDATE behavior for your domain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Anlab.Sql/dbo/Tables/Orders.sql`:
- Line 21: The Orders table's IsDeleted column is declared as BIT NOT NULL
without a default which breaks inserts that don't supply it; update the Orders
table schema so IsDeleted has a DB-level default of 0 (e.g., add a DEFAULT 0
constraint on the IsDeleted column) to preserve backward-compatible inserts and
consider adding a migration/ALTER TABLE to apply the default for existing
databases; keep the column name IsDeleted and the table name Orders when
locating the change.
- Line 4: The schema sync removed foreign key constraints and a default value
causing data-integrity and INSERT issues; restore the FK constraints linking
Orders.CreatorId to the Users (or appropriate principal) table and
Orders.ApprovedPaymentTransaction_Id to the PaymentTransactions (or appropriate
principal) table by adding back the corresponding ALTER TABLE ... ADD CONSTRAINT
... FOREIGN KEY declarations (use the original constraint names if known), and
restore the DEFAULT ((0)) for the Orders.IsDeleted column so inserts that omit
IsDeleted work; update the Orders table DDL around the columns
ApprovedPaymentTransaction_Id, CreatorId and IsDeleted and ensure the related
indexes on those columns are present (recreate any dropped indexes referenced in
the diff) so the soft-delete and FK-dependent views and logic continue to work.
---
Outside diff comments:
In `@Anlab.Sql/dbo/Tables/History.sql`:
- Around line 3-12: The table definition for History is missing a foreign key
from History.OrderId to dbo.Orders(Id), allowing orphaned rows; add a FOREIGN
KEY constraint (e.g., CONSTRAINT FK_History_OrderId FOREIGN KEY ([OrderId])
REFERENCES dbo.Orders([Id]) ) to the History table definition (alongside or
after CONSTRAINT [PK_History]) so History.OrderId enforces referential integrity
and choose the appropriate ON DELETE/ON UPDATE behavior for your domain.
In `@Anlab.Sql/dbo/Tables/MailMessages.sql`:
- Around line 6-15: MailMessages.OrderId is missing a foreign-key constraint;
add a FK from MailMessages.OrderId to dbo.Orders(Id) by adding a constraint such
as CONSTRAINT [FK_MailMessages_Orders_OrderId] FOREIGN KEY ([OrderId])
REFERENCES [dbo].[Orders] ([Id]) (optionally with an ON DELETE/UPDATE action you
want) to the CREATE TABLE for MailMessages (near CONSTRAINT [PK_MailMessages]
and the existing FK to AspNetUsers) or implement as an ALTER TABLE ... ADD
CONSTRAINT if changing the existing table.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 89808e46-d83f-44c8-9762-83004372b508
📒 Files selected for processing (8)
Anlab.Core/Domain/TestItem.csAnlab.Sql/dbo/Tables/History.sqlAnlab.Sql/dbo/Tables/MailMessages.sqlAnlab.Sql/dbo/Tables/Orders.sqlAnlab.Sql/dbo/Tables/TestItems.sqlAnlab.Sql/dbo/Views/HistoricalSalesView.sqlTest/TestsDatabase/TestItemTests.csTest/TestsModel/TestItemModelTest.cs
✅ Files skipped from review due to trivial changes (2)
- Test/TestsDatabase/TestItemTests.cs
- Anlab.Sql/dbo/Views/HistoricalSalesView.sql
🚧 Files skipped from review as they are similar to previous changes (2)
- Anlab.Sql/dbo/Tables/TestItems.sql
- Anlab.Core/Domain/TestItem.cs
Integrates the TestGroup property into the TestItem create, edit, details, and index views. This allows for multi-selection of test groups when creating or editing a test item, and provides filtering capabilities in the list view, similar to existing category functionality. This work completes the UI aspect of issue #1161.
This introduces a new TestGroup field in the TestItem domain object and database column. It allows test items to be associated with predefined groups (e.g., AnLab, SIF) and facilitates filtering available tests for clients. issue #1161
Summary by CodeRabbit