forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid names above 63 characters to comply with pg identifier limit (t…
…wentyhq#6095) Fixes twentyhq#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>
- Loading branch information
1 parent
5df0ea6
commit 6cd154a
Showing
18 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...twenty-front/src/modules/settings/data-model/constants/DatabaseIdentifierMaximumLength.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const DATABASE_IDENTIFIER_MAXIMUM_LENGTH = 63; |
3 changes: 3 additions & 0 deletions
3
packages/twenty-front/src/modules/settings/data-model/constants/FieldNameMaximumLength.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength'; | ||
|
||
export const FIELD_NAME_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH; |
3 changes: 3 additions & 0 deletions
3
packages/twenty-front/src/modules/settings/data-model/constants/ObjectNameMaximumLength.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength'; | ||
|
||
export const OBJECT_NAME_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH; |
3 changes: 3 additions & 0 deletions
3
packages/twenty-front/src/modules/settings/data-model/constants/OptionValueMaximumLength.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength'; | ||
|
||
export const OPTION_VALUE_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 30 additions & 7 deletions
37
.../twenty-server/src/engine/metadata-modules/utils/__tests__/validate-metadata-name.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,57 @@ | ||
import { | ||
validateMetadataName, | ||
validateMetadataNameOrThrow, | ||
InvalidStringException, | ||
NameTooLongException, | ||
} from 'src/engine/metadata-modules/utils/validate-metadata-name.utils'; | ||
|
||
describe('validateMetadataName', () => { | ||
describe('validateMetadataNameOrThrow', () => { | ||
it('does not throw if string is valid', () => { | ||
const input = 'testName'; | ||
|
||
expect(validateMetadataName(input)).not.toThrow; | ||
expect(validateMetadataNameOrThrow(input)).not.toThrow; | ||
}); | ||
it('throws error if string has spaces', () => { | ||
const input = 'name with spaces'; | ||
|
||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException); | ||
expect(() => validateMetadataNameOrThrow(input)).toThrow( | ||
InvalidStringException, | ||
); | ||
}); | ||
it('throws error if string starts with capital letter', () => { | ||
const input = 'StringStartingWithCapitalLetter'; | ||
|
||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException); | ||
expect(() => validateMetadataNameOrThrow(input)).toThrow( | ||
InvalidStringException, | ||
); | ||
}); | ||
|
||
it('throws error if string has non latin characters', () => { | ||
const input = 'בְרִבְרִ'; | ||
|
||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException); | ||
expect(() => validateMetadataNameOrThrow(input)).toThrow( | ||
InvalidStringException, | ||
); | ||
}); | ||
|
||
it('throws error if starts with digits', () => { | ||
const input = '123string'; | ||
|
||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException); | ||
expect(() => validateMetadataNameOrThrow(input)).toThrow( | ||
InvalidStringException, | ||
); | ||
}); | ||
it('does not throw if string is less than 63 characters', () => { | ||
const inputWith63Characters = | ||
'thisIsAstringWithSixtyThreeCharacters11111111111111111111111111'; | ||
|
||
expect(validateMetadataNameOrThrow(inputWith63Characters)).not.toThrow; | ||
}); | ||
it('throws error if string is above 63 characters', () => { | ||
const inputWith64Characters = | ||
'thisIsAstringWithSixtyFourCharacters1111111111111111111111111111'; | ||
|
||
expect(() => validateMetadataNameOrThrow(inputWith64Characters)).toThrow( | ||
NameTooLongException, | ||
); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/twenty-server/src/engine/metadata-modules/utils/metadata.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const IDENTIFIER_MAX_CHAR_LENGTH = 63; |
5 changes: 5 additions & 0 deletions
5
...nty-server/src/engine/metadata-modules/utils/validate-database-identifier-length.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'src/engine/metadata-modules/utils/metadata.constants'; | ||
|
||
export const exceedsDatabaseIdentifierMaximumLength = (string: string) => { | ||
return string.length > IDENTIFIER_MAX_CHAR_LENGTH; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters