Browse Source

fix: avoid duplicate column_name error by adding suffix

pull/6736/head
Pranav C 1 year ago
parent
commit
aa5cc48c0a
  1. 7
      packages/nocodb/src/helpers/columnHelpers.ts
  2. 10
      packages/nocodb/src/services/columns.service.ts

7
packages/nocodb/src/helpers/columnHelpers.ts

@ -264,5 +264,10 @@ export async function populateRollupForLTAR({
}
export const sanitizeColumnName = (name: string) => {
return name.replace(/\W+/g, '_').trim();
const columnName = name.replace(/\W+/g, '_').trim();
// if column name only contains _ then return as 'field'
if (/^_+$/.test(columnName)) return 'field';
return columnName;
};

10
packages/nocodb/src/services/columns.service.ts

@ -123,10 +123,7 @@ export class ColumnsService {
param.column.column_name = sanitizeColumnName(param.column.column_name);
}
if (
param.column.column_name &&
param.column.column_name.length > mxColumnLength
) {
if (param.column.column_name) {
// - 5 is a buffer for suffix
let colName = param.column.column_name.slice(0, mxColumnLength - 5);
let suffix = 1;
@ -1069,10 +1066,7 @@ export class ColumnsService {
param.column.column_name = sanitizeColumnName(param.column.column_name);
}
if (
param.column.column_name &&
param.column.column_name.length > mxColumnLength
) {
if (param.column.column_name) {
// - 5 is a buffer for suffix
let colName = param.column.column_name.slice(0, mxColumnLength - 5);
let suffix = 1;

Loading…
Cancel
Save