Projects with terraform module metadata can't be deleted

Description

The existence of terraform module metadata Packages::TerraformModule::Metadata prevent a project deletion.

ActiveRecord::NotNullViolation: PG::NotNullViolation: ERROR: null value in column "project_id" of relation "packages_terraform_module_metadata" violates not-null constraint

The project_id column in the packages_terraform_module_metadata is marked as NOT NULL and we cann't nullify when the linked project gets deleted.

Solution

We could remove the foreign key to projects and use the loose foreign key with async_delete option to delete entries in the packages_terraform_module_metadata table.

Edited by Dzmitry (Dima) Meshcharakou