Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { BackfillPageLayoutUniversalIdentifiersCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-backfill-page-layout-universal-identifiers.command';
import { BackfillViewMainGroupByFieldMetadataIdCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-backfill-view-main-group-by-field-metadata-id.command';
import { CleanEmptyStringNullInTextFieldsCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-clean-empty-string-null-in-text-fields.command';
import { DeduplicateRoleTargetsCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-deduplicate-role-targets.command';
import { MigrateStandardInvalidEntitiesCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-migrate-standard-invalid-entities.command';
Expand Down Expand Up @@ -59,7 +58,6 @@ import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-o
],
providers: [
CleanEmptyStringNullInTextFieldsCommand,
BackfillViewMainGroupByFieldMetadataIdCommand,
BackfillPageLayoutUniversalIdentifiersCommand,
DeduplicateRoleTargetsCommand,
RenameIndexNameCommand,
Expand All @@ -69,7 +67,6 @@ import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-o
],
exports: [
CleanEmptyStringNullInTextFieldsCommand,
BackfillViewMainGroupByFieldMetadataIdCommand,
BackfillPageLayoutUniversalIdentifiersCommand,
DeduplicateRoleTargetsCommand,
RenameIndexNameCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
type VersionCommands,
} from 'src/database/commands/command-runners/upgrade.command-runner';
import { BackfillPageLayoutUniversalIdentifiersCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-backfill-page-layout-universal-identifiers.command';
import { BackfillViewMainGroupByFieldMetadataIdCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-backfill-view-main-group-by-field-metadata-id.command';
import { CleanEmptyStringNullInTextFieldsCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-clean-empty-string-null-in-text-fields.command';
import { DeduplicateRoleTargetsCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-deduplicate-role-targets.command';
import { MigrateStandardInvalidEntitiesCommand } from 'src/database/commands/upgrade-version-command/1-13/1-13-migrate-standard-invalid-entities.command';
Expand Down Expand Up @@ -42,7 +41,6 @@ export class UpgradeCommand extends UpgradeCommandRunner {
protected readonly updateRoleTargetsUniqueConstraintMigrationCommand: UpdateRoleTargetsUniqueConstraintMigrationCommand,
protected readonly backfillPageLayoutUniversalIdentifiersCommand: BackfillPageLayoutUniversalIdentifiersCommand,
protected readonly migrateStandardInvalidEntitiesCommand: MigrateStandardInvalidEntitiesCommand,
protected readonly backfillViewMainGroupByFieldMetadataIdCommand: BackfillViewMainGroupByFieldMetadataIdCommand,
protected readonly cleanEmptyStringNullInTextFieldsCommand: CleanEmptyStringNullInTextFieldsCommand,
protected readonly renameIndexNameCommand: RenameIndexNameCommand,
) {
Expand All @@ -62,7 +60,6 @@ export class UpgradeCommand extends UpgradeCommandRunner {
this.updateRoleTargetsUniqueConstraintMigrationCommand,
this.backfillPageLayoutUniversalIdentifiersCommand,
this.migrateStandardInvalidEntitiesCommand,
this.backfillViewMainGroupByFieldMetadataIdCommand,
this.cleanEmptyStringNullInTextFieldsCommand,
this.renameIndexNameCommand,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';

export class RemoveFieldMetadataIdInViewGroup1765808791153
implements MigrationInterface
{
name = 'RemoveFieldMetadataIdInViewGroup1765808791153';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."viewGroup" DROP CONSTRAINT "FK_b3aa7ec58cdd9e83729f2232591"`,
);
await queryRunner.query(
`ALTER TABLE "core"."viewGroup" DROP COLUMN "fieldMetadataId"`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."viewGroup" ADD "fieldMetadataId" uuid NOT NULL`,
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The down migration adds fieldMetadataId as NOT NULL without a default value. If any rows exist in viewGroup when rolling back, this will fail. Consider making the column nullable in the rollback, or adding a comment explaining the rollback limitation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/database/typeorm/core/migrations/common/1765808791153-remove-field-metadata-id-in-view-group.ts, line 19:

<comment>The `down` migration adds `fieldMetadataId` as `NOT NULL` without a default value. If any rows exist in `viewGroup` when rolling back, this will fail. Consider making the column nullable in the rollback, or adding a comment explaining the rollback limitation.</comment>

<file context>
@@ -0,0 +1,25 @@
+
+  public async down(queryRunner: QueryRunner): Promise&lt;void&gt; {
+    await queryRunner.query(
+      `ALTER TABLE &quot;core&quot;.&quot;viewGroup&quot; ADD &quot;fieldMetadataId&quot; uuid NOT NULL`,
+    );
+    await queryRunner.query(
</file context>

✅ Addressed in fb13a7d

);
await queryRunner.query(
`ALTER TABLE "core"."viewGroup" ADD CONSTRAINT "FK_b3aa7ec58cdd9e83729f2232591" FOREIGN KEY ("fieldMetadataId") REFERENCES "core"."fieldMetadata"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('getConflictingFields', () => {
universalIdentifier: overrides.id,
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const mockFieldMetadatas: FlatFieldMetadata[] = [
universalIdentifier: 'name-id',
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand All @@ -48,7 +47,6 @@ const mockFieldMetadatas: FlatFieldMetadata[] = [
universalIdentifier: 'emails-id',
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand All @@ -71,7 +69,6 @@ const mockFieldMetadatas: FlatFieldMetadata[] = [
universalIdentifier: 'linkedinLink-id',
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand All @@ -90,7 +87,6 @@ const mockFieldMetadatas: FlatFieldMetadata[] = [
universalIdentifier: 'jobTitle-id',
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('buildColumnsToSelect', () => {
universalIdentifier: overrides.id,
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('getAllSelectableFields', () => {
universalIdentifier: overrides.id,
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('computeCursorArgFilter', () => {
universalIdentifier: overrides.id,
viewFieldIds: [],
viewFilterIds: [],
viewGroupIds: [],
kanbanAggregateOperationViewIds: [],
calendarViewIds: [],
applicationId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
import { FieldPermissionEntity } from 'src/engine/metadata-modules/object-permission/field-permission/field-permission.entity';
import { ViewFieldEntity } from 'src/engine/metadata-modules/view-field/entities/view-field.entity';
import { ViewFilterEntity } from 'src/engine/metadata-modules/view-filter/entities/view-filter.entity';
import { ViewGroupEntity } from 'src/engine/metadata-modules/view-group/entities/view-group.entity';
import { ViewEntity } from 'src/engine/metadata-modules/view/entities/view.entity';

@Entity('fieldMetadata')
Expand Down Expand Up @@ -201,9 +200,6 @@ export class FieldMetadataEntity<
@OneToMany(() => ViewFilterEntity, (viewFilter) => viewFilter.fieldMetadata)
viewFilters: Relation<ViewFilterEntity[]>;

@OneToMany(() => ViewGroupEntity, (viewGroup) => viewGroup.fieldMetadata)
viewGroups: Relation<ViewGroupEntity[]>;

@OneToMany(
() => ViewEntity,
(view) => view.kanbanAggregateOperationFieldMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const FIELD_METADATA_RELATION_PROPERTIES = [
'kanbanAggregateOperationViews',
'calendarViews',
'mainGroupByFieldMetadataViews',
'viewGroups',
] as const satisfies (keyof FieldMetadataEntity)[];

export type FieldMetadataEntityRelationProperties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const recomputeViewGroupsOnEnumFlatFieldMetadataIsNullableUpdate = ({
deletedAt: null,
viewId,
applicationId: toFlatFieldMetadata.applicationId,
fieldMetadataId: fromFlatFieldMetadata.id,
});
} else if (isDefined(emptyValueFlatViewGroup)) {
sideEffectResult.flatViewGroupsToDelete.push(emptyValueFlatViewGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export const FLAT_VIEW_GROUP_EDITABLE_PROPERTIES = [
'isVisible',
'fieldValue',
'position',
'fieldMetadataId',
] as const satisfies (keyof FlatViewGroup)[];
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const computeFlatViewGroupsOnViewCreate = ({

flatViewGroups.push({
id: emptyGroupId,
fieldMetadataId: mainGroupByFieldMetadata.id,
viewId: flatViewToCreateId,
workspaceId: mainGroupByFieldMetadata.workspaceId,
createdAt,
Expand Down
Loading
Loading