twenty icon indicating copy to clipboard operation
twenty copied to clipboard

Add unique indexes and indexes for composite types

Open FelixMalfait opened this issue 5 months ago • 2 comments

Add support for indexes on composite fields and unicity constraint on indexes

This pull request includes several changes across multiple files to improve error handling, enforce unique constraints, and update database migrations. The most important changes include updating error messages for snack bars, adding a new command to enforce unique constraints, and updating database migrations to include new fields and constraints.

Error Handling Improvements:

  • packages/twenty-front/src/modules/error-handler/components/PromiseRejectionEffect.tsx: Updated error messages in enqueueSnackBar to use error.message directly.
  • packages/twenty-front/src/modules/object-metadata/hooks/useFindManyObjectMetadataItems.ts: Simplified error messages in enqueueSnackBar.
  • packages/twenty-front/src/modules/object-record/hooks/useFindDuplicateRecords.ts: Simplified error messages in enqueueSnackBar.
  • packages/twenty-front/src/modules/object-record/hooks/useHandleFindManyRecordsError.ts: Simplified error messages in enqueueSnackBar.

New Command for Unique Constraints:

  • packages/twenty-server/src/database/commands/upgrade-version/0-31/0-31-enforce-unique-constraints.command.ts: Added a new command to enforce unique constraints on company domain names and person emails.
  • packages/twenty-server/src/database/commands/upgrade-version/0-31/0-31-upgrade-version.command.ts: Integrated the new EnforceUniqueConstraintsCommand into the upgrade process. [1] [2] [3]
  • packages/twenty-server/src/database/commands/upgrade-version/0-31/0-31-upgrade-version.module.ts: Registered the new EnforceUniqueConstraintsCommand in the module. [1] [2]

Database Migrations:

  • packages/twenty-server/src/database/typeorm/metadata/migrations/1726757368824-migrationDebt.ts: Added a migration to update the relationMetadata_ondeleteaction_enum and set default values.
  • packages/twenty-server/src/database/typeorm/metadata/migrations/1726757368825-addIsUniqueToIndexMetadata.ts: Added a migration to include the isUnique field in indexMetadata.
  • packages/twenty-server/src/database/typeorm/metadata/migrations/1726762935841-addCompostiveColumnToIndexFieldMetadata.ts: Added a migration to include the compositeColumn field in indexFieldMetadata.
  • packages/twenty-server/src/database/typeorm/metadata/migrations/1726766871572-addWhereToIndexMetadata.ts: Added a migration to include the indexWhereClause field in indexMetadata.

GraphQL Exception Handling:

  • packages/twenty-server/src/engine/api/graphql/workspace-query-runner/utils/workspace-query-runner-graphql-api-exception-handler.util.ts: Enhanced exception handling for QueryFailedError to provide more specific error messages for unique constraint violations. [1] [2]
  • packages/twenty-server/src/engine/api/graphql/workspace-resolver-builder/factories/create-many-resolver.factory.ts: Updated the workspaceQueryRunnerGraphqlApiExceptionHandler call to include context.
  • packages/twenty-server/src/engine/api/graphql/workspace-resolver-builder/factories/create-one-resolver.factory.ts: Updated the workspaceQueryRunnerGraphqlApiExceptionHandler call to include context.

FelixMalfait avatar Sep 19 '24 16:09 FelixMalfait