From 5cc3dc5ab39aee8d51a53b77150e151ff800ba31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sedat=20=C3=96ZT=C3=9CRK?=
<76204082+iamsedatozturk@users.noreply.github.com>
Date: Mon, 16 Mar 2026 12:52:15 +0300
Subject: [PATCH] SqlTableDesigner fix
---
.../views/developerKit/SqlObjectExplorer.tsx | 2 +-
.../developerKit/SqlTableDesignerDialog.tsx | 52 ++++++++++++-------
2 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/ui/src/views/developerKit/SqlObjectExplorer.tsx b/ui/src/views/developerKit/SqlObjectExplorer.tsx
index a8a0a75..b2eadfd 100644
--- a/ui/src/views/developerKit/SqlObjectExplorer.tsx
+++ b/ui/src/views/developerKit/SqlObjectExplorer.tsx
@@ -282,7 +282,7 @@ const SqlObjectExplorer = ({
{loading &&
{translate('::App.Platform.Loading')}
}
{!loading && treeData.length === 0 && {translate('::App.Platform.NoDataSourceSelected')}
}
{!loading && filteredTree.length > 0 && {filteredTree.map((n) => renderNode(n))}
}
- {!loading && treeData.length > 0 && filteredTree.length === 0 && {translate('::App.Platform.NoResultsFound')}
}
+ {!loading && treeData.length > 0 && filteredTree.length === 0 && {translate('::App.Platform.NoResults')}
}
{/* Context menu */}
diff --git a/ui/src/views/developerKit/SqlTableDesignerDialog.tsx b/ui/src/views/developerKit/SqlTableDesignerDialog.tsx
index db6d877..a6e201d 100644
--- a/ui/src/views/developerKit/SqlTableDesignerDialog.tsx
+++ b/ui/src/views/developerKit/SqlTableDesignerDialog.tsx
@@ -257,14 +257,7 @@ function generateCreateTableSql(
const userCols = columns.filter((c) => c.columnName.trim())
const allBodyCols = userCols
-
- const hasIdCol = userCols.some((c) => c.columnName.trim().toLowerCase() === 'id')
- const bodyLines = hasIdCol
- ? [
- ...allBodyCols.map((c) => colToSqlLine(c, true)),
- ` CONSTRAINT [PK_${tableName}] PRIMARY KEY NONCLUSTERED ([Id])`,
- ]
- : allBodyCols.map((c, i) => colToSqlLine(c, i < allBodyCols.length - 1))
+ const bodyLines = allBodyCols.map((c, i) => colToSqlLine(c, i < allBodyCols.length - 1))
// FK constraint lines
const fkLines: string[] = []
@@ -1000,22 +993,25 @@ const SqlTableDesignerDialog = ({
const nonEmpty = prev.filter((c) => c.columnName.trim() !== '')
return [...nonEmpty, ...toAdd.map((c) => ({ ...c })), createEmptyColumn()]
})
- // Auto-add PK for Id column if not already defined
- const hasPk = indexes.some((ix) => ix.indexType === 'PrimaryKey')
- if (!hasPk) {
- const tblName = settings.tableName || initialTableData?.tableName || 'Table'
- setIndexes((prev) => [
+
+ // FullAudited ile Id eklendiğinde PK tanımı Index/Key listesine otomatik düşsün.
+ setIndexes((prev) => {
+ const hasPk = prev.some((ix) => ix.indexType === 'PrimaryKey')
+ if (hasPk) return prev
+
+ const tableName = settings.tableName || initialTableData?.tableName || 'Table'
+ return [
...prev,
{
id: `auto-pk-${crypto.randomUUID()}`,
- indexName: `PK_${tblName}`,
+ indexName: `PK_${tableName}`,
indexType: 'PrimaryKey',
isClustered: false,
columns: [{ columnName: 'Id', order: 'ASC' }],
- description: 'Primary key',
+ description: 'Primary key (auto)',
},
- ])
- }
+ ]
+ })
}
const addMultiTenantColumns = () => {
@@ -1051,8 +1047,11 @@ const SqlTableDesignerDialog = ({
// ── Settings helpers ───────────────────────────────────────────────────────
+ const hasTenantIdColumn = (cols: ColumnDefinition[]) =>
+ cols.some((c) => c.columnName.trim().toLowerCase() === 'tenantid')
+
const buildTableName = (prefix: string, entity: string) =>
- prefix && entity ? `${prefix}_D_${entity}` : ''
+ prefix && entity ? `${prefix}_${hasTenantIdColumn(columns) ? 'T' : 'D'}_${entity}` : ''
const syncAutoPkName = (newTableName: string) => {
if (!newTableName) return
@@ -1093,6 +1092,23 @@ const SqlTableDesignerDialog = ({
syncAutoPkName(newTableName)
}
+ useEffect(() => {
+ if (isEditMode) return
+ if (!settings.menuPrefix || !settings.entityName) return
+
+ const recalculatedTableName = buildTableName(settings.menuPrefix, settings.entityName)
+ if (!recalculatedTableName || recalculatedTableName === settings.tableName) return
+
+ setSettings((s) => ({ ...s, tableName: recalculatedTableName }))
+ syncAutoPkName(recalculatedTableName)
+ }, [
+ isEditMode,
+ columns,
+ settings.menuPrefix,
+ settings.entityName,
+ settings.tableName,
+ ])
+
// ── FK Relationship handlers ───────────────────────────────────────────────
const loadTargetColumns = (tableName: string) => {