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:
Félix Malfait
2026-07-02 12:01:15 +02:00
committed by GitHub
parent 63d092a31b
commit 5a4ebca226
121 changed files with 2394 additions and 3109 deletions
@@ -12,7 +12,7 @@ export const ATTACHMENT_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Attachments',
description: 'An attachment',
icon: 'IconFileImport',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const COMPANY_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Companies',
description: 'A company',
icon: 'IconBuildingSkyscraper',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -44,7 +44,7 @@ export const getFlatObjectMetadataMock = (
nameSingular: 'defaultflatObjectMetadataNameSingular',
shortcut: 'shortcut',
applicationId,
standardOverrides: null,
overrides: null,
targetTableName: '',
workspaceId: faker.string.uuid(),
createdAt,
@@ -69,7 +69,7 @@ export const getStandardFlatObjectMetadataMock = (
overrides: Omit<FlatObjectMetadataOverrides, 'isCustom' | 'isSystem'>,
) => {
return getFlatObjectMetadataMock({
standardOverrides: {},
overrides: {},
isSystem: true,
applicationUniversalIdentifier:
TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
@@ -12,7 +12,7 @@ export const NOTE_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Notes',
description: 'A note',
icon: 'IconNotes',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const NOTE_TARGET_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Note Targets',
description: 'A note target',
icon: 'IconCheckbox',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const OPPORTUNITY_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Opportunities',
description: 'An opportunity',
icon: 'IconTargetArrow',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const PERSON_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'People',
description: 'A person',
icon: 'IconUser',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -8,7 +8,7 @@ export const PET_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Pets',
description: null,
icon: 'IconCat',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -8,7 +8,7 @@ export const ROCKET_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Rockets',
description: 'A rocket',
icon: 'IconRocket',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const TASK_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Tasks',
description: 'A task',
icon: 'IconCheckbox',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const TASK_TARGET_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Task Targets',
description: 'A task target',
icon: 'IconCheckbox',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -12,7 +12,7 @@ export const TIMELINE_ACTIVITY_FLAT_OBJECT_MOCK = getFlatObjectMetadataMock({
labelPlural: 'Timeline Activities',
description: 'Aggregated / filtered event to be displayed on the timeline',
icon: 'IconTimelineEvent',
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
isRemote: false,
isActive: true,
@@ -89,7 +89,7 @@ export const fromCreateObjectInputToFlatObjectMetadataAndFlatFieldMetadatasToCre
namePlural: createObjectInput.namePlural,
nameSingular: createObjectInput.nameSingular,
shortcut: createObjectInput.shortcut ?? null,
standardOverrides: null,
overrides: null,
targetTableName: 'DEPRECATED',
applicationUniversalIdentifier: flatApplication.universalIdentifier,
fieldUniversalIdentifiers: [],
@@ -10,7 +10,7 @@ export const fromFlatObjectMetadataToObjectMetadataDto = (
color,
description,
icon,
standardOverrides,
overrides,
shortcut,
duplicateCriteria,
id,
@@ -55,7 +55,7 @@ export const fromFlatObjectMetadataToObjectMetadataDto = (
color: color ?? undefined,
description: description ?? undefined,
icon: icon ?? undefined,
standardOverrides: standardOverrides ?? undefined,
overrides: overrides ?? undefined,
shortcut: shortcut ?? undefined,
duplicateCriteria: duplicateCriteria ?? undefined,
applicationId,
@@ -66,7 +66,7 @@ export const fromUpdateObjectInputToFlatObjectMetadataAndRelatedFlatEntities =
const isStandardObject = belongsToTwentyStandardApp(
existingFlatObjectMetadata,
);
const { standardOverrides, updatedEditableObjectProperties } =
const { overrides, updatedEditableObjectProperties } =
sanitizeRawUpdateObjectInput({
existingFlatObjectMetadata,
rawUpdateObjectInput,
@@ -81,7 +81,7 @@ export const fromUpdateObjectInputToFlatObjectMetadataAndRelatedFlatEntities =
],
update: updatedEditableObjectProperties,
}),
standardOverrides,
overrides,
};
if (
@@ -1,14 +1,13 @@
import { extractAndSanitizeObjectStringFields } from 'twenty-shared/utils';
import { ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME } from 'src/engine/metadata-modules/flat-entity/constant/all-overridable-properties-by-metadata-name.constant';
import { FLAT_OBJECT_METADATA_EDITABLE_PROPERTIES } from 'src/engine/metadata-modules/flat-object-metadata/constants/flat-object-metadata-editable-properties.constant';
import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
import { OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES } from 'src/engine/metadata-modules/object-metadata/constants/object-metadata-standard-overrides-properties.constant';
import { type UpdateOneObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/update-object.input';
import {
ObjectMetadataException,
ObjectMetadataExceptionCode,
} from 'src/engine/metadata-modules/object-metadata/object-metadata.exception';
import { type ObjectMetadataStandardOverridesProperties } from 'src/engine/metadata-modules/object-metadata/types/object-metadata-standard-overrides-properties.types';
import { belongsToTwentyStandardApp } from 'src/engine/metadata-modules/utils/belongs-to-twenty-standard-app.util';
import { computeMetadataOverridesBlob } from 'src/engine/metadata-modules/utils/compute-metadata-overrides-blob.util';
@@ -37,7 +36,7 @@ export const sanitizeRawUpdateObjectInput = ({
if (!isStandardObject) {
return {
updatedEditableObjectProperties,
standardOverrides: null,
overrides: null,
};
}
@@ -46,7 +45,7 @@ export const sanitizeRawUpdateObjectInput = ({
).filter(
(property) =>
!FLAT_OBJECT_METADATA_EDITABLE_PROPERTIES.standard.includes(
property as ObjectMetadataStandardOverridesProperties,
property as (typeof FLAT_OBJECT_METADATA_EDITABLE_PROPERTIES.standard)[number],
),
);
@@ -57,16 +56,16 @@ export const sanitizeRawUpdateObjectInput = ({
);
}
const { overrides: standardOverrides, remainingProperties } =
computeMetadataOverridesBlob({
overridableProperties: OBJECT_METADATA_STANDARD_OVERRIDES_PROPERTIES,
updatedProperties: updatedEditableObjectProperties,
existingEntity: existingFlatObjectMetadata,
existingOverrides: existingFlatObjectMetadata.standardOverrides,
});
const { overrides, remainingProperties } = computeMetadataOverridesBlob({
overridableProperties:
ALL_OVERRIDABLE_PROPERTIES_BY_METADATA_NAME.objectMetadata,
updatedProperties: updatedEditableObjectProperties,
existingEntity: existingFlatObjectMetadata,
existingOverrides: existingFlatObjectMetadata.overrides,
});
return {
standardOverrides,
overrides,
updatedEditableObjectProperties: remainingProperties,
};
};