mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-17 04:00:48 +01: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: '',
|
||||
stringsWrapper: '"',
|
||||
tableAdd: false,
|
||||
tableTruncateDisableFKCheck: false,
|
||||
viewAdd: false,
|
||||
triggerAdd: false,
|
||||
triggerFunctionAdd: false,
|
||||
|
@ -28,6 +28,7 @@ export const customizations: Customizations = {
|
||||
elementsWrapper: '',
|
||||
stringsWrapper: '"',
|
||||
tableAdd: true,
|
||||
tableTruncateDisableFKCheck: true,
|
||||
viewAdd: true,
|
||||
triggerAdd: true,
|
||||
routineAdd: true,
|
||||
|
@ -29,7 +29,13 @@ export interface Customizations {
|
||||
elementsWrapper: string;
|
||||
stringsWrapper: string;
|
||||
tableAdd?: boolean;
|
||||
tableSettings?: boolean;
|
||||
tableOptions?: boolean;
|
||||
tableArray?: boolean;
|
||||
tableRealCount?: boolean;
|
||||
tableTruncateDisableFKCheck?: boolean;
|
||||
viewAdd?: boolean;
|
||||
viewSettings?: boolean;
|
||||
triggerAdd?: boolean;
|
||||
triggerFunctionAdd?: boolean;
|
||||
routineAdd?: boolean;
|
||||
@ -41,11 +47,6 @@ export interface Customizations {
|
||||
schemaExport?: boolean;
|
||||
exportByChunks?: boolean;
|
||||
schemaImport?: boolean;
|
||||
tableSettings?: boolean;
|
||||
tableOptions?: boolean;
|
||||
tableArray?: boolean;
|
||||
tableRealCount?: boolean;
|
||||
viewSettings?: boolean;
|
||||
triggerSettings?: boolean;
|
||||
triggerFunctionSettings?: boolean;
|
||||
routineSettings?: boolean;
|
||||
|
@ -912,8 +912,15 @@ export class MySQLClient extends AntaresCore {
|
||||
return await this.raw(sql);
|
||||
}
|
||||
|
||||
async truncateTable (params: { schema: string; table: string }) {
|
||||
const sql = `TRUNCATE TABLE \`${params.schema}\`.\`${params.table}\``;
|
||||
async truncateTable (params: { schema: string; table: string; force: boolean }) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,16 @@ const props = defineProps({
|
||||
default: false
|
||||
},
|
||||
confirmText: String,
|
||||
cancelText: String
|
||||
cancelText: String,
|
||||
disableAutofocus: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
const emit = defineEmits(['confirm', 'hide']);
|
||||
const slots = useSlots();
|
||||
|
||||
const { trapRef } = useFocusTrap({ disableAutofocus: true });
|
||||
const { trapRef } = useFocusTrap({ disableAutofocus: props.disableAutofocus });
|
||||
|
||||
const hasHeader = computed(() => !!slots.header);
|
||||
const hasBody = computed(() => !!slots.body);
|
||||
|
@ -8,31 +8,31 @@
|
||||
class="context-element"
|
||||
@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
|
||||
v-if="selectedTable && selectedTable.type === 'view' && customizations.viewSettings"
|
||||
class="context-element"
|
||||
@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
|
||||
v-if="selectedTable && selectedTable.type === 'table'"
|
||||
class="context-element"
|
||||
@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
|
||||
v-if="selectedTable && selectedTable.type === 'table'"
|
||||
class="context-element"
|
||||
@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 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>
|
||||
|
||||
<ConfirmModal
|
||||
@ -42,12 +42,17 @@
|
||||
>
|
||||
<template #header>
|
||||
<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>
|
||||
</template>
|
||||
<template #body>
|
||||
<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>
|
||||
</template>
|
||||
</ConfirmModal>
|
||||
@ -59,12 +64,12 @@
|
||||
<template #header>
|
||||
<div class="d-flex">
|
||||
<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>
|
||||
</template>
|
||||
<template #body>
|
||||
<div class="mb-2">
|
||||
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||
{{ t('message.deleteCorfirm') }} "<b>{{ selectedTable.name }}</b>"?
|
||||
</div>
|
||||
</template>
|
||||
</ConfirmModal>
|
||||
@ -79,6 +84,9 @@ import { useWorkspacesStore } from '@/stores/workspaces';
|
||||
import BaseContextMenu from '@/components/BaseContextMenu.vue';
|
||||
import ConfirmModal from '@/components/BaseConfirmModal.vue';
|
||||
import Tables from '@/ipc-api/Tables';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const props = defineProps({
|
||||
contextEvent: MouseEvent,
|
||||
@ -103,6 +111,7 @@ const {
|
||||
|
||||
const isDeleteModal = ref(false);
|
||||
const isEmptyModal = ref(false);
|
||||
const forceTruncate = ref(false);
|
||||
|
||||
const workspace = computed(() => getWorkspace(selectedWorkspace.value));
|
||||
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({
|
||||
uid: selectedWorkspace.value,
|
||||
table: props.selectedTable.name,
|
||||
schema: props.selectedSchema
|
||||
schema: props.selectedSchema,
|
||||
force: forceTruncate.value
|
||||
});
|
||||
|
||||
if (status === 'success')
|
||||
|
@ -457,8 +457,11 @@ const selectAllRows = (e: KeyboardEvent) => {
|
||||
|
||||
const deselectRows = (e: Event) => {
|
||||
if (!isEditingRow.value) {
|
||||
selectedRows.value = [];
|
||||
if (!isDeleteConfirmModal.value)
|
||||
selectedRows.value = [];
|
||||
|
||||
selectedField.value = null;
|
||||
|
||||
if (e.type === 'blur')
|
||||
hasFocus.value = false;
|
||||
}
|
||||
|
@ -70,6 +70,7 @@
|
||||
v-if="isTextareaEditor"
|
||||
:confirm-text="t('word.update')"
|
||||
size="medium"
|
||||
:disable-autofocus="true"
|
||||
@confirm="editOFF"
|
||||
@hide="hideEditorModal"
|
||||
>
|
||||
|
@ -290,7 +290,8 @@ module.exports = {
|
||||
disableBlur: 'Disable blur',
|
||||
untrustedConnection: 'Untrusted connection',
|
||||
missingOrIncompleteTranslation: 'Missing or incomplete translation?',
|
||||
findOutHowToContribute: 'Find out how to contribute'
|
||||
findOutHowToContribute: 'Find out how to contribute',
|
||||
disableFKChecks: 'Disable foreigh key checks'
|
||||
},
|
||||
faker: {
|
||||
address: 'Address',
|
||||
|
@ -98,7 +98,7 @@ export default class {
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user