Skip to content

Enhance table settings generation by filtering required fields and updating columns view logic#1714

Merged
Artuomka merged 1 commit intomainfrom
backend_improve_ai_settings-_prompt
Apr 9, 2026
Merged

Enhance table settings generation by filtering required fields and updating columns view logic#1714
Artuomka merged 1 commit intomainfrom
backend_improve_ai_settings-_prompt

Conversation

@Artuomka
Copy link
Copy Markdown
Collaborator

@Artuomka Artuomka commented Apr 9, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved AI-generated table settings to correctly handle required fields. Required fields are now automatically included in column views and excluded from read-only field lists to prevent invalid configurations.

Copilot AI review requested due to automatic review settings April 9, 2026 15:28
@Artuomka Artuomka enabled auto-merge April 9, 2026 15:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 690a6404-f4ff-4615-8ce7-16b0db265567

📥 Commits

Reviewing files that changed from the base of the PR and between 528b32d and 902625e.

📒 Files selected for processing (1)
  • backend/src/entities/ai/ai.service.ts

📝 Walkthrough

Walkthrough

The AI service's table settings builder now computes required fields without defaults from the schema and enforces their inclusion in column views while preventing them from being marked readonly.

Changes

Cohort / File(s) Summary
Table Settings Field Validation
backend/src/entities/ai/ai.service.ts
Introduces logic to identify required fields (non-nullable, no default, non-auto-increment), filters them out of readonly_fields, and ensures columns_view includes all required fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through fields of code,
Required fields now show the road,
No longer lost, no longer shy,
They'll appear—we can't deny! 🌟

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: enhancing table settings generation by filtering required fields and updating columns view logic, which aligns with the actual implementation changes in ai.service.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Security Check ✅ Passed PR implements robust OWASP security controls including whitelist validation against database schema, strict type mapping, safe JSON handling, and enforcement of database constraints.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backend_improve_ai_settings-_prompt

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates AI-generated TableSettingsEntity creation to better handle required DB columns by preventing them from being marked read-only and ensuring they are visible in the configured columns view.

Changes:

  • Derive a set of non-nullable columns with no default (excluding autoincrement) from table structure metadata.
  • Remove those required fields from readonly_fields.
  • Ensure those required fields are present in columns_view.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


const requiredFieldsWithoutDefault = new Set(
tableInfo?.structure
.filter((col) => !col.allow_null && col.column_default === null && !checkFieldAutoincrement(col.column_default, col.extra))
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

requiredFieldsWithoutDefault calls checkFieldAutoincrement(col.column_default, col.extra) in a branch where col.column_default is guaranteed to be null. The helper is typed as checkFieldAutoincrement(defaultValue: string, ...), so this is type-inconsistent and can break compilation under strictNullChecks (and makes the intent unclear). Consider updating the helper signature to accept string | null (and extra?: string | null) or coalescing the argument at the call site.

Suggested change
.filter((col) => !col.allow_null && col.column_default === null && !checkFieldAutoincrement(col.column_default, col.extra))
.filter(
(col) =>
!col.allow_null &&
col.column_default === null &&
!checkFieldAutoincrement(col.column_default ?? '', col.extra),
)

Copilot uses AI. Check for mistakes.
Comment on lines +318 to +320
for (const requiredField of requiredFieldsWithoutDefault) {
if (!filteredColumnsView.includes(requiredField)) {
filteredColumnsView.push(requiredField);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The loop that appends requiredFieldsWithoutDefault to filteredColumnsView does an includes check for each required field, resulting in O(n*m) behavior for wide tables. Converting filteredColumnsView to a Set for membership checks (and back to an array at the end) would make this linear and simpler to reason about.

Suggested change
for (const requiredField of requiredFieldsWithoutDefault) {
if (!filteredColumnsView.includes(requiredField)) {
filteredColumnsView.push(requiredField);
const filteredColumnsViewSet = new Set(filteredColumnsView);
for (const requiredField of requiredFieldsWithoutDefault) {
if (!filteredColumnsViewSet.has(requiredField)) {
filteredColumnsView.push(requiredField);
filteredColumnsViewSet.add(requiredField);

Copilot uses AI. Check for mistakes.
@Artuomka Artuomka merged commit 18725bd into main Apr 9, 2026
23 checks passed
@Artuomka Artuomka deleted the backend_improve_ai_settings-_prompt branch April 9, 2026 15:39
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