mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-25 07:18:46 +02:00
feat(MySQL): option to disable foreign key checks when empty a table
This commit is contained in:
parent
5f57a9f60d
commit
902c29ffa5
@ -31,6 +31,7 @@ export const defaults: Customizations = {
|
|||||||
elementsWrapper: '',
|
elementsWrapper: '',
|
||||||
stringsWrapper: '"',
|
stringsWrapper: '"',
|
||||||
tableAdd: false,
|
tableAdd: false,
|
||||||
|
tableTruncateDisableFKCheck: false,
|
||||||
viewAdd: false,
|
viewAdd: false,
|
||||||
triggerAdd: false,
|
triggerAdd: false,
|
||||||
triggerFunctionAdd: false,
|
triggerFunctionAdd: false,
|
||||||
|
@ -28,6 +28,7 @@ export const customizations: Customizations = {
|
|||||||
elementsWrapper: '',
|
elementsWrapper: '',
|
||||||
stringsWrapper: '"',
|
stringsWrapper: '"',
|
||||||
tableAdd: true,
|
tableAdd: true,
|
||||||
|
tableTruncateDisableFKCheck: true,
|
||||||
viewAdd: true,
|
viewAdd: true,
|
||||||
triggerAdd: true,
|
triggerAdd: true,
|
||||||
routineAdd: true,
|
routineAdd: true,
|
||||||
|
@ -29,7 +29,13 @@ export interface Customizations {
|
|||||||
elementsWrapper: string;
|
elementsWrapper: string;
|
||||||
stringsWrapper: string;
|
stringsWrapper: string;
|
||||||
tableAdd?: boolean;
|
tableAdd?: boolean;
|
||||||
|
tableSettings?: boolean;
|
||||||
|
tableOptions?: boolean;
|
||||||
|
tableArray?: boolean;
|
||||||
|
tableRealCount?: boolean;
|
||||||
|
tableTruncateDisableFKCheck?: boolean;
|
||||||
viewAdd?: boolean;
|
viewAdd?: boolean;
|
||||||
|
viewSettings?: boolean;
|
||||||
triggerAdd?: boolean;
|
triggerAdd?: boolean;
|
||||||
triggerFunctionAdd?: boolean;
|
triggerFunctionAdd?: boolean;
|
||||||
routineAdd?: boolean;
|
routineAdd?: boolean;
|
||||||
@ -41,11 +47,6 @@ export interface Customizations {
|
|||||||
schemaExport?: boolean;
|
schemaExport?: boolean;
|
||||||
exportByChunks?: boolean;
|
exportByChunks?: boolean;
|
||||||
schemaImport?: boolean;
|
schemaImport?: boolean;
|
||||||
tableSettings?: boolean;
|
|
||||||
tableOptions?: boolean;
|
|
||||||
tableArray?: boolean;
|
|
||||||
tableRealCount?: boolean;
|
|
||||||
viewSettings?: boolean;
|
|
||||||
triggerSettings?: boolean;
|
triggerSettings?: boolean;
|
||||||
triggerFunctionSettings?: boolean;
|
triggerFunctionSettings?: boolean;
|
||||||
routineSettings?: boolean;
|
routineSettings?: boolean;
|
||||||
|
@ -912,8 +912,15 @@ export class MySQLClient extends AntaresCore {
|
|||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
async truncateTable (params: { schema: string; table: string }) {
|
async truncateTable (params: { schema: string; table: string; force: boolean }) {
|
||||||
const sql = `TRUNCATE TABLE \`${params.schema}\`.\`${params.table}\``;
|
let sql = `TRUNCATE TABLE \`${params.schema}\`.\`${params.table}\`;`;
|
||||||
|
if (params.force) {
|
||||||
|
sql = `
|
||||||
|
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||||
|
${sql}
|
||||||
|
SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1);
|
||||||
|
`;
|
||||||
|
}
|
||||||
return await this.raw(sql);
|
return await this.raw(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,16 @@ const props = defineProps({
|
|||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
confirmText: String,
|
confirmText: String,
|
||||||
cancelText: String
|
cancelText: String,
|
||||||
|
disableAutofocus: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const emit = defineEmits(['confirm', 'hide']);
|
const emit = defineEmits(['confirm', 'hide']);
|
||||||
const slots = useSlots();
|
const slots = useSlots();
|
||||||
|
|
||||||
const { trapRef } = useFocusTrap({ disableAutofocus: true });
|
const { trapRef } = useFocusTrap({ disableAutofocus: props.disableAutofocus });
|
||||||
|
|
||||||
const hasHeader = computed(() => !!slots.header);
|
const hasHeader = computed(() => !!slots.header);
|
||||||
const hasBody = computed(() => !!slots.body);
|
const hasBody = computed(() => !!slots.body);
|
||||||
|
@ -8,31 +8,31 @@
|
|||||||
class="context-element"
|
class="context-element"
|
||||||
@click="openTableSettingTab"
|
@click="openTableSettingTab"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ $t('word.settings') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ t('word.settings') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="selectedTable && selectedTable.type === 'view' && customizations.viewSettings"
|
v-if="selectedTable && selectedTable.type === 'view' && customizations.viewSettings"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@click="openViewSettingTab"
|
@click="openViewSettingTab"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ $t('word.settings') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ t('word.settings') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="selectedTable && selectedTable.type === 'table'"
|
v-if="selectedTable && selectedTable.type === 'table'"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@click="duplicateTable"
|
@click="duplicateTable"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-table-multiple text-light pr-1" /> {{ $t('message.duplicateTable') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-multiple text-light pr-1" /> {{ t('message.duplicateTable') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="selectedTable && selectedTable.type === 'table'"
|
v-if="selectedTable && selectedTable.type === 'table'"
|
||||||
class="context-element"
|
class="context-element"
|
||||||
@click="showEmptyModal"
|
@click="showEmptyModal"
|
||||||
>
|
>
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-table-off text-light pr-1" /> {{ $t('message.emptyTable') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-off text-light pr-1" /> {{ t('message.emptyTable') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="context-element" @click="showDeleteModal">
|
<div class="context-element" @click="showDeleteModal">
|
||||||
<span class="d-flex"><i class="mdi mdi-18px mdi-table-remove text-light pr-1" /> {{ $t('word.delete') }}</span>
|
<span class="d-flex"><i class="mdi mdi-18px mdi-table-remove text-light pr-1" /> {{ t('word.delete') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
@ -42,12 +42,17 @@
|
|||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<i class="mdi mdi-24px mdi-table-off mr-1" /> <span class="cut-text">{{ $t('message.emptyTable') }}</span>
|
<i class="mdi mdi-24px mdi-table-off mr-1" /> <span class="cut-text">{{ t('message.emptyTable') }}</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{{ $t('message.emptyCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
{{ t('message.emptyCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||||
|
</div>
|
||||||
|
<div v-if="customizations.tableTruncateDisableFKCheck">
|
||||||
|
<label class="form-checkbox form-inline">
|
||||||
|
<input v-model="forceTruncate" type="checkbox"><i class="form-icon" /> {{ t('message.disableFKChecks') }}
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
@ -59,12 +64,12 @@
|
|||||||
<template #header>
|
<template #header>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<i class="mdi mdi-24px mdi-table-remove mr-1" />
|
<i class="mdi mdi-24px mdi-table-remove mr-1" />
|
||||||
<span class="cut-text">{{ selectedTable.type === 'table' ? $t('message.deleteTable') : $t('message.deleteView') }}</span>
|
<span class="cut-text">{{ selectedTable.type === 'table' ? t('message.deleteTable') : t('message.deleteView') }}</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
{{ t('message.deleteCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
@ -79,6 +84,9 @@ import { useWorkspacesStore } from '@/stores/workspaces';
|
|||||||
import BaseContextMenu from '@/components/BaseContextMenu.vue';
|
import BaseContextMenu from '@/components/BaseContextMenu.vue';
|
||||||
import ConfirmModal from '@/components/BaseConfirmModal.vue';
|
import ConfirmModal from '@/components/BaseConfirmModal.vue';
|
||||||
import Tables from '@/ipc-api/Tables';
|
import Tables from '@/ipc-api/Tables';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
contextEvent: MouseEvent,
|
contextEvent: MouseEvent,
|
||||||
@ -103,6 +111,7 @@ const {
|
|||||||
|
|
||||||
const isDeleteModal = ref(false);
|
const isDeleteModal = ref(false);
|
||||||
const isEmptyModal = ref(false);
|
const isEmptyModal = ref(false);
|
||||||
|
const forceTruncate = ref(false);
|
||||||
|
|
||||||
const workspace = computed(() => getWorkspace(selectedWorkspace.value));
|
const workspace = computed(() => getWorkspace(selectedWorkspace.value));
|
||||||
const customizations = computed(() => workspace.value && workspace.value.customizations ? workspace.value.customizations : null);
|
const customizations = computed(() => workspace.value && workspace.value.customizations ? workspace.value.customizations : null);
|
||||||
@ -178,7 +187,8 @@ const emptyTable = async () => {
|
|||||||
const { status, response } = await Tables.truncateTable({
|
const { status, response } = await Tables.truncateTable({
|
||||||
uid: selectedWorkspace.value,
|
uid: selectedWorkspace.value,
|
||||||
table: props.selectedTable.name,
|
table: props.selectedTable.name,
|
||||||
schema: props.selectedSchema
|
schema: props.selectedSchema,
|
||||||
|
force: forceTruncate.value
|
||||||
});
|
});
|
||||||
|
|
||||||
if (status === 'success')
|
if (status === 'success')
|
||||||
|
@ -457,8 +457,11 @@ const selectAllRows = (e: KeyboardEvent) => {
|
|||||||
|
|
||||||
const deselectRows = (e: Event) => {
|
const deselectRows = (e: Event) => {
|
||||||
if (!isEditingRow.value) {
|
if (!isEditingRow.value) {
|
||||||
|
if (!isDeleteConfirmModal.value)
|
||||||
selectedRows.value = [];
|
selectedRows.value = [];
|
||||||
|
|
||||||
selectedField.value = null;
|
selectedField.value = null;
|
||||||
|
|
||||||
if (e.type === 'blur')
|
if (e.type === 'blur')
|
||||||
hasFocus.value = false;
|
hasFocus.value = false;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
v-if="isTextareaEditor"
|
v-if="isTextareaEditor"
|
||||||
:confirm-text="t('word.update')"
|
:confirm-text="t('word.update')"
|
||||||
size="medium"
|
size="medium"
|
||||||
|
:disable-autofocus="true"
|
||||||
@confirm="editOFF"
|
@confirm="editOFF"
|
||||||
@hide="hideEditorModal"
|
@hide="hideEditorModal"
|
||||||
>
|
>
|
||||||
|
@ -290,7 +290,8 @@ module.exports = {
|
|||||||
disableBlur: 'Disable blur',
|
disableBlur: 'Disable blur',
|
||||||
untrustedConnection: 'Untrusted connection',
|
untrustedConnection: 'Untrusted connection',
|
||||||
missingOrIncompleteTranslation: 'Missing or incomplete translation?',
|
missingOrIncompleteTranslation: 'Missing or incomplete translation?',
|
||||||
findOutHowToContribute: 'Find out how to contribute'
|
findOutHowToContribute: 'Find out how to contribute',
|
||||||
|
disableFKChecks: 'Disable foreigh key checks'
|
||||||
},
|
},
|
||||||
faker: {
|
faker: {
|
||||||
address: 'Address',
|
address: 'Address',
|
||||||
|
@ -98,7 +98,7 @@ export default class {
|
|||||||
return ipcRenderer.invoke('duplicate-table', unproxify(params));
|
return ipcRenderer.invoke('duplicate-table', unproxify(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
static truncateTable (params: { uid: string; schema: string; table: string }): Promise<IpcResponse> {
|
static truncateTable (params: { uid: string; schema: string; table: string; force: boolean }): Promise<IpcResponse> {
|
||||||
return ipcRenderer.invoke('truncate-table', unproxify(params));
|
return ipcRenderer.invoke('truncate-table', unproxify(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user