|
|
@ -466,6 +466,20 @@ export class TablesService { |
|
|
|
req?: any; |
|
|
|
req?: any; |
|
|
|
}, |
|
|
|
}, |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
// before validating add title for columns if only column name is present
|
|
|
|
|
|
|
|
if (param.table.columns) { |
|
|
|
|
|
|
|
param.table.columns.forEach((c) => { |
|
|
|
|
|
|
|
if (!c.title && c.column_name) { |
|
|
|
|
|
|
|
c.title = c.column_name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// before validating add title for table if only table name is present
|
|
|
|
|
|
|
|
if (!param.table.title && param.table.table_name) { |
|
|
|
|
|
|
|
param.table.title = param.table.table_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
validatePayload('swagger.json#/components/schemas/TableReq', param.table); |
|
|
|
validatePayload('swagger.json#/components/schemas/TableReq', param.table); |
|
|
|
|
|
|
|
|
|
|
|
const tableCreatePayLoad: Omit<TableReqType, 'columns'> & { |
|
|
|
const tableCreatePayLoad: Omit<TableReqType, 'columns'> & { |
|
|
@ -558,13 +572,22 @@ export class TablesService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tableCreatePayLoad.title) { |
|
|
|
|
|
|
|
NcError.badRequest('Missing table `title` property in request body'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tableCreatePayLoad.table_name) { |
|
|
|
|
|
|
|
tableCreatePayLoad.table_name = tableCreatePayLoad.title; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
!tableCreatePayLoad.table_name || |
|
|
|
!(await Model.checkAliasAvailable(context, { |
|
|
|
(base.prefix && base.prefix === tableCreatePayLoad.table_name) |
|
|
|
title: tableCreatePayLoad.title, |
|
|
|
|
|
|
|
base_id: base.id, |
|
|
|
|
|
|
|
source_id: source.id, |
|
|
|
|
|
|
|
})) |
|
|
|
) { |
|
|
|
) { |
|
|
|
NcError.badRequest( |
|
|
|
NcError.badRequest('Duplicate table alias'); |
|
|
|
'Missing table name `table_name` property in request body', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (source.type === 'databricks') { |
|
|
|
if (source.type === 'databricks') { |
|
|
@ -608,16 +631,6 @@ export class TablesService { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
!(await Model.checkAliasAvailable(context, { |
|
|
|
|
|
|
|
title: tableCreatePayLoad.title, |
|
|
|
|
|
|
|
base_id: base.id, |
|
|
|
|
|
|
|
source_id: source.id, |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
NcError.badRequest('Duplicate table alias'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sqlMgr = await ProjectMgrv2.getSqlMgr(context, base); |
|
|
|
const sqlMgr = await ProjectMgrv2.getSqlMgr(context, base); |
|
|
|
|
|
|
|
|
|
|
|
const sqlClient = await NcConnectionMgrv2.getSqlClient(source); |
|
|
|
const sqlClient = await NcConnectionMgrv2.getSqlClient(source); |
|
|
@ -652,6 +665,11 @@ export class TablesService { |
|
|
|
) { |
|
|
|
) { |
|
|
|
const mxColumnLength = Column.getMaxColumnNameLength(sqlClientType); |
|
|
|
const mxColumnLength = Column.getMaxColumnNameLength(sqlClientType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set column name using title if not present
|
|
|
|
|
|
|
|
if (!column.column_name && column.title) { |
|
|
|
|
|
|
|
column.column_name = column.title; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// - 5 is a buffer for suffix
|
|
|
|
// - 5 is a buffer for suffix
|
|
|
|
column.column_name = sanitizeColumnName( |
|
|
|
column.column_name = sanitizeColumnName( |
|
|
|
column.column_name.slice(0, mxColumnLength - 5), |
|
|
|
column.column_name.slice(0, mxColumnLength - 5), |
|
|
|