SqlTableDesigner fix
This commit is contained in:
parent
66a3261e2c
commit
5cc3dc5ab3
2 changed files with 35 additions and 19 deletions
|
|
@ -282,7 +282,7 @@ const SqlObjectExplorer = ({
|
|||
{loading && <div className="text-center py-8 text-gray-500 text-sm">{translate('::App.Platform.Loading')}</div>}
|
||||
{!loading && treeData.length === 0 && <div className="text-center py-8 text-gray-500 text-sm">{translate('::App.Platform.NoDataSourceSelected')}</div>}
|
||||
{!loading && filteredTree.length > 0 && <div className="p-1">{filteredTree.map((n) => renderNode(n))}</div>}
|
||||
{!loading && treeData.length > 0 && filteredTree.length === 0 && <div className="text-center py-8 text-gray-500 text-sm">{translate('::App.Platform.NoResultsFound')}</div>}
|
||||
{!loading && treeData.length > 0 && filteredTree.length === 0 && <div className="text-center py-8 text-gray-500 text-sm">{translate('::App.Platform.NoResults')}</div>}
|
||||
</div>
|
||||
|
||||
{/* Context menu */}
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue