refactor(server): unify the two metadata override mechanisms into one (#22417)
## Unify the two metadata override mechanisms into one Twenty had **two** override mechanisms: - **`standardOverrides`** — a bespoke JSONB column on `objectMetadata`/`fieldMetadata` with typed DTOs and a per-locale `translations` map, resolved by two i18n-aware resolvers. - **`OverridableEntity.overrides`** — a flat, registry-driven JSONB blob on view / view-field / view-field-group / command-menu-item / page-layout-tab / page-layout-widget, resolved by a plain spread. This PR collapses them into **one** concept: a single `overrides` blob, one registry-driven overridable set, one i18n-aware read path, and one write path (`computeMetadataOverridesBlob`, extracted in #22404). Object/field **stay on `SyncableEntity`** (not reparented to `OverridableEntity`) so their `isActive` default stays **FALSE** — this sidesteps the `isActive` default conflict entirely. ### GraphQL breaking change (accepted) The `standardOverrides` field is **removed** with no deprecation alias — `overrides` (a `JSON` scalar) is exposed instead on `Object` and `Field`. Product confirmed negligible external usage; the front-end has no hand-written consumer (only generated types), which are regenerated here. ### Commit structure (reviewable commit-by-commit) 1. **Unified resolver + parity harness** — `resolveEffectiveEntityProperty` is a strict superset of the three legacy resolvers; a corpus parity spec compares it against a *frozen reference* of the old logic across every locale, `isStandardApp` branch and override shape. 2. **Registry-driven** — object/field presentation props tagged `isOverridable` + `translatable`; the overridable/translatable sets are derived from the registry (a test asserts they equal the legacy hardcoded lists). 3. **Rename + swap + delete** — `standardOverrides` → `overrides` across entities, DTOs, flat/universal types, producers, the ~12 resolve/write/create/sync call sites, mocks and specs; the reconciler's two compare entries collapse to one; the three legacy resolvers, both DTOs and the hardcoded constants/types are deleted. 4. **Migration (zero-downtime, two-phase)** — split across two releases so a rolling deploy never drops a column a previous-release pod still `SELECT`s: - **2.19 fast** — add the `overrides` column (schema only). - **2.19 slow** — backfill `overrides` from `standardOverrides` in `runDataMigration` (kept out of the schema transaction so the bulk write doesn't hold the ACCESS EXCLUSIVE lock; skipped on fresh installs, which have no data to copy). - **2.20 fast** — drop the legacy `standardOverrides` column (gated by `TWENTY_NEXT_VERSIONS`, so it stays dormant until the instance reaches 2.20). 5. **Front/client-SDK regen** — regenerated metadata GraphQL types. 6. **Integration specs + i18n** — updated the standard object/field update integration specs + snapshots, and the reworded validator message catalog entry. ### Rolling-deploy safety `standardOverrides` is retained through 2.19 and only dropped in 2.20, mirroring the codebase's deferred-drop convention (`isUIReadOnly`/`isCustom`). During the 2.19 rollout both columns exist, so old and new pods coexist without "column does not exist" errors. The backfill lives in a slow `runDataMigration` (per the `no-data-mutation-in-fast-instance-command` rule) so it doesn't stall reads. ### `isActive` guard The migration never reads or writes `isActive`; the backfill asserts the active-row count is unchanged and aborts otherwise. Verified on a real DB: apply + revert preserves the blob **and** the nested `translations` map, with `isActive` counts identical before/after. ### Verification (local) - `nx typecheck twenty-server` + `nx typecheck twenty-front` — green - `nx lint:diff-with-main twenty-server` (oxlint `--type-aware` + oxfmt) — green - `nx test twenty-server` — green (unit + parity + registry + migration tests) - `nx run twenty-server:test:integration:with-db-reset` — green - `database:reset` applies the 2.19 phases and leaves **both** columns present (2.20 drop stays dormant); backfill + revert round-trip verified on a real DB - Metadata integration suites (standard object/field update, application sync) pass end-to-end against the two-column schema - Metadata GraphQL types regenerated against a booted server; zero `standardOverrides` references remain in application code (only the migration commands + the legacy schema baseline) --------- Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
+18
-19
@@ -6,8 +6,7 @@ import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
|
||||
import { I18nService } from 'src/engine/core-modules/i18n/i18n.service';
|
||||
import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
|
||||
import { NavigationMenuItemRecordIdentifierService } from 'src/engine/metadata-modules/navigation-menu-item/services/navigation-menu-item-record-identifier.service';
|
||||
import { FIELD_METADATA_STANDARD_OVERRIDES_PROPERTIES } from 'src/engine/metadata-modules/field-metadata/constants/field-metadata-standard-overrides-properties.constant';
|
||||
import { OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES } from 'src/engine/metadata-modules/object-metadata/constants/object-metadata-standard-overrides-properties.constant';
|
||||
import { ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME } from 'src/engine/metadata-modules/flat-entity/constant/all-overridable-properties-by-metadata-name.constant';
|
||||
import { type MetadataEventBatch } from 'src/engine/subscriptions/metadata-event/types/metadata-event-batch.type';
|
||||
import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
|
||||
import { enrichCommandMenuItemEventWithResolvedNavigation } from 'src/engine/subscriptions/metadata-event/utils/enrich-command-menu-item-event-with-resolved-navigation.util';
|
||||
@@ -61,7 +60,7 @@ export class MetadataEventPublisher {
|
||||
metadataEventBatch as MetadataEventBatch<'commandMenuItem'>,
|
||||
);
|
||||
case 'objectMetadata':
|
||||
return this.resolveObjectMetadataStandardOverrides(
|
||||
return this.resolveObjectMetadataOverrides(
|
||||
metadataEventBatch as MetadataEventBatch<'objectMetadata'>,
|
||||
);
|
||||
default:
|
||||
@@ -87,9 +86,9 @@ export class MetadataEventPublisher {
|
||||
'before' in enrichedProperties &&
|
||||
isDefined(enrichedProperties.before)
|
||||
) {
|
||||
enrichedProperties.before = this.applyStandardOverridesToMetadataRecord(
|
||||
enrichedProperties.before = this.applyOverridesToMetadataRecord(
|
||||
enrichedProperties.before as Record<string, unknown>,
|
||||
FIELD_METADATA_STANDARD_OVERRIDES_PROPERTIES,
|
||||
ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME.fieldMetadata,
|
||||
) as typeof enrichedProperties.before;
|
||||
}
|
||||
|
||||
@@ -103,9 +102,9 @@ export class MetadataEventPublisher {
|
||||
flatObjectMetadataMaps,
|
||||
});
|
||||
|
||||
enrichedProperties.after = this.applyStandardOverridesToMetadataRecord(
|
||||
enrichedProperties.after = this.applyOverridesToMetadataRecord(
|
||||
enrichedAfter,
|
||||
FIELD_METADATA_STANDARD_OVERRIDES_PROPERTIES,
|
||||
ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME.fieldMetadata,
|
||||
) as typeof enrichedProperties.after;
|
||||
}
|
||||
|
||||
@@ -207,7 +206,7 @@ export class MetadataEventPublisher {
|
||||
return { ...metadataEventBatch, events: enrichedEvents };
|
||||
}
|
||||
|
||||
private resolveObjectMetadataStandardOverrides(
|
||||
private resolveObjectMetadataOverrides(
|
||||
metadataEventBatch: MetadataEventBatch<'objectMetadata'>,
|
||||
): MetadataEventBatch<'objectMetadata'> {
|
||||
const enrichedEvents = metadataEventBatch.events.map((event) => {
|
||||
@@ -217,9 +216,9 @@ export class MetadataEventPublisher {
|
||||
'before' in enrichedProperties &&
|
||||
isDefined(enrichedProperties.before)
|
||||
) {
|
||||
enrichedProperties.before = this.applyStandardOverridesToMetadataRecord(
|
||||
enrichedProperties.before = this.applyOverridesToMetadataRecord(
|
||||
enrichedProperties.before as Record<string, unknown>,
|
||||
OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES,
|
||||
ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME.objectMetadata,
|
||||
) as typeof enrichedProperties.before;
|
||||
}
|
||||
|
||||
@@ -227,9 +226,9 @@ export class MetadataEventPublisher {
|
||||
'after' in enrichedProperties &&
|
||||
isDefined(enrichedProperties.after)
|
||||
) {
|
||||
enrichedProperties.after = this.applyStandardOverridesToMetadataRecord(
|
||||
enrichedProperties.after = this.applyOverridesToMetadataRecord(
|
||||
enrichedProperties.after as Record<string, unknown>,
|
||||
OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES,
|
||||
ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME.objectMetadata,
|
||||
) as typeof enrichedProperties.after;
|
||||
}
|
||||
|
||||
@@ -239,24 +238,24 @@ export class MetadataEventPublisher {
|
||||
return { ...metadataEventBatch, events: enrichedEvents };
|
||||
}
|
||||
|
||||
private applyStandardOverridesToMetadataRecord(
|
||||
private applyOverridesToMetadataRecord(
|
||||
record: Record<string, unknown>,
|
||||
standardOverrideProperties: readonly string[],
|
||||
overridableProperties: readonly string[],
|
||||
): Record<string, unknown> {
|
||||
const standardOverrides = record.standardOverrides as
|
||||
const overrides = record.overrides as
|
||||
| Record<string, unknown>
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
if (!isDefined(standardOverrides)) {
|
||||
if (!isDefined(overrides)) {
|
||||
return record;
|
||||
}
|
||||
|
||||
const resolved = { ...record };
|
||||
|
||||
for (const key of standardOverrideProperties) {
|
||||
if (isDefined(standardOverrides[key])) {
|
||||
resolved[key] = standardOverrides[key];
|
||||
for (const key of overridableProperties) {
|
||||
if (isDefined(overrides[key])) {
|
||||
resolved[key] = overrides[key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -32,7 +32,7 @@ const makeFlatObjectMetadata = (
|
||||
labelPlural: 'People',
|
||||
labelSingular: 'Person',
|
||||
icon: 'IconUser',
|
||||
standardOverrides: null,
|
||||
overrides: null,
|
||||
...overrides,
|
||||
}) as unknown as FlatObjectMetadata;
|
||||
|
||||
@@ -148,10 +148,10 @@ describe('enrichCommandMenuItemEventWithResolvedNavigation', () => {
|
||||
const flatObjectMetadata = makeFlatObjectMetadata({
|
||||
labelPlural: 'People',
|
||||
icon: 'IconUser',
|
||||
standardOverrides: {
|
||||
overrides: {
|
||||
labelPlural: 'Contacts',
|
||||
icon: 'IconContacts',
|
||||
} as unknown as FlatObjectMetadata['standardOverrides'],
|
||||
} as unknown as FlatObjectMetadata['overrides'],
|
||||
});
|
||||
const flatObjectMetadataMaps =
|
||||
makeFlatObjectMetadataMaps(flatObjectMetadata);
|
||||
@@ -174,7 +174,7 @@ describe('enrichCommandMenuItemEventWithResolvedNavigation', () => {
|
||||
const flatObjectMetadata = makeFlatObjectMetadata({
|
||||
labelPlural: 'Companies',
|
||||
icon: 'IconBuilding',
|
||||
standardOverrides: null,
|
||||
overrides: null,
|
||||
});
|
||||
const flatObjectMetadataMaps =
|
||||
makeFlatObjectMetadataMaps(flatObjectMetadata);
|
||||
|
||||
Reference in New Issue
Block a user