Skip to content

DB Migration 20240305120015_torrust_add_independent_root_hash_field.sql truncates data for torrent secondary tables #526

@josecelano

Description

@josecelano

The latest migrations added in this PR #516 produce data lost in the database.

Since SQLite does not support changing the table schema you have to

  • create a new table
  • copy data from the old table to the new table
  • drop the old table

When you drop the old table an implicit DELETE query is executed for the master table and it triggers DELETE queries for secondary tables that contain foreign keys to the primary table torrust_torrents with ON DELETE CASCADE

The official documentation about DROP is not clear (at least for me). In this site it explains the problem.

However, if the foreign key constraint is defined with ON DELETE CASCADE, then the parent table will be dropped, and any rows that reference that table’s primary key column will be deleted in the child table.

We have to change the migration to avoid deleting secondary tables.

Links

Metadata

Metadata

Assignees

Labels

BugIncorrect Behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions