Unique field - add unique property creation/deletion on field (#13539)
Done : - add isUnique prop availability on gql update/create fieldMetadata resolvers - add unique index creation logic at update & creation - add unique index deletion logic at update - update unique index if field name updated - edge cases : can't have default value and unique fields / standard default value excluded from index (where clause) / can't have composite unique fields / can't create unique fields on MORPH closes https://github.com/twentyhq/core-team-issues/issues/1222
This commit is contained in:
+16
@@ -1,8 +1,13 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { type QueryRunner, Table, type TableColumn } from 'typeorm';
|
||||
|
||||
import {
|
||||
IndexMetadataException,
|
||||
IndexMetadataExceptionCode,
|
||||
} from 'src/engine/metadata-modules/index-metadata/index-field-metadata.exception';
|
||||
import { IndexType } from 'src/engine/metadata-modules/index-metadata/types/indexType.types';
|
||||
import {
|
||||
type WorkspaceMigrationColumnAction,
|
||||
@@ -246,6 +251,17 @@ export class WorkspaceMigrationRunnerService {
|
||||
if (error.code === '42P07') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (error.code === '23505') {
|
||||
throw new IndexMetadataException(
|
||||
`Unique index creation failed because of unique constraint violation`,
|
||||
IndexMetadataExceptionCode.INDEX_CREATION_FAILED,
|
||||
{
|
||||
userFriendlyMessage: t`Cannot enable uniqueness due to existing duplicate values. Please review and fix your data first.`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user