twenty icon indicating copy to clipboard operation
twenty copied to clipboard

Database Migration Fails on Upgrade: Cannot drop table 'view' due to dependency from 'favorite' table

Open worldwidehigh opened this issue 4 weeks ago • 0 comments

Bug Description

During an application upgrade, the process fails with a database migration error. The logs show that the WorkspaceSyncMetadataService is unable to complete its task.

Specifically, the migration script attempts to execute DROP TABLE "view", but this command fails because a foreign key constraint from the favorite table still depends on it. This stops the entire upgrade process for the affected workspace.

The exact error message from the log is:

[Nest] 36  - 11/06/2025, 11:35:14 AM     LOG [WorkspaceSyncMetadataService] Executing pending migrations
query failed: DROP TABLE "workspace_ayu08mgns69ifde3gdqskh4xr"."view"
error: error: cannot drop table view because other objects depend on it
[Nest] 36  - 11/06/2025, 11:35:14 AM   ERROR [WorkspaceSyncMetadataService] Sync of standard objects failed with:
[Nest] 36  - 11/06/2025, 11:35:14 AM   ERROR [WorkspaceSyncMetadataService] QueryFailedError: cannot drop table view because other objects depend on it
[Nest] 36  - 11/06/2025, 11:35:14 AM   ERROR [WorkspaceSyncMetadataService] constraint FK_ed76ca74c462dee23069097e301 on table favorite depends on table view
[Nest] 36  - 11/06/2025, 11:35:14 AM    WARN [UpgradeCommand] Error in workspace b94182c1-fe42-4224-a117-76294043973f: cannot drop table view because other objects depend on it
PromiseMemoizer Event: A WorkspaceDataSource for workspace b94182c1-fe42-4224-a117-76294043973f is being cleared. Actual pool closure managed by PgPoolSharedService. Not calling dataSource.destroy().
[Nest] 36  - 11/06/2025, 11:35:14 AM   ERROR [UpgradeCommand] Error in workspace b94182c1-fe42-4224-a117-76294043973f: cannot drop table view because other objects depend on it
[Nest] 36  - 11/06/2025, 11:35:14 AM   ERROR [UpgradeCommand] undefined
[Nest] 36  - 11/06/2025, 11:35:14 AM     LOG [UpgradeCommand] Command completed!

Note: The log snippet is provided as a more precise alternative to a screenshot.

Expected behavior

A clear and concise description of what the expected behavior is. The database migration script should run without errors during an application upgrade. It should correctly handle existing database dependencies before attempting to drop tables. The upgrade process should complete successfully.

Technical inputs

Root Cause: The migration script does not account for the FK_ed76ca74c462dee23069097e301 constraint on the favorite table when trying to remove the view table. The migration needs to be made more robust to handle this dependency, for example by dropping the constraint before dropping the table.

Environment:

Twenty CRM Version (Upgrading from): 1.8.7. Twenty CRM Version (Upgrading to): 1.10.2. Deployment Method: Docker / Docker Compose Database: PostgreSQL

worldwidehigh avatar Nov 06 '25 11:11 worldwidehigh