Browse Source

Merge pull request #6736 from nocodb/nc-fix/6709-duplicate-column-bug

fix: avoid duplicate column_name error by adding suffix
pull/6738/head
Raju Udava 1 year ago committed by GitHub
parent
commit
4901b930cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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