|
|
@ -2059,6 +2059,7 @@ export class ColumnsService { |
|
|
|
req?: any; |
|
|
|
req?: any; |
|
|
|
columnId: string; |
|
|
|
columnId: string; |
|
|
|
user: UserType; |
|
|
|
user: UserType; |
|
|
|
|
|
|
|
forceDeleteSystem?: boolean; |
|
|
|
reuse?: ReusableParams; |
|
|
|
reuse?: ReusableParams; |
|
|
|
}, |
|
|
|
}, |
|
|
|
ncMeta = this.metaService, |
|
|
|
ncMeta = this.metaService, |
|
|
@ -2067,7 +2068,7 @@ export class ColumnsService { |
|
|
|
|
|
|
|
|
|
|
|
const column = await Column.get({ colId: param.columnId }, ncMeta); |
|
|
|
const column = await Column.get({ colId: param.columnId }, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
if (column.system) { |
|
|
|
if (column.system && !param.forceDeleteSystem) { |
|
|
|
NcError.badRequest( |
|
|
|
NcError.badRequest( |
|
|
|
`The column '${ |
|
|
|
`The column '${ |
|
|
|
column.title || column.column_name |
|
|
|
column.title || column.column_name |
|
|
@ -2178,9 +2179,11 @@ export class ColumnsService { |
|
|
|
colOpt.type === 'mm' && |
|
|
|
colOpt.type === 'mm' && |
|
|
|
colOpt.fk_parent_column_id === childColumn.id && |
|
|
|
colOpt.fk_parent_column_id === childColumn.id && |
|
|
|
colOpt.fk_child_column_id === parentColumn.id && |
|
|
|
colOpt.fk_child_column_id === parentColumn.id && |
|
|
|
colOpt.fk_mm_model_id === mmTable.id && |
|
|
|
colOpt.fk_mm_model_id === relationColOpt.fk_mm_model_id && |
|
|
|
colOpt.fk_mm_parent_column_id === mmChildCol.id && |
|
|
|
colOpt.fk_mm_parent_column_id === |
|
|
|
colOpt.fk_mm_child_column_id === mmParentCol.id |
|
|
|
relationColOpt.fk_mm_child_column_id && |
|
|
|
|
|
|
|
colOpt.fk_mm_child_column_id === |
|
|
|
|
|
|
|
relationColOpt.fk_mm_parent_column_id |
|
|
|
) { |
|
|
|
) { |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -2189,14 +2192,16 @@ export class ColumnsService { |
|
|
|
|
|
|
|
|
|
|
|
await Column.delete(relationColOpt.fk_column_id, ncMeta); |
|
|
|
await Column.delete(relationColOpt.fk_column_id, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
// delete bt columns in m2m table
|
|
|
|
if (mmTable) { |
|
|
|
await mmTable.getColumns(ncMeta); |
|
|
|
// delete bt columns in m2m table
|
|
|
|
for (const c of mmTable.columns) { |
|
|
|
await mmTable.getColumns(ncMeta); |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
for (const c of mmTable.columns) { |
|
|
|
const colOpt = |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
const colOpt = |
|
|
|
if (colOpt.type === 'bt') { |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
if (colOpt.type === 'bt') { |
|
|
|
|
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2206,7 +2211,9 @@ export class ColumnsService { |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
const colOpt = |
|
|
|
const colOpt = |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
if (colOpt.fk_related_model_id === mmTable.id) { |
|
|
|
if ( |
|
|
|
|
|
|
|
colOpt.fk_related_model_id === relationColOpt.fk_mm_model_id |
|
|
|
|
|
|
|
) { |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2217,20 +2224,24 @@ export class ColumnsService { |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
if (!isLinksOrLTAR(c.uidt)) continue; |
|
|
|
const colOpt = |
|
|
|
const colOpt = |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
await c.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
if (colOpt.fk_related_model_id === mmTable.id) { |
|
|
|
if ( |
|
|
|
|
|
|
|
colOpt.fk_related_model_id === relationColOpt.fk_mm_model_id |
|
|
|
|
|
|
|
) { |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
await Column.delete(c.id, ncMeta); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// retrieve columns in m2m table again
|
|
|
|
if (mmTable) { |
|
|
|
await mmTable.getColumns(ncMeta); |
|
|
|
// retrieve columns in m2m table again
|
|
|
|
|
|
|
|
await mmTable.getColumns(ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
// ignore deleting table if it has more than 2 columns
|
|
|
|
// ignore deleting table if it has more than 2 columns
|
|
|
|
// the expected 2 columns would be table1_id & table2_id
|
|
|
|
// the expected 2 columns would be table1_id & table2_id
|
|
|
|
if (mmTable.columns.length === 2) { |
|
|
|
if (mmTable.columns.length === 2) { |
|
|
|
(mmTable as any).tn = mmTable.table_name; |
|
|
|
(mmTable as any).tn = mmTable.table_name; |
|
|
|
await sqlMgr.sqlOpPlus(source, 'tableDelete', mmTable); |
|
|
|
await sqlMgr.sqlOpPlus(source, 'tableDelete', mmTable); |
|
|
|
await mmTable.delete(ncMeta); |
|
|
|
await mmTable.delete(ncMeta); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -2340,42 +2351,44 @@ export class ColumnsService { |
|
|
|
}, |
|
|
|
}, |
|
|
|
ignoreFkDelete = false, |
|
|
|
ignoreFkDelete = false, |
|
|
|
) => { |
|
|
|
) => { |
|
|
|
let foreignKeyName; |
|
|
|
if (childTable) { |
|
|
|
|
|
|
|
let foreignKeyName; |
|
|
|
// if relationColOpt is not provided, extract it from child table
|
|
|
|
|
|
|
|
// and get the foreign key name for dropping the foreign key
|
|
|
|
// if relationColOpt is not provided, extract it from child table
|
|
|
|
if (!relationColOpt) { |
|
|
|
// and get the foreign key name for dropping the foreign key
|
|
|
|
foreignKeyName = ( |
|
|
|
if (!relationColOpt) { |
|
|
|
( |
|
|
|
foreignKeyName = ( |
|
|
|
await childTable.getColumns(ncMeta).then(async (cols) => { |
|
|
|
( |
|
|
|
for (const col of cols) { |
|
|
|
await childTable.getColumns(ncMeta).then(async (cols) => { |
|
|
|
if (col.uidt === UITypes.LinkToAnotherRecord) { |
|
|
|
for (const col of cols) { |
|
|
|
const colOptions = |
|
|
|
if (col.uidt === UITypes.LinkToAnotherRecord) { |
|
|
|
await col.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
const colOptions = |
|
|
|
if (colOptions.fk_related_model_id === parentTable.id) { |
|
|
|
await col.getColOptions<LinkToAnotherRecordColumn>(ncMeta); |
|
|
|
return { colOptions }; |
|
|
|
if (colOptions.fk_related_model_id === parentTable.id) { |
|
|
|
|
|
|
|
return { colOptions }; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
)?.colOptions as LinkToAnotherRecordType |
|
|
|
)?.colOptions as LinkToAnotherRecordType |
|
|
|
).fk_index_name; |
|
|
|
).fk_index_name; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
foreignKeyName = relationColOpt.fk_index_name; |
|
|
|
foreignKeyName = relationColOpt.fk_index_name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!relationColOpt?.virtual && !virtual) { |
|
|
|
if (!relationColOpt?.virtual && !virtual) { |
|
|
|
// todo: handle relation delete exception
|
|
|
|
// todo: handle relation delete exception
|
|
|
|
try { |
|
|
|
try { |
|
|
|
await sqlMgr.sqlOpPlus(source, 'relationDelete', { |
|
|
|
await sqlMgr.sqlOpPlus(source, 'relationDelete', { |
|
|
|
childColumn: childColumn.column_name, |
|
|
|
childColumn: childColumn.column_name, |
|
|
|
childTable: childTable.table_name, |
|
|
|
childTable: childTable.table_name, |
|
|
|
parentTable: parentTable.table_name, |
|
|
|
parentTable: parentTable.table_name, |
|
|
|
parentColumn: parentColumn.column_name, |
|
|
|
parentColumn: parentColumn.column_name, |
|
|
|
foreignKeyName, |
|
|
|
foreignKeyName, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.log(e.message); |
|
|
|
console.log(e.message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2424,7 +2437,7 @@ export class ColumnsService { |
|
|
|
...index, |
|
|
|
...index, |
|
|
|
tn: cTable.table_name, |
|
|
|
tn: cTable.table_name, |
|
|
|
columns: [childColumn.column_name], |
|
|
|
columns: [childColumn.column_name], |
|
|
|
indexName: index.index_name, |
|
|
|
indexName: index.key_name, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|