Browse Source

fix: deprecate old validator

pull/7092/head
mertmit 1 year ago
parent
commit
c0a8aacab0
  1. 2
      packages/nc-gui/components/template/Editor.vue
  2. 2
      packages/nc-gui/composables/useColumnCreateStore.ts
  3. 18
      packages/nc-gui/utils/validation.ts
  4. 7
      packages/nocodb/src/services/tables.service.ts

2
packages/nc-gui/components/template/Editor.vue

@ -133,7 +133,7 @@ const validators = computed(() =>
table.columns?.forEach((column, columnIdx) => { table.columns?.forEach((column, columnIdx) => {
acc[`tables.${tableIdx}.columns.${columnIdx}.column_name`] = [ acc[`tables.${tableIdx}.columns.${columnIdx}.column_name`] = [
fieldRequiredValidator(), fieldRequiredValidator(),
fieldLengthValidator(base.value?.sources?.[0].type || ClientType.MYSQL), fieldLengthValidator(),
] ]
acc[`tables.${tableIdx}.columns.${columnIdx}.uidt`] = [fieldRequiredValidator()] acc[`tables.${tableIdx}.columns.${columnIdx}.uidt`] = [fieldRequiredValidator()]
if (isSelect(column)) { if (isSelect(column)) {

2
packages/nc-gui/composables/useColumnCreateStore.ts

@ -136,7 +136,7 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
}) })
}, },
}, },
fieldLengthValidator(source.value?.type || ClientType.MYSQL), fieldLengthValidator(),
], ],
uidt: [ uidt: [
{ {

18
packages/nc-gui/utils/validation.ts

@ -102,21 +102,17 @@ export const fieldRequiredValidator = () => {
} }
} }
export const fieldLengthValidator = (sqlClientType: string) => { export const fieldLengthValidator = () => {
return { return {
validator: (rule: any, value: any) => { validator: (rule: any, value: any) => {
const { t } = getI18n().global const { t } = getI18n().global
// no limit for sqlite but set as 255 /// mysql allows 64 characters for column_name
let fieldLengthLimit = 255 // postgres allows 59 characters for column_name
// mssql allows 128 characters for column_name
if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') { // sqlite allows any number of characters for column_name
fieldLengthLimit = 64 // We allow 255 for all databases, truncate will be handled by backend for column_name
} else if (sqlClientType === 'pg') { const fieldLengthLimit = 255
fieldLengthLimit = 59
} else if (sqlClientType === 'mssql') {
fieldLengthLimit = 128
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (value?.length > fieldLengthLimit) { if (value?.length > fieldLengthLimit) {

7
packages/nocodb/src/services/tables.service.ts

@ -459,7 +459,12 @@ export class TablesService {
for (const column of param.table.columns) { for (const column of param.table.columns) {
if (!isVirtualCol(column)) { if (!isVirtualCol(column)) {
column.column_name = sanitizeColumnName(column.column_name); const mxColumnLength = Column.getMaxColumnNameLength(sqlClientType);
// - 5 is a buffer for suffix
column.column_name = sanitizeColumnName(
column.column_name.slice(0, mxColumnLength - 5),
);
if (uniqueColumnNameCount[column.column_name]) { if (uniqueColumnNameCount[column.column_name]) {
let suffix = 1; let suffix = 1;

Loading…
Cancel
Save