Fixes #6032. Pg has a char limit on identifiers (= table, columns, enum names) of 63 bytes. Let's limit the metadata names that will be converted to identifiers (objects names, fields names, relation names, enum values) to 63 chars. For the sake of simplicity in the FE we will limit the input length of labels. --------- Co-authored-by: Charles Bochet <charles@twenty.com>
29 lines
792 B
TypeScript
29 lines
792 B
TypeScript
import { exceedsDatabaseIdentifierMaximumLength } from 'src/engine/metadata-modules/utils/validate-database-identifier-length.utils';
|
|
|
|
const VALID_STRING_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
|
|
|
|
export const validateMetadataNameOrThrow = (name: string) => {
|
|
if (!name.match(VALID_STRING_PATTERN)) {
|
|
throw new InvalidStringException(name);
|
|
}
|
|
if (exceedsDatabaseIdentifierMaximumLength(name)) {
|
|
throw new NameTooLongException(name);
|
|
}
|
|
};
|
|
|
|
export class InvalidStringException extends Error {
|
|
constructor(string: string) {
|
|
const message = `String "${string}" is not valid`;
|
|
|
|
super(message);
|
|
}
|
|
}
|
|
|
|
export class NameTooLongException extends Error {
|
|
constructor(string: string) {
|
|
const message = `String "${string}" exceeds 63 characters limit`;
|
|
|
|
super(message);
|
|
}
|
|
}
|