feat(mysql): add batch auto-increment start setting

This commit is contained in:
leekeep authored and GitHub committed 2026-09-08 22:35:06 +08:00
1 parent dcbe9701ef
commit b7c9312c9f
11 files changed
+166 -2

No files matched your search

@@ -141,11 +141,14 @@ import {
buildCopyTableDataSql,
buildEmptyTableSql,
buildTruncateTableSql,
buildMysqlAutoIncrementSql,
supportsDropTableCascade,
supportsTruncateTableCascade,
supportsNativeMysqlAutoIncrement,
supportsSchemaComment,
type DropTableChildObjectSqlOptions,
type DropObjectSqlOptions,
type MysqlAutoIncrementSqlOptions,
type TableChildObjectType,
} from "@/lib/database/dbAdminSql";
import { buildRenameObjectSql, buildRenameDatabaseSql, buildRenameDatabasePreflightSql, databaseRenameMaintenanceDatabase, supportsDatabaseRename, supportsObjectRename, type RenameableObjectType } from "@/lib/table/objectRenameSql";
@@ -227,6 +230,9 @@ import {
showTruncateTableConfirm,
showVacuumTableConfirm,
showMysqlAutoIncrementConfirm,
showBatchMysqlAutoIncrementConfirm,
batchMysqlAutoIncrementTargets,
batchMysqlAutoIncrementPreviewSql,
showRenameObjectDialog,
renameObjectName,
renameObjectError,
@@ -2813,6 +2819,87 @@ function requestBatchEmpty() {
});
}
function selectedBatchMysqlAutoIncrementTargets(): TreeNode[] {
const targets = selectedBatchTableTargets();
return targets.filter((node) => {
const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;
return supportsNativeMysqlAutoIncrement(config);
});
}
function batchMysqlAutoIncrementMenuLabel(): string {
return t("contextMenu.batchMysqlAutoIncrement", { count: selectedBatchMysqlAutoIncrementTargets().length });
}
function batchMysqlAutoIncrementSqlOptionsForNode(node: TreeNode): MysqlAutoIncrementSqlOptions {
const config = node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined;
return {
databaseType: config?.db_type ?? databaseTypeForNode(node) ?? "mysql",
driverProfile: config?.driver_profile,
schema: node.database || node.schema,
tableName: node.label,
value: mysqlAutoIncrementValue.value,
};
}
async function refreshBatchMysqlAutoIncrementPreviewSql() {
const targets = batchMysqlAutoIncrementTargets.value;
const statements: string[] = [];
for (const target of targets) {
const sql = await buildMysqlAutoIncrementSql(batchMysqlAutoIncrementSqlOptionsForNode(target)).catch(() => "");
if (sql) statements.push(sql);
}
batchMysqlAutoIncrementPreviewSql.value = statements.join("\n");
}
function requestBatchMysqlAutoIncrement() {
const targets = selectedBatchMysqlAutoIncrementTargets();
if (!targets.length) return;
batchMysqlAutoIncrementTargets.value = targets.slice();
mysqlAutoIncrementValue.value = "1";
batchMysqlAutoIncrementPreviewSql.value = "";
void refreshBatchMysqlAutoIncrementPreviewSql();
showBatchMysqlAutoIncrementConfirm.value = true;
}
async function confirmBatchMysqlAutoIncrement() {
const targets = batchMysqlAutoIncrementTargets.value.slice();
if (!targets.length) return;
const succeeded: TreeNode[] = [];
let failedCount = 0;
let firstError: unknown;
for (const target of targets) {
if (!target.connectionId || !target.database) {
failedCount++;
continue;
}
try {
const config = connectionStore.getConfig(target.connectionId);
if (!supportsNativeMysqlAutoIncrement(config)) throw new Error("Setting AUTO_INCREMENT is supported only for native MySQL connections.");
await connectionStore.ensureConnected(target.connectionId);
const sqlOptions = batchMysqlAutoIncrementSqlOptionsForNode(target);
const sql = await buildMysqlAutoIncrementSql(sqlOptions);
await executeTreeNodeSqlWithProductionGuard(target, sql, { database: target.database, schema: target.schema });
succeeded.push(target);
} catch (error) {
failedCount++;
firstError ??= error;
}
}
if (succeeded.length > 0) {
await refreshMutatedTableDataTabsForNodes(succeeded);
}
if (failedCount > 0 && firstError) {
toast(t("contextMenu.batchMysqlAutoIncrementPartialFail", { success: succeeded.length, failed: failedCount }), 5000);
} else if (succeeded.length > 0) {
toast(t("contextMenu.batchMysqlAutoIncrementSuccess", { count: succeeded.length, value: mysqlAutoIncrementValue.value }), 3000);
} else if (firstError) {
toast(t("contextMenu.tableOperationFailed", { message: (firstError as any)?.message || String(firstError) }), 5000);
}
batchMysqlAutoIncrementTargets.value = [];
showBatchMysqlAutoIncrementConfirm.value = false;
}
function requestDropSelectedNodes(): boolean {
const selected = selectedTreeNodesInVisibleOrder();
if (selected.length > 1 && selected.some((node) => node.id === activeNode.value.id)) {
@@ -4679,6 +4766,31 @@ routeDangerDialog(showMysqlAutoIncrementConfirm, () =>
}),
);
routeDangerDialog(showBatchMysqlAutoIncrementConfirm, () =>
dangerRequest({
title: t("contextMenu.batchMysqlAutoIncrementTitle", { count: batchMysqlAutoIncrementTargets.value.length }),
message: t("contextMenu.batchMysqlAutoIncrementMessage", { count: batchMysqlAutoIncrementTargets.value.length }),
detailsText: t("contextMenu.mysqlAutoIncrementNonemptyHint"),
get sql() {
return batchMysqlAutoIncrementPreviewSql.value;
},
get confirmLabel() {
return t("contextMenu.batchMysqlAutoIncrement", { count: batchMysqlAutoIncrementTargets.value.length });
},
textInput: {
value: mysqlAutoIncrementValue.value,
label: t("contextMenu.mysqlAutoIncrementValue"),
placeholder: "1",
inputMode: "numeric",
async onInput(value) {
mysqlAutoIncrementValue.value = value;
await refreshBatchMysqlAutoIncrementPreviewSql();
},
},
confirm: confirmBatchMysqlAutoIncrement,
}),
);
routeDangerDialog(showDropObjectConfirm, () =>
dangerRequest({
title: dropObjectConfirmTitle(),
@@ -5887,8 +5999,8 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
if (supportsVacuum.value) {
destructiveActions.push({ label: t("contextMenu.vacuumTable"), action: vacuumTable, icon: Activity, variant: "destructive" as const });
}
if (supportsMysqlAutoIncrement.value) {
items.push({ label: t("contextMenu.mysqlAutoIncrement"), action: mysqlAutoIncrement, icon: Gauge });
if (supportsMysqlAutoIncrement.value || batchAutoIncrementCount > 1) {
items.push({ label: autoIncrementMenuLabel(t("contextMenu.mysqlAutoIncrement")), action: autoIncrementMenuAction(mysqlAutoIncrement), icon: Gauge });
}
if (supportsTruncate.value) {
destructiveActions.push({
@@ -6199,12 +6311,15 @@ function treeItemMenuItems(): ContextMenuItem[] {
const batchDropCount = selectedBatchDropTargets().length;
const batchEmptyCount = selectedBatchEmptyTargets().length;
const batchTruncateCount = selectedBatchTruncateTargets().length;
const batchAutoIncrementCount = selectedBatchMysqlAutoIncrementTargets().length;
const deleteMenuLabel = (singleLabel: string) => (batchDropCount > 1 ? batchDropMenuLabel() : singleLabel);
const deleteMenuAction = (singleAction: () => void) => (batchDropCount > 1 ? requestBatchDrop : singleAction);
const truncateMenuLabel = (singleLabel: string) => (batchTruncateCount > 1 ? batchTruncateMenuLabel() : singleLabel);
const truncateMenuAction = (singleAction: () => void) => (batchTruncateCount > 1 ? requestBatchTruncate : singleAction);
const emptyMenuLabel = (singleLabel: string) => (batchEmptyCount > 1 ? batchEmptyMenuLabel() : singleLabel);
const emptyMenuAction = (singleAction: () => void) => (batchEmptyCount > 1 ? requestBatchEmpty : singleAction);
const autoIncrementMenuLabel = (singleLabel: string) => (batchAutoIncrementCount > 1 ? batchMysqlAutoIncrementMenuLabel() : singleLabel);
const autoIncrementMenuAction = (singleAction: () => void) => (batchAutoIncrementCount > 1 ? requestBatchMysqlAutoIncrement : singleAction);
// 1. Pin toggle
if (canPin.value) {
@@ -39,6 +39,9 @@ export const showEmptyTableConfirm = ref(false);
export const showTruncateTableConfirm = ref(false);
export const showVacuumTableConfirm = ref(false);
export const showMysqlAutoIncrementConfirm = ref(false);
export const showBatchMysqlAutoIncrementConfirm = ref(false);
export const batchMysqlAutoIncrementTargets = ref<TreeNode[]>([]);
export const batchMysqlAutoIncrementPreviewSql = ref("");
export const showRenameObjectDialog = ref(false);
export const renameObjectName = ref("");
export const renameObjectError = ref("");
@@ -201,6 +204,7 @@ const openFlags = [
showTruncateTableConfirm,
showVacuumTableConfirm,
showMysqlAutoIncrementConfirm,
showBatchMysqlAutoIncrementConfirm,
showDropObjectConfirm,
showRenameObjectDialog,
showDuplicateDialog,
+5
View File
@@ -3305,6 +3305,7 @@ export default {
batchDrop: "Drop selected ({count})",
batchEmpty: "Empty selected ({count})",
batchTruncate: "Truncate selected ({count})",
batchMysqlAutoIncrement: "Set AUTO_INCREMENT ({count})",
batchDropIndexes: "Drop Indexes ({count})",
executeProcedure: "Execute Procedure",
compileObject: "Compile",
@@ -3351,6 +3352,10 @@ export default {
confirmBatchEmptyMessage: "Are you sure you want to delete all data from {count} selected tables?",
confirmBatchTruncateTitle: "Truncate Selected Tables",
confirmBatchTruncateMessage: "Are you sure you want to truncate {count} selected tables? This will remove all rows.",
batchMysqlAutoIncrementTitle: "Set MySQL AUTO_INCREMENT ({count} Tables)",
batchMysqlAutoIncrementMessage: "Set the next AUTO_INCREMENT value requested for {count} selected tables?",
batchMysqlAutoIncrementSuccess: "Requested AUTO_INCREMENT {value} for {count} tables",
batchMysqlAutoIncrementPartialFail: "Set AUTO_INCREMENT for {success} tables, {failed} failed",
confirmDropProcedureTitle: "Drop Procedure",
confirmDropProcedureMessage: 'Are you sure you want to drop procedure "{name}"?',
confirmDropFunctionTitle: "Drop Function",
+5
View File
@@ -3127,6 +3127,7 @@ export default withEnglishFallback({
batchDrop: "Eliminar seleccionados ({count})",
batchEmpty: "Vaciar seleccionadas ({count})",
batchTruncate: "Truncar seleccionadas ({count})",
batchMysqlAutoIncrement: "Establecer AUTO_INCREMENT ({count})",
executeProcedure: "Ejecutar procedimiento",
confirmExecuteProcedureTitle: "Ejecutar procedimiento",
confirmExecuteProcedureMessage: '¿Ejecutar el procedimiento "{name}"? Puedes completar o ajustar los valores de los parámetros primero.',
@@ -3199,6 +3200,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "¿Seguro que deseas eliminar todos los datos de {count} tablas seleccionadas?",
confirmBatchTruncateTitle: "Truncar tablas seleccionadas",
confirmBatchTruncateMessage: "¿Seguro que deseas truncar {count} tablas seleccionadas? Esto eliminará todas las filas.",
batchMysqlAutoIncrementTitle: "Establecer AUTO_INCREMENT de MySQL ({count} tablas)",
batchMysqlAutoIncrementMessage: "¿Establecer el siguiente valor de AUTO_INCREMENT solicitado para {count} tablas seleccionadas?",
batchMysqlAutoIncrementSuccess: "AUTO_INCREMENT {value} solicitado para {count} tablas",
batchMysqlAutoIncrementPartialFail: "AUTO_INCREMENT establecido para {success} tablas, {failed} fallaron",
confirmDropProcedureTitle: "Eliminar procedimiento",
confirmDropProcedureMessage: '¿Seguro que deseas eliminar el procedimiento "{name}"?',
confirmDropFunctionTitle: "Eliminar función",
+5
View File
@@ -3155,6 +3155,7 @@ export default withEnglishFallback({
batchDrop: "Elimina selezionati ({count})",
batchEmpty: "Svuota selezionate ({count})",
batchTruncate: "Tronca selezionate ({count})",
batchMysqlAutoIncrement: "Imposta AUTO_INCREMENT ({count})",
batchDropIndexes: "Elimina indici ({count})",
executeProcedure: "Esegui Procedura",
confirmExecuteProcedureTitle: "Esegui Procedura",
@@ -3197,6 +3198,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "Sei sicuro di voler eliminare tutti i dati da {count} tabelle selezionate?",
confirmBatchTruncateTitle: "Tronca Tabelle Selezionate",
confirmBatchTruncateMessage: "Sei sicuro di voler troncare {count} tabelle selezionate? Questa operazione rimuoverà tutte le righe.",
batchMysqlAutoIncrementTitle: "Imposta AUTO_INCREMENT MySQL ({count} tabelle)",
batchMysqlAutoIncrementMessage: "Impostare il valore AUTO_INCREMENT successivo richiesto per {count} tabelle selezionate?",
batchMysqlAutoIncrementSuccess: "AUTO_INCREMENT {value} richiesto per {count} tabelle",
batchMysqlAutoIncrementPartialFail: "AUTO_INCREMENT impostato per {success} tabelle, {failed} fallite",
confirmDropProcedureTitle: "Elimina Procedura",
confirmDropProcedureMessage: 'Sei sicuro di voler eliminare la procedura "{name}"?',
confirmDropFunctionTitle: "Elimina Funzione",
+5
View File
@@ -3145,6 +3145,7 @@ export default withEnglishFallback({
batchDrop: "選択を削除({count}件)",
batchEmpty: "選択したテーブルを空にする({count}件)",
batchTruncate: "選択をトランケート({count}件)",
batchMysqlAutoIncrement: "AUTO_INCREMENT を設定({count}件)",
executeProcedure: "プロシージャを実行",
confirmExecuteProcedureTitle: "プロシージャを実行",
confirmExecuteProcedureMessage: "プロシージャ「{name}」を実行しますか?実行前に入力パラメータの値を設定・調整できます。",
@@ -3217,6 +3218,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "選択した{count}テーブルのすべてのデータを削除しますか?",
confirmBatchTruncateTitle: "選択したテーブルをトランケート",
confirmBatchTruncateMessage: "選択した{count}テーブルをトランケートしますか?すべての行が削除されます。",
batchMysqlAutoIncrementTitle: "MySQL の AUTO_INCREMENT を設定({count} テーブル)",
batchMysqlAutoIncrementMessage: "選択した {count} テーブルの次の AUTO_INCREMENT 値を設定しますか?",
batchMysqlAutoIncrementSuccess: "{count} テーブルに AUTO_INCREMENT {value} を設定しました",
batchMysqlAutoIncrementPartialFail: "{success} テーブルの AUTO_INCREMENT を設定しました。{failed} テーブルが失敗しました",
confirmDropProcedureTitle: "プロシージャを削除",
confirmDropProcedureMessage: "本当にプロシージャ「{name}」を削除しますか?",
confirmDropFunctionTitle: "関数を削除",
+5
View File
@@ -3048,6 +3048,7 @@ export default withEnglishFallback({
batchDrop: "선택 항목 삭제 ({count})",
batchEmpty: "선택 항목 비우기 ({count})",
batchTruncate: "선택 항목 TRUNCATE ({count})",
batchMysqlAutoIncrement: "AUTO_INCREMENT 설정 ({count})",
batchDropIndexes: "인덱스 삭제 ({count})",
executeProcedure: "프로시저 실행",
confirmExecuteProcedureTitle: "프로시저 실행",
@@ -3092,6 +3093,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "선택한 테이블 {count}개의 모든 데이터를 삭제하시겠습니까?",
confirmBatchTruncateTitle: "선택한 테이블 TRUNCATE",
confirmBatchTruncateMessage: "선택한 테이블 {count}개를 TRUNCATE하시겠습니까? 모든 행이 제거됩니다.",
batchMysqlAutoIncrementTitle: "MySQL AUTO_INCREMENT 설정 ({count}개 테이블)",
batchMysqlAutoIncrementMessage: "선택한 {count}개 테이블의 다음 AUTO_INCREMENT 값을 설정하시겠습니까?",
batchMysqlAutoIncrementSuccess: "{count}개 테이블에 AUTO_INCREMENT {value} 설정 완료",
batchMysqlAutoIncrementPartialFail: "{success}개 테이블에 AUTO_INCREMENT 설정, {failed}개 실패",
confirmDropProcedureTitle: "프로시저 삭제",
confirmDropProcedureMessage: '프로시저 "{name}"을(를) 삭제하시겠습니까?',
confirmDropFunctionTitle: "함수 삭제",
+5
View File
@@ -3123,6 +3123,7 @@ export default withEnglishFallback({
batchDrop: "Remover selecionados ({count})",
batchEmpty: "Esvaziar selecionadas ({count})",
batchTruncate: "Truncar selecionadas ({count})",
batchMysqlAutoIncrement: "Definir AUTO_INCREMENT ({count})",
executeProcedure: "Executar Procedimento",
confirmExecuteProcedureTitle: "Executar Procedimento",
confirmExecuteProcedureMessage: 'Executar o procedimento "{name}"? Você pode preencher ou ajustar os valores dos parâmetros primeiro.',
@@ -3195,6 +3196,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "Tem certeza de que deseja excluir todos os dados de {count} tabelas selecionadas?",
confirmBatchTruncateTitle: "Truncar tabelas selecionadas",
confirmBatchTruncateMessage: "Tem certeza de que deseja truncar {count} tabelas selecionadas? Isso removerá todas as linhas.",
batchMysqlAutoIncrementTitle: "Definir AUTO_INCREMENT do MySQL ({count} tabelas)",
batchMysqlAutoIncrementMessage: "Definir o próximo valor de AUTO_INCREMENT solicitado para {count} tabelas selecionadas?",
batchMysqlAutoIncrementSuccess: "AUTO_INCREMENT {value} solicitado para {count} tabelas",
batchMysqlAutoIncrementPartialFail: "AUTO_INCREMENT definido para {success} tabelas, {failed} falharam",
confirmDropProcedureTitle: "Remover Procedimento",
confirmDropProcedureMessage: 'Tem certeza de que deseja remover o procedimento "{name}"?',
confirmDropFunctionTitle: "Remover Função",
+5
View File
@@ -3278,6 +3278,7 @@ export default withEnglishFallback({
batchDrop: "Seçilenleri sil ({count})",
batchEmpty: "Seçilenleri boşalt ({count})",
batchTruncate: "Seçilenleri truncate et ({count})",
batchMysqlAutoIncrement: "AUTO_INCREMENT Ayarla ({count})",
batchDropIndexes: "Dizinleri Sil ({count})",
executeProcedure: "Yordamı Çalıştır",
compileObject: "Derle",
@@ -3324,6 +3325,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "Seçili {count} tablodaki tüm verileri silmek istediğinizden emin misiniz?",
confirmBatchTruncateTitle: "Seçili Tabloları Truncate Et",
confirmBatchTruncateMessage: "Seçili {count} tabloyu truncate etmek istediğinizden emin misiniz? Bu, tüm satırları kaldırır.",
batchMysqlAutoIncrementTitle: "MySQL AUTO_INCREMENT Ayarla ({count} Tablo)",
batchMysqlAutoIncrementMessage: "Seçili {count} tablo için istenen bir sonraki AUTO_INCREMENT değeri ayarlansın mı?",
batchMysqlAutoIncrementSuccess: "{count} tablo için AUTO_INCREMENT {value} istendi",
batchMysqlAutoIncrementPartialFail: "{success} tablo için AUTO_INCREMENT ayarlandı, {failed} başarısız",
confirmDropProcedureTitle: "Yordamı Sil",
confirmDropProcedureMessage: '"{name}" yordamını silmek istediğinizden emin misiniz?',
confirmDropFunctionTitle: "İşlevi Sil",
+5
View File
@@ -3228,6 +3228,7 @@ export default withEnglishFallback({
batchDrop: "删除所选({count})",
batchEmpty: "清空所选({count})",
batchTruncate: "截断所选({count})",
batchMysqlAutoIncrement: "设置自增起始值({count})",
batchDropIndexes: "删除索引({count})",
executeProcedure: "执行过程",
compileObject: "编译",
@@ -3274,6 +3275,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "确定要删除已选择的 {count} 张表中的所有数据吗?",
confirmBatchTruncateTitle: "截断所选表",
confirmBatchTruncateMessage: "确定要截断已选择的 {count} 张表吗?这将删除所有行。",
batchMysqlAutoIncrementTitle: "设置 MySQL 自增起始值({count} 张表)",
batchMysqlAutoIncrementMessage: "确定要设置已选择的 {count} 张表请求的下一个自增值吗?",
batchMysqlAutoIncrementSuccess: "已为 {count} 张表请求自增值 {value}",
batchMysqlAutoIncrementPartialFail: "已为 {success} 张表设置自增值,{failed} 张失败",
confirmDropProcedureTitle: "删除存储过程",
confirmDropProcedureMessage: "确定要删除存储过程「{name}」吗?",
confirmDropFunctionTitle: "删除函数",
+5
View File
@@ -3124,6 +3124,7 @@ export default withEnglishFallback({
batchDrop: "刪除所選({count})",
batchEmpty: "清空所選({count})",
batchTruncate: "截斷所選({count})",
batchMysqlAutoIncrement: "設定自動遞增值({count})",
executeProcedure: "執行預存程序",
confirmExecuteProcedureTitle: "執行預存程序",
confirmExecuteProcedureMessage: "確認執行預存程序「{name}」?可先補充或調整參數值。",
@@ -3196,6 +3197,10 @@ export default withEnglishFallback({
confirmBatchEmptyMessage: "確定要刪除已選擇的 {count} 張資料表中的所有資料嗎?",
confirmBatchTruncateTitle: "截斷所選資料表",
confirmBatchTruncateMessage: "確定要截斷已選擇的 {count} 張資料表嗎?這將刪除所有行。",
batchMysqlAutoIncrementTitle: "設定 MySQL 自動遞增值({count} 張資料表)",
batchMysqlAutoIncrementMessage: "確定要設定已選擇的 {count} 張資料表請求的下一個自動遞增值嗎?",
batchMysqlAutoIncrementSuccess: "已為 {count} 張資料表請求自動遞增值 {value}",
batchMysqlAutoIncrementPartialFail: "已為 {success} 張資料表設定自動遞增值,{failed} 張失敗",
confirmDropProcedureTitle: "刪除預存程序",
confirmDropProcedureMessage: "確定要刪除預存程序「{name}」嗎?",
confirmDropFunctionTitle: "刪除函式",