mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
fix(MySQL): handle absence of CHECK_CONSTRAINTS table, fixes #981
This commit is contained in:
@@ -696,7 +696,12 @@ export class MySQLClient extends BaseClient {
|
|||||||
return rows.length ? rows[0].count : 0;
|
return rows.length ? rows[0].count : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTableChecks ({ schema, table }: { schema: string; table: string }): Promise<antares.TableCheck[]> {
|
async getTableChecks ({ schema, table }: { schema: string; table: string }): Promise<antares.TableCheck[] | false> {
|
||||||
|
const { rows: checkTableExists } = await this.raw('SELECT table_name FROM information_schema.tables WHERE table_schema = "information_schema" AND table_name = "CHECK_CONSTRAINTS"');
|
||||||
|
|
||||||
|
if (!checkTableExists.length)// check if CHECK_CONSTRAINTS table exists
|
||||||
|
return false;
|
||||||
|
|
||||||
const { rows } = await this.raw(`
|
const { rows } = await this.raw(`
|
||||||
SELECT
|
SELECT
|
||||||
CONSTRAINT_NAME as name,
|
CONSTRAINT_NAME as name,
|
||||||
|
@@ -73,7 +73,7 @@
|
|||||||
<span>{{ t('database.foreignKeys') }}</span>
|
<span>{{ t('database.foreignKeys') }}</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="workspace.customizations.tableCheck"
|
v-if="workspace.customizations.tableCheck && originalTableChecks !== false"
|
||||||
class="btn btn-dark btn-sm ml-2 mr-0"
|
class="btn btn-dark btn-sm ml-2 mr-0"
|
||||||
:disabled="isSaving"
|
:disabled="isSaving"
|
||||||
:title="t('database.manageTableChecks')"
|
:title="t('database.manageTableChecks')"
|
||||||
@@ -234,7 +234,7 @@
|
|||||||
/>
|
/>
|
||||||
<WorkspaceTabPropsTableChecksModal
|
<WorkspaceTabPropsTableChecksModal
|
||||||
v-if="isTableChecksModal"
|
v-if="isTableChecksModal"
|
||||||
:local-checks="localTableChecks"
|
:local-checks="localTableChecks || []"
|
||||||
:table="table"
|
:table="table"
|
||||||
:workspace="workspace"
|
:workspace="workspace"
|
||||||
@hide="hideTableChecksModal"
|
@hide="hideTableChecksModal"
|
||||||
@@ -305,8 +305,8 @@ const originalKeyUsage: Ref<TableForeign[]> = ref([]);
|
|||||||
const localKeyUsage: Ref<TableForeign[]> = ref([]);
|
const localKeyUsage: Ref<TableForeign[]> = ref([]);
|
||||||
const originalIndexes: Ref<TableIndex[]> = ref([]);
|
const originalIndexes: Ref<TableIndex[]> = ref([]);
|
||||||
const localIndexes: Ref<TableIndex[]> = ref([]);
|
const localIndexes: Ref<TableIndex[]> = ref([]);
|
||||||
const originalTableChecks: Ref<TableCheck[]> = ref([]);
|
const originalTableChecks: Ref<TableCheck[] | false> = ref([]);
|
||||||
const localTableChecks: Ref<TableCheck[]> = ref([]);
|
const localTableChecks: Ref<TableCheck[] | false> = ref(false);
|
||||||
const tableOptions: Ref<TableOptions> = ref(null);
|
const tableOptions: Ref<TableOptions> = ref(null);
|
||||||
const localOptions: Ref<TableOptions> = ref({} as TableOptions);
|
const localOptions: Ref<TableOptions> = ref({} as TableOptions);
|
||||||
const lastTable = ref(null);
|
const lastTable = ref(null);
|
||||||
@@ -465,13 +465,19 @@ const getFieldsData = async () => {
|
|||||||
const { status, response } = await Tables.getTableChecks(params);
|
const { status, response } = await Tables.getTableChecks(params);
|
||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
originalTableChecks.value = response.map((check: TableCheck) => {
|
if (response === false) {
|
||||||
return {
|
originalTableChecks.value = false;
|
||||||
_antares_id: uidGen(),
|
localTableChecks.value = false;
|
||||||
...check
|
}
|
||||||
};
|
else {
|
||||||
});
|
originalTableChecks.value = response.map((check: TableCheck) => {
|
||||||
localTableChecks.value = JSON.parse(JSON.stringify(originalTableChecks.value));
|
return {
|
||||||
|
_antares_id: uidGen(),
|
||||||
|
...check
|
||||||
|
};
|
||||||
|
});
|
||||||
|
localTableChecks.value = JSON.parse(JSON.stringify(originalTableChecks.value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
addNotification({ status: 'error', message: response });
|
addNotification({ status: 'error', message: response });
|
||||||
@@ -576,32 +582,68 @@ const saveChanges = async () => {
|
|||||||
// Foreigns Deletions
|
// Foreigns Deletions
|
||||||
foreignChanges.deletions = originalKeyUsage.value.filter(foreign => !localForeignIDs.includes(foreign._antares_id));
|
foreignChanges.deletions = originalKeyUsage.value.filter(foreign => !localForeignIDs.includes(foreign._antares_id));
|
||||||
|
|
||||||
|
// CHECKS
|
||||||
|
if (originalTableChecks.value !== false && localTableChecks.value !== false) {
|
||||||
|
const checkChanges = {
|
||||||
|
additions: [] as TableCheck[],
|
||||||
|
changes: [] as TableCheck[],
|
||||||
|
deletions: [] as TableCheck[]
|
||||||
|
};
|
||||||
|
const originalCheckIDs = originalTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
||||||
|
const localCheckIDs = localTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
||||||
|
|
||||||
|
// Check Additions
|
||||||
|
checkChanges.additions = localTableChecks.value.filter(check => !originalCheckIDs.includes(check._antares_id));
|
||||||
|
|
||||||
|
// Check Changes
|
||||||
|
originalTableChecks.value.forEach(originalCheck => {
|
||||||
|
const lI = Array.isArray(localTableChecks.value)
|
||||||
|
? localTableChecks.value.findIndex(localCheck => localCheck._antares_id === originalCheck._antares_id)
|
||||||
|
: -1;
|
||||||
|
if (Array.isArray(localTableChecks.value) && JSON.stringify(originalCheck) !== JSON.stringify(localTableChecks.value[lI])) {
|
||||||
|
if (localTableChecks.value[lI]) {
|
||||||
|
checkChanges.changes.push({
|
||||||
|
...localTableChecks.value[lI]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check Deletions
|
||||||
|
checkChanges.deletions = originalTableChecks.value.filter(check => !localCheckIDs.includes(check._antares_id));
|
||||||
|
}
|
||||||
|
|
||||||
// CHECKS
|
// CHECKS
|
||||||
const checkChanges = {
|
const checkChanges = {
|
||||||
additions: [] as TableCheck[],
|
additions: [] as TableCheck[],
|
||||||
changes: [] as TableCheck[],
|
changes: [] as TableCheck[],
|
||||||
deletions: [] as TableCheck[]
|
deletions: [] as TableCheck[]
|
||||||
};
|
};
|
||||||
const originalCheckIDs = originalTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
|
||||||
const localCheckIDs = localTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
|
||||||
|
|
||||||
// Check Additions
|
if (originalTableChecks.value !== false && localTableChecks.value !== false) {
|
||||||
checkChanges.additions = localTableChecks.value.filter(check => !originalCheckIDs.includes(check._antares_id));
|
const originalCheckIDs = originalTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
||||||
|
const localCheckIDs = localTableChecks.value.reduce((acc, curr) => [...acc, curr._antares_id], []);
|
||||||
|
|
||||||
// Check Changes
|
// Check Additions
|
||||||
originalTableChecks.value.forEach(originalCheck => {
|
checkChanges.additions = localTableChecks.value.filter(check => !originalCheckIDs.includes(check._antares_id));
|
||||||
const lI = localTableChecks.value.findIndex(localCheck => localCheck._antares_id === originalCheck._antares_id);
|
|
||||||
if (JSON.stringify(originalCheck) !== JSON.stringify(localTableChecks.value[lI])) {
|
// Check Changes
|
||||||
if (localTableChecks.value[lI]) {
|
originalTableChecks.value.forEach(originalCheck => {
|
||||||
checkChanges.changes.push({
|
const lI = Array.isArray(localTableChecks.value)
|
||||||
...localTableChecks.value[lI]
|
? localTableChecks.value.findIndex(localCheck => localCheck._antares_id === originalCheck._antares_id)
|
||||||
});
|
: -1;
|
||||||
|
if (Array.isArray(localTableChecks.value) && JSON.stringify(originalCheck) !== JSON.stringify(localTableChecks.value[lI])) {
|
||||||
|
if (localTableChecks.value[lI]) {
|
||||||
|
checkChanges.changes.push({
|
||||||
|
...localTableChecks.value[lI]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Check Deletions
|
// Check Deletions
|
||||||
checkChanges.deletions = originalTableChecks.value.filter(check => !localCheckIDs.includes(check._antares_id));
|
checkChanges.deletions = originalTableChecks.value.filter(check => !localCheckIDs.includes(check._antares_id));
|
||||||
|
}
|
||||||
|
|
||||||
// ALTER
|
// ALTER
|
||||||
const params = {
|
const params = {
|
||||||
|
Reference in New Issue
Block a user