Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid names above 63 characters to comply with pg identifier limit #6095

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve naming
  • Loading branch information
ijreilly committed Jul 4, 2024
commit a712262a464cdecfe6bacec769fd73d4bd2f6dab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DATABASE_IDENTIFIER_MAXIMUM_LENGTH = 63;
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;
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;
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;
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { isObjectMetadataAvailableForRelation } from '@/object-metadata/utils/isObjectMetadataAvailableForRelation';
import { fieldMetadataItemSchema } from '@/object-metadata/validation-schemas/fieldMetadataItemSchema';
import { FIELD_NAME_MAXIMUM_LENGTH } from '@/settings/data-model/constants/FieldNameMaximumLength';
import { RELATION_TYPES } from '@/settings/data-model/constants/RelationTypes';
import { useRelationSettingsFormInitialValues } from '@/settings/data-model/fields/forms/relation/hooks/useRelationSettingsFormInitialValues';
import { RelationType } from '@/settings/data-model/types/RelationType';
import { IconPicker } from '@/ui/input/components/IconPicker';
import { Select } from '@/ui/input/components/Select';
import { TextInput } from '@/ui/input/components/TextInput';
import { NAME_MAXIMUM_LENGTH } from '~/pages/settings/data-model/constants/NameMaximumLength';

export const settingsDataModelFieldRelationFormSchema = z.object({
relation: z.object({
Expand Down Expand Up @@ -164,7 +164,7 @@ export const SettingsDataModelFieldRelationForm = ({
value={value}
onChange={onChange}
fullWidth
maxLength={NAME_MAXIMUM_LENGTH}
maxLength={FIELD_NAME_MAXIMUM_LENGTH}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { v4 } from 'uuid';

import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem';
import { OPTION_VALUE_MAXIMUM_LENGTH } from '@/settings/data-model/constants/OptionValueMaximumLength';
import { getOptionValueFromLabel } from '@/settings/data-model/fields/forms/select/utils/getOptionValueFromLabel';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { TextInput } from '@/ui/input/components/TextInput';
Expand All @@ -22,7 +23,6 @@ import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/Drop
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { MenuItemSelectColor } from '@/ui/navigation/menu-item/components/MenuItemSelectColor';
import { NAME_MAXIMUM_LENGTH } from '~/pages/settings/data-model/constants/NameMaximumLength';

type SettingsDataModelFieldSelectFormOptionRowProps = {
className?: string;
Expand Down Expand Up @@ -134,7 +134,7 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
})
}
RightIcon={isDefault ? IconCheck : undefined}
maxLength={NAME_MAXIMUM_LENGTH}
maxLength={OPTION_VALUE_MAXIMUM_LENGTH}
/>
<Dropdown
dropdownId={dropdownIds.actions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from 'zod';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { objectMetadataItemSchema } from '@/object-metadata/validation-schemas/objectMetadataItemSchema';
import { OBJECT_NAME_MAXIMUM_LENGTH } from '@/settings/data-model/constants/ObjectNameMaximumLength';
import { IconPicker } from '@/ui/input/components/IconPicker';
import { TextArea } from '@/ui/input/components/TextArea';
import { TextInput } from '@/ui/input/components/TextInput';
Expand Down Expand Up @@ -97,6 +98,7 @@ export const SettingsDataModelObjectAboutForm = ({
onChange={onChange}
disabled={disabled || disableNameEdit}
fullWidth
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RecordFieldValueSelectorContextProvider } from '@/object-record/record-
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { FIELD_NAME_MAXIMUM_LENGTH } from '@/settings/data-model/constants/FieldNameMaximumLength';
import { SettingsDataModelFieldAboutForm } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldAboutForm';
import { SettingsDataModelFieldSettingsFormCard } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard';
import { SettingsDataModelFieldTypeSelect } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldTypeSelect';
Expand All @@ -34,7 +35,6 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer'
import { Section } from '@/ui/layout/section/components/Section';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { NAME_MAXIMUM_LENGTH } from '~/pages/settings/data-model/constants/NameMaximumLength';
import { isDefined } from '~/utils/isDefined';

type SettingsDataModelFieldEditFormValues = z.infer<
Expand Down Expand Up @@ -203,7 +203,7 @@ export const SettingsObjectFieldEdit = () => {
<SettingsDataModelFieldAboutForm
disabled={!activeMetadataField.isCustom}
fieldMetadataItem={activeMetadataField}
maxLength={NAME_MAXIMUM_LENGTH}
maxLength={FIELD_NAME_MAXIMUM_LENGTH}
/>
</Section>
<Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RecordFieldValueSelectorContextProvider } from '@/object-record/record-
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { FIELD_NAME_MAXIMUM_LENGTH } from '@/settings/data-model/constants/FieldNameMaximumLength';
import { SettingsDataModelFieldAboutForm } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldAboutForm';
import { SettingsDataModelFieldSettingsFormCard } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard';
import { SettingsDataModelFieldTypeSelect } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldTypeSelect';
Expand All @@ -31,7 +32,6 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { View } from '@/views/types/View';
import { ViewType } from '@/views/types/ViewType';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { NAME_MAXIMUM_LENGTH } from '~/pages/settings/data-model/constants/NameMaximumLength';
import { isDefined } from '~/utils/isDefined';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';

Expand Down Expand Up @@ -204,7 +204,7 @@ export const SettingsObjectNewFieldStep2 = () => {
description="The name and description of this field"
/>
<SettingsDataModelFieldAboutForm
maxLength={NAME_MAXIMUM_LENGTH}
maxLength={FIELD_NAME_MAXIMUM_LENGTH}
/>
</Section>
<Section>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
FieldMetadataException,
FieldMetadataExceptionCode,
} from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
import { isIdentifierNameTooLong } from 'src/engine/metadata-modules/utils/validate-identifier-length.utils';
import { exceedsDatabaseIdentifierMaximumLength } from 'src/engine/metadata-modules/utils/validate-database-identifier-length.utils';

import {
FieldMetadataEntity,
Expand Down Expand Up @@ -623,7 +623,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit

if (fieldMetadataInput.options) {
for (const option of fieldMetadataInput.options) {
if (isIdentifierNameTooLong(option.value)) {
if (exceedsDatabaseIdentifierMaximumLength(option.value)) {
throw new FieldMetadataException(
`Option value "${option.value}" exceeds 63 characters`,
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ObjectMetadataException,
ObjectMetadataExceptionCode,
} from 'src/engine/metadata-modules/object-metadata/object-metadata.exception';
import { isIdentifierNameTooLong } from 'src/engine/metadata-modules/utils/validate-identifier-length.utils';
import { exceedsDatabaseIdentifierMaximumLength } from 'src/engine/metadata-modules/utils/validate-database-identifier-length.utils';
import {
validateMetadataNameOrThrow,
InvalidStringException,
Expand Down Expand Up @@ -84,7 +84,7 @@ const validateNameCamelCasedOrThrow = (name?: string) => {

const validateNameIsNotTooLongThrow = (name?: string) => {
if (name) {
if (isIdentifierNameTooLong(name)) {
if (exceedsDatabaseIdentifierMaximumLength(name)) {
throw new ObjectMetadataException(
`Name exceeds 63 characters: ${name}`,
ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'src/engine/metadata-modules/utils/metadata.constants';

export const isIdentifierNameTooLong = (string: string) => {
export const exceedsDatabaseIdentifierMaximumLength = (string: string) => {
return string.length > IDENTIFIER_MAX_CHAR_LENGTH;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isIdentifierNameTooLong } from 'src/engine/metadata-modules/utils/validate-identifier-length.utils';
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 (isIdentifierNameTooLong(name)) {
if (exceedsDatabaseIdentifierMaximumLength(name)) {
throw new NameTooLongException(name);
}
};
Expand Down