Refactor seed to use twenty-standard application (#16598)
# Introduction In this pull-request we introduce a service dedicated to the twenty-standard app installation, we will later be able to re-use existing logic to be more generic and allow any app installation. For the moment sticking to this usage https://github.com/twentyhq/core-team-issues/issues/1995 ## Encountered issues - We decided not to migrate deprecated fields ( also they will become custom field for any existing workspace having them in the future ) - duplicate criteria - wrong search index declaration - forgotten isSearchable - Attachement seed - Restored standardId ## Note For the moment we're still searching through standardId for code that run on both existing and new workspaces. For code running on new workspace exclusively we're searching using universalIdentifier We will standardize universalIdentifier usage later when we've migratred all the existing workspaces ## Workspace creation Will handle workspace creation the same way in another PR Related https://github.com/twentyhq/twenty/pull/15065 ## TODO - [ ] Double all frontend hardcoded queries to not refer to deprecated fields especially attachments
This commit is contained in:
+10
-7
@@ -3,12 +3,15 @@ import { isDefined } from 'twenty-shared/utils';
|
||||
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity.type';
|
||||
|
||||
export const getFlatEntitiesByApplicationId = <T extends SyncableFlatEntity>(
|
||||
maps: FlatEntityMaps<T>,
|
||||
applicationId: string,
|
||||
): T[] => {
|
||||
export const findFlatEntitiesByApplicationId = <T extends SyncableFlatEntity>({
|
||||
applicationId,
|
||||
flatEntityMaps,
|
||||
}: {
|
||||
flatEntityMaps: FlatEntityMaps<T>;
|
||||
applicationId: string;
|
||||
}): T[] => {
|
||||
const universalIdentifiers =
|
||||
maps.universalIdentifiersByApplicationId[applicationId];
|
||||
flatEntityMaps.universalIdentifiersByApplicationId[applicationId];
|
||||
|
||||
if (!isDefined(universalIdentifiers)) {
|
||||
return [];
|
||||
@@ -16,13 +19,13 @@ export const getFlatEntitiesByApplicationId = <T extends SyncableFlatEntity>(
|
||||
|
||||
return universalIdentifiers
|
||||
.map((universalId) => {
|
||||
const id = maps.idByUniversalIdentifier[universalId];
|
||||
const id = flatEntityMaps.idByUniversalIdentifier[universalId];
|
||||
|
||||
if (!isDefined(id)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const entity = maps.byId[id];
|
||||
const entity = flatEntityMaps.byId[id];
|
||||
|
||||
if (!isDefined(entity)) {
|
||||
return undefined;
|
||||
+11
-7
@@ -3,17 +3,21 @@ import { isDefined } from 'twenty-shared/utils';
|
||||
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity.type';
|
||||
|
||||
export const getFlatEntityByUniversalIdentifier = <
|
||||
export const findFlatEntityByUniversalIdentifier = <
|
||||
T extends SyncableFlatEntity,
|
||||
>(
|
||||
maps: FlatEntityMaps<T>,
|
||||
universalIdentifier: string,
|
||||
): T | undefined => {
|
||||
const flatEntityId = maps.idByUniversalIdentifier[universalIdentifier];
|
||||
>({
|
||||
flatEntityMaps,
|
||||
universalIdentifier,
|
||||
}: {
|
||||
flatEntityMaps: FlatEntityMaps<T>;
|
||||
universalIdentifier: string;
|
||||
}): T | undefined => {
|
||||
const flatEntityId =
|
||||
flatEntityMaps.idByUniversalIdentifier[universalIdentifier];
|
||||
|
||||
if (!isDefined(flatEntityId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return maps.byId[flatEntityId];
|
||||
return flatEntityMaps.byId[flatEntityId];
|
||||
};
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
||||
import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity.type';
|
||||
import { findFlatEntitiesByApplicationId } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entities-by-application-id.util';
|
||||
import { getSubFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/get-sub-flat-entity-maps-or-throw.util';
|
||||
|
||||
export const getSubFlatEntityMapsByApplicationIdOrThrow = <
|
||||
T extends SyncableFlatEntity,
|
||||
>({
|
||||
applicationId,
|
||||
flatEntityMaps,
|
||||
}: {
|
||||
applicationId: string;
|
||||
flatEntityMaps: FlatEntityMaps<T>;
|
||||
}) => {
|
||||
const allApplicationFlatEntity = findFlatEntitiesByApplicationId({
|
||||
applicationId,
|
||||
flatEntityMaps,
|
||||
});
|
||||
|
||||
return getSubFlatEntityMapsOrThrow({
|
||||
flatEntityIds: allApplicationFlatEntity.map((flatEntity) => flatEntity.id),
|
||||
flatEntityMaps,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user