feat(types): add database type help

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-07-12 13:28:46 +08:00
1 parent fdb33ef477
commit 4f1997d8eb
30 files changed
+2006 -79

No files matched your search

@@ -27,6 +27,9 @@ import { queryTimeoutSecsForConnection } from "@/lib/sql/queryTimeout";
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
import { type BuildTableStructureChangeSqlOptions, type EditableStructureColumn, type EditableStructureForeignKey, type EditableStructureIndex, type EditableStructureTrigger } from "@/lib/table/tableStructureEditorSql";
import { PRESET_FIELDS_TEMPLATE_ID, createTableColumnTemplateDrafts } from "@/lib/table/tableColumnTemplates";
import { getMysqlDataTypeHelp } from "@/lib/table/mysqlDataTypeHelp";
import { getPostgresDataTypeHelp } from "@/lib/table/postgresDataTypeHelp";
import { getSqliteDataTypeHelp } from "@/lib/table/sqliteDataTypeHelp";
import { getTableMetadataCapabilities, firstStructureMetadataTab, isStructureMetadataTabSupported } from "@/lib/table/tableMetadataCapabilities";
import { canAddTableStructureColumn, getTableStructureCapabilities, hasLocalTableColumnOrderChange, isPhysicalTableColumnOrderChange, supportsLocalTableColumnReorder } from "@/lib/table/tableStructureCapabilities";
import { orderedColumnIndexes, uniqueDataGridColumnOrderKeys } from "@/lib/dataGrid/dataGridColumnOrder";
@@ -43,6 +46,7 @@ import {
createIndexDrafts,
createTriggerDrafts,
dataTypeLengthInputValue,
defaultNewColumnDataType,
generateIndexName,
generateUniqueIndexName,
getColumnEditorControls,
@@ -599,6 +603,7 @@ function onIndexColResize(e: MouseEvent, col: number) {
const connection = computed(() => (props.connectionId ? store.getConfig(props.connectionId) : undefined));
const databaseType = computed(() => tableStructureDatabaseTypeForConnection(connection.value));
const usesMysql8SafeDefaults = computed(() => databaseType.value === "mysql" && connection.value?.db_type === "mysql" && connection.value.driver_profile === "mysql");
const structureCapabilities = computed(() => getTableStructureCapabilities(databaseType.value, connection.value?.db_type));
const tableMetadataCapabilities = computed(() => getTableMetadataCapabilities(databaseType.value));
const structureDialect = computed(() => structureCapabilities.value.dialect);
@@ -1008,6 +1013,32 @@ function mergeDataTypeOptions(primary: readonly string[], fallback: readonly str
return result;
}
function mysqlDataTypeTooltip(option: string): string | undefined {
if (databaseType.value !== "mysql") return undefined;
const product = connection.value?.driver_profile === "mariadb" ? "mariadb" : connection.value?.driver_profile === "mysql" ? "mysql" : undefined;
const help = getMysqlDataTypeHelp(option, { product });
return help ? [help.key, ...(help.warningKeys ?? [])].map((key) => t(`structureEditor.mysqlDataTypeHelp.${key}`)).join("\n\n") : undefined;
}
function postgresDataTypeTooltip(option: string): string | undefined {
if (databaseType.value !== "postgres") return undefined;
const help = getPostgresDataTypeHelp(option);
return help ? t(`structureEditor.postgresDataTypeHelp.${help.key}`) : undefined;
}
function sqliteDataTypeTooltip(option: string): string | undefined {
if (databaseType.value !== "sqlite") return undefined;
const help = getSqliteDataTypeHelp(option);
return help ? t(`structureEditor.sqliteDataTypeHelp.${help.key}`) : undefined;
}
function dataTypeTooltip(option: string): string | undefined {
if (databaseType.value === "mysql") return mysqlDataTypeTooltip(option);
if (databaseType.value === "postgres") return postgresDataTypeTooltip(option);
if (databaseType.value === "sqlite") return sqliteDataTypeTooltip(option);
return undefined;
}
async function loadDynamicDataTypeOptions() {
const requestId = ++dataTypeOptionsRequestId;
const connectionId = props.connectionId;
@@ -1278,7 +1309,7 @@ async function refreshStructureAfterSave(scope: StructureRefreshScope) {
async function addColumn() {
if (!canAddColumn.value) return;
activeTab.value = "columns";
const dataType = databaseType.value === "manticoresearch" ? combineDataTypeForDatabase(databaseType.value, dataTypeOptions.value[0] ?? "text", getDefaultLengthForType(databaseType.value, dataTypeOptions.value[0] ?? "text")) : "varchar(255)";
const dataType = defaultNewColumnDataType(databaseType.value, dataTypeOptions.value);
const column: EditableStructureColumn = {
id: `new:${uuid()}`,
name: "",
@@ -1517,7 +1548,7 @@ function updateColumnDataType(column: EditableStructureColumn, baseType: string)
if (!column.enumValues?.length) column.enumValues = [""];
column.dataType = mysqlEnumDataType(column.enumValues);
} else {
column.dataType = combineDataTypeForDatabase(databaseType.value, baseType, getDefaultLengthForType(databaseType.value, baseType));
column.dataType = combineDataTypeForDatabase(databaseType.value, baseType, getDefaultLengthForType(databaseType.value, baseType, { omitMysqlDeprecatedDefaults: usesMysql8SafeDefaults.value }));
}
syncSqlServerIdentityForDataType(column);
syncDamengIdentityForDataType(column);
@@ -2567,6 +2598,7 @@ watch([activeTab, ddlLoading], ([tab, loading]) => {
:empty-text="t('structureEditor.noMatchingType')"
:loading-text="t('common.loading')"
:allow-custom="true"
:option-tooltip="dataTypeTooltip"
:trigger-class="[structureMonoControlClass, 'w-full']"
@update:model-value="(v: string) => updateColumnDataType(column, v)"
/>