Skip to content

Commit cf964f0

Browse files
authored
Merge pull request #1732 from rocket-admin/backend_identity_field_prompt
add identity_column to AIGeneratedTableSettings
2 parents 253bc82 + 69c7e13 commit cf964f0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

backend/src/entities/ai/ai.service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface AIGeneratedTableSettings {
4545
columns_view: string[];
4646
ordering: string;
4747
ordering_field: string;
48+
identity_column: string | null;
4849
widgets: Array<{
4950
field_name: string;
5051
widget_type: string;
@@ -135,6 +136,7 @@ For each table, provide:
135136
5. ordering: Default sort order - either "ASC" or "DESC" (use "DESC" for tables with timestamps to show newest first)
136137
6. ordering_field: Column name to sort by default (prefer created_at, updated_at, or primary key)
137138
7. widgets: For each column, suggest the best widget type from: ${widgetTypes}
139+
8. identity_column: The column that best identifies a row in human-readable format. This is shown when other tables reference this table via foreign keys, so users see meaningful data instead of just IDs. Choose columns like: name, title, email, username, full_name, label, or any descriptive text field. If no good candidate exists, use null.
138140
139141
Available widget types and when to use them:
140142
@@ -242,6 +244,7 @@ Respond ONLY with valid JSON in this exact format (no markdown, no explanations)
242244
"columns_view": ["id", "name", "email", "created_at"],
243245
"ordering": "DESC",
244246
"ordering_field": "created_at",
247+
"identity_column": "name",
245248
"widgets": [
246249
{
247250
"field_name": "id",
@@ -303,7 +306,10 @@ IMPORTANT:
303306

304307
const requiredFieldsWithoutDefault = new Set(
305308
tableInfo?.structure
306-
.filter((col) => !col.allow_null && col.column_default === null && !checkFieldAutoincrement(col.column_default, col.extra))
309+
.filter(
310+
(col) =>
311+
!col.allow_null && col.column_default === null && !checkFieldAutoincrement(col.column_default, col.extra),
312+
)
307313
.map((col) => col.column_name) || [],
308314
);
309315

@@ -325,6 +331,10 @@ IMPORTANT:
325331
settings.ordering_field = validColumnNames.includes(tableSettings.ordering_field)
326332
? tableSettings.ordering_field
327333
: null;
334+
settings.identity_column =
335+
tableSettings.identity_column && validColumnNames.includes(tableSettings.identity_column)
336+
? tableSettings.identity_column
337+
: null;
328338
settings.table_widgets = tableSettings.widgets
329339
.filter((w) => validColumnNames.includes(w.field_name))
330340
.map((widgetData) => {

0 commit comments

Comments
 (0)