Remove duplicated position for task's status field (#11998)

In this PR:

- Set the default position for the DONE option of the task's status
option to `2` instead of `1`, which was the same as `IN_PROGRESS`
option's position.
- Write a command to prevent position duplicates in the database for the
task's status field.

What I've checked before setting this PR as ready to be reviewed:

- De-duplicating the position solves the issue and it's possible to edit
the field (solves the related issue)
- The upgrade command de-duplicates the position for each workspace.
There are no more DONE options with `position=2`. I ran the upgrade
command on the `database-snapshot-manager` dataset.
- Suspended workspaces aren't fixed

---

To test the script:

```ts
const scannedPositions = new Set();
let biggestPosition = -1;

// Sort options by position for consistent processing
const sortedOptions = [
  { name: 'a', position: 2 },
  { name: 'b', position: 1 },
  { name: 'c', position: 1 },
  { name: 'd', position: 2 },
].sort((a, b) => a.position - b.position);

for (const option of sortedOptions) {
  if (scannedPositions.has(option.position)) {
    option.position = biggestPosition + 1;
  }

  biggestPosition = Math.max(biggestPosition, option.position);
  scannedPositions.add(option.position);
}

console.log('Sorted options:', sortedOptions);
```

Closes https://github.com/twentyhq/twenty/issues/11790
This commit is contained in:
Baptiste Devessier
2025-05-13 18:21:47 +02:00
committed by GitHub
parent dfe8011948
commit fc4d313907
5 changed files with 146 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import { CopyTypeormMigrationsCommand } from 'src/database/commands/upgrade-vers
import { MigrateWorkflowEventListenersToAutomatedTriggersCommand } from 'src/database/commands/upgrade-version-command/0-53/0-53-migrate-workflow-event-listeners-to-automated-triggers.command';
import { RemoveRelationForeignKeyFieldMetadataCommand } from 'src/database/commands/upgrade-version-command/0-53/0-53-remove-relation-foreign-key-field-metadata.command';
import { UpgradeSearchVectorOnPersonEntityCommand } from 'src/database/commands/upgrade-version-command/0-53/0-53-upgrade-search-vector-on-person-entity.command';
import { FixStandardSelectFieldsPositionCommand } from 'src/database/commands/upgrade-version-command/0-54/0-54-fix-standard-select-fields-position.command';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
@ -66,6 +67,9 @@ export class UpgradeCommand extends UpgradeCommandRunner {
protected readonly copyTypeormMigrationsCommand: CopyTypeormMigrationsCommand,
protected readonly upgradeSearchVectorOnPersonEntityCommand: UpgradeSearchVectorOnPersonEntityCommand,
protected readonly removeRelationForeignKeyFieldMetadataCommand: RemoveRelationForeignKeyFieldMetadataCommand,
// 0.54 Commands
protected readonly fixStandardSelectFieldsPositionCommand: FixStandardSelectFieldsPositionCommand,
) {
super(
workspaceRepository,
@ -122,6 +126,11 @@ export class UpgradeCommand extends UpgradeCommandRunner {
],
};
const commands_054: VersionCommands = {
beforeSyncMetadata: [this.fixStandardSelectFieldsPositionCommand],
afterSyncMetadata: [],
};
this.allCommands = {
'0.43.0': commands_043,
'0.44.0': commands_044,
@ -129,6 +138,7 @@ export class UpgradeCommand extends UpgradeCommandRunner {
'0.51.0': commands_051,
'0.52.0': commands_052,
'0.53.0': commands_053,
'0.54.0': commands_054,
};
}
}